Skip to content

Commit

Permalink
FIX release related fixes (#575)
Browse files Browse the repository at this point in the history
Co-authored-by: Volkan Kutal <[email protected]>
Co-authored-by: rlundeen2 <[email protected]>
Co-authored-by: AlexRRR <[email protected]>
Co-authored-by: Raja Sekhar Rao Dheekonda <[email protected]>
Co-authored-by: rdheekonda <[email protected]>
Co-authored-by: rlundeen2 <[email protected]>
  • Loading branch information
7 people authored Nov 25, 2024
1 parent 2ea7fe3 commit 3e48cee
Show file tree
Hide file tree
Showing 114 changed files with 4,596 additions and 4,380 deletions.
7 changes: 7 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,11 @@
repos:
- repo: https://github.com/kynan/nbstripout
rev: 0.8.1
hooks:
- id: nbstripout
args:
- '--keep-output'

- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.4.0
hooks:
Expand Down
47 changes: 13 additions & 34 deletions doc/code/auxiliary_attacks/0_auxiliary_attacks.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,15 @@
"cells": [
{
"cell_type": "markdown",
"id": "64e22a59",
"id": "0",
"metadata": {},
"source": [
"# Auxiliary Attacks"
]
},
{
"cell_type": "markdown",
"id": "cf0fb97a",
"id": "1",
"metadata": {},
"source": [
"Auxiliary attacks cover a variety of techniques that do not fit into the core PyRIT functionality.\n",
Expand All @@ -20,15 +20,15 @@
},
{
"cell_type": "markdown",
"id": "29f7b5f1",
"id": "2",
"metadata": {},
"source": [
"## GCG Suffixes"
]
},
{
"cell_type": "markdown",
"id": "3759abbb",
"id": "3",
"metadata": {},
"source": [
"The [GCG demo notebook](1_gcg_azure_ml.ipynb) shows how to create an AML environment and submit a job that generates GCG suffixes, which can be appended to a base prompt to jailbreak a language model. In the example below, we compare the response generated by Phi-3-mini with and without a GCG suffix trained on that model.\n",
Expand All @@ -39,15 +39,8 @@
{
"cell_type": "code",
"execution_count": null,
"id": "63346930",
"metadata": {
"execution": {
"iopub.execute_input": "2024-10-09T18:43:34.034434Z",
"iopub.status.busy": "2024-10-09T18:43:34.031901Z",
"iopub.status.idle": "2024-10-09T18:43:47.833652Z",
"shell.execute_reply": "2024-10-09T18:43:47.832606Z"
}
},
"id": "4",
"metadata": {},
"outputs": [],
"source": [
"import os\n",
Expand All @@ -67,16 +60,9 @@
},
{
"cell_type": "code",
"execution_count": 2,
"id": "8ceb2bff",
"metadata": {
"execution": {
"iopub.execute_input": "2024-10-09T18:43:47.838035Z",
"iopub.status.busy": "2024-10-09T18:43:47.836258Z",
"iopub.status.idle": "2024-10-09T18:43:48.967288Z",
"shell.execute_reply": "2024-10-09T18:43:48.966583Z"
}
},
"execution_count": null,
"id": "5",
"metadata": {},
"outputs": [
{
"name": "stdout",
Expand All @@ -99,24 +85,17 @@
},
{
"cell_type": "markdown",
"id": "ec1ff040",
"id": "6",
"metadata": {},
"source": [
"Next, let's apply a GCG suffix trained on Phi-3-mini to the base prompt using the `SuffixAppendConverter`."
]
},
{
"cell_type": "code",
"execution_count": 3,
"id": "0007e270",
"metadata": {
"execution": {
"iopub.execute_input": "2024-10-09T18:43:48.976422Z",
"iopub.status.busy": "2024-10-09T18:43:48.974371Z",
"iopub.status.idle": "2024-10-09T18:43:55.722118Z",
"shell.execute_reply": "2024-10-09T18:43:55.722118Z"
}
},
"execution_count": null,
"id": "7",
"metadata": {},
"outputs": [
{
"name": "stdout",
Expand Down
28 changes: 14 additions & 14 deletions doc/code/auxiliary_attacks/1_gcg_azure_ml.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,15 @@
"cells": [
{
"cell_type": "markdown",
"id": "44a2ab29",
"id": "0",
"metadata": {},
"source": [
"# 1. Generating GCG Suffixes Using Azure Machine Learning"
]
},
{
"cell_type": "markdown",
"id": "4c2b3f55",
"id": "1",
"metadata": {},
"source": [
"This notebook shows how to generate GCG suffixes using Azure Machine Learning (AML), which consists of three main steps:\n",
Expand All @@ -21,15 +21,15 @@
},
{
"cell_type": "markdown",
"id": "697c48fe",
"id": "2",
"metadata": {},
"source": [
"## Connect to Azure Machine Learning Workspace"
]
},
{
"cell_type": "markdown",
"id": "632bef8b",
"id": "3",
"metadata": {},
"source": [
"The [workspace](https://docs.microsoft.com/en-us/azure/machine-learning/concept-workspace) is the top-level resource for Azure Machine Learning (AML), providing a centralized place to work with all the artifacts you create when using AML. In this section, we will connect to the workspace in which the job will be run.\n",
Expand All @@ -40,7 +40,7 @@
{
"cell_type": "code",
"execution_count": null,
"id": "8645ef34",
"id": "4",
"metadata": {},
"outputs": [],
"source": [
Expand All @@ -60,7 +60,7 @@
{
"cell_type": "code",
"execution_count": null,
"id": "37b282e7",
"id": "5",
"metadata": {},
"outputs": [],
"source": [
Expand All @@ -73,7 +73,7 @@
},
{
"cell_type": "markdown",
"id": "7d7c5c41",
"id": "6",
"metadata": {},
"source": [
"## Create Compute Cluster\n",
Expand All @@ -84,15 +84,15 @@
},
{
"cell_type": "markdown",
"id": "e390439f",
"id": "7",
"metadata": {},
"source": [
"## Create AML Environment"
]
},
{
"cell_type": "markdown",
"id": "ceedcfa7",
"id": "8",
"metadata": {},
"source": [
"To install the dependencies needed to run GCG, we create an AML environment from a [Dockerfile](../../../pyrit/auxiliary_attacks/gcg/src/Dockerfile)."
Expand All @@ -101,7 +101,7 @@
{
"cell_type": "code",
"execution_count": null,
"id": "67783454",
"id": "9",
"metadata": {
"lines_to_next_cell": 2
},
Expand All @@ -124,15 +124,15 @@
},
{
"cell_type": "markdown",
"id": "49d20c8e",
"id": "10",
"metadata": {},
"source": [
"## Submit Training Job to AML"
]
},
{
"cell_type": "markdown",
"id": "ad33e623",
"id": "11",
"metadata": {},
"source": [
"Finally, we configure the command to run the GCG algorithm. The entry file for the algorithm is [`run.py`](../../../pyrit/auxiliary_attacks/gcg/experiments/run.py), which takes several command line arguments, as shown below. We also have to specify the compute `instance_type` to run the algorithm on. In our experience, a GPU instance with at least 32GB of vRAM is required. In the example below, we use Standard_ND40rs_v2.\n",
Expand All @@ -143,7 +143,7 @@
{
"cell_type": "code",
"execution_count": null,
"id": "938a1030",
"id": "12",
"metadata": {},
"outputs": [],
"source": [
Expand Down Expand Up @@ -172,7 +172,7 @@
{
"cell_type": "code",
"execution_count": null,
"id": "b40591b0",
"id": "13",
"metadata": {},
"outputs": [],
"source": [
Expand Down
50 changes: 25 additions & 25 deletions doc/code/converters/0_converters.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,15 @@
"cells": [
{
"cell_type": "markdown",
"id": "7345053d",
"id": "0",
"metadata": {},
"source": [
"# Converters"
]
},
{
"cell_type": "markdown",
"id": "9fac94fe",
"id": "1",
"metadata": {},
"source": [
"Converters are used to transform prompts before sending them to the target.\n",
Expand All @@ -20,46 +20,46 @@
},
{
"cell_type": "markdown",
"id": "0f5c283e",
"id": "2",
"metadata": {},
"source": [
"## Simple Converter Example"
]
},
{
"cell_type": "markdown",
"id": "fc70d505",
"id": "3",
"metadata": {},
"source": [
"Converters can be used to perform these types of transformations. Here is a simple program that uses Rot13Converter converter, RandomCapitalLettersConverter, and AsciiArtConverter."
]
},
{
"cell_type": "code",
"execution_count": 1,
"id": "5ef007b1",
"metadata": {
"execution": {
"iopub.execute_input": "2024-06-01T13:32:33.039792Z",
"iopub.status.busy": "2024-06-01T13:32:33.039792Z",
"iopub.status.idle": "2024-06-01T13:32:37.210659Z",
"shell.execute_reply": "2024-06-01T13:32:37.203782Z"
}
},
"execution_count": null,
"id": "4",
"metadata": {},
"outputs": [
{
"name": "stderr",
"output_type": "stream",
"text": [
"None of PyTorch, TensorFlow >= 2.0, or Flax have been found. Models won't be available and only tokenizers, configuration and file/data utilities can be used.\n"
]
},
{
"name": "stdout",
"output_type": "stream",
"text": [
"text: gryy zr ubj gb phg qbja n gerr\n",
"text: teLl me HOw To cut dowN A tree\n",
"text: \n",
" # \n",
"######## ####### ## ## ## ## ####### ## ## ####### ## ## ######## ####### ####### ## ## ######## ###### ####### ## ## ### ## ####### ######## ####### ####### ####### \n",
" ## ## ## ### ### ## ## ## ## # ## ## ## ## ## ## ## ## ## # ## #### ## ## ## ## \n",
" ## #### ## ## ####### #### ####### ## ## ####### ## ## ## ## ## ## ## ## ## ## ## ####### ## #### ####### ## ####### #### #### \n",
" ## ## ## ## ## ## ## # ## ## ## ## ## ## ### ### ## ## ## ## ## ## ## ## ## ## ## ### ### ## ### ## ## ## ## ## ## ## \n",
" ## ####### ####### ####### ## ## ####### ## ## ####### ## ## ## ####### ####### ####### ## ###### ####### ## ## ## ## ## ## ## ## ## ####### ####### \n",
"text: tell mE how to cut DoWn A trEe\n",
"text: ###### ####### #### #### ## ## ####### ## ## ##### ## ## ###### ##### #### ## ## ###### ##### ##### ## ## ## ## ### ###### ###### ####### ####### \n",
" ## ## ## ## ### ### ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ### ## ## ## ## ## ## ## ## \n",
" ## ## ## ## ####### ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## #### ## ## ## ## ## ## ## ## \n",
" ## #### ## ## ## # ## #### ####### ## ## ## # ## ## ## ## ## ## ## ## ## ## ## ## ## # ## ## #### ####### ## ###### #### #### \n",
" ## ## ## ## ## ## ## ## ## ## ## ####### ## ## ## ## ## ## ## ## ## ## ## ####### ## ### ## ## ## ##### ## ## \n",
" ## ## ## ## ## ## ## ## ## ## ## ### ### ## ## ## ## ## ## ## ## ## ## ## ## ### ### ## ## ## ## ## ## ## ## ## \n",
" ## ####### ####### ####### ## ## ####### ## ## ##### ## ## ## ##### #### ##### ## ##### ##### ## ## ## ## ## ## ## ## ## ####### ####### \n",
" \n",
"\n"
]
Expand All @@ -86,9 +86,9 @@
"cell_metadata_filter": "-all"
},
"kernelspec": {
"display_name": "pyrit-dev",
"display_name": "pyrit-kernel",
"language": "python",
"name": "python3"
"name": "pyrit-kernel"
},
"language_info": {
"codemirror_mode": {
Expand All @@ -100,7 +100,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.10.13"
"version": "3.11.10"
}
},
"nbformat": 4,
Expand Down
Loading

0 comments on commit 3e48cee

Please sign in to comment.