Skip to content
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -194,3 +194,4 @@ doc/_autosummary/
# Ignore notebooks directory in Docker folder
/docker/notebooks/
/docker/notebooks/*
pyrit/auxiliary_attacks/gcg/experiments/mlruns/*
67 changes: 23 additions & 44 deletions doc/code/auxiliary_attacks/1_gcg_azure_ml.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -42,23 +42,21 @@
"execution_count": null,
"id": "4",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"romanlutz\n"
]
}
],
"outputs": [],
"source": [
"from pyrit.common import DUCK_DB, initialize_pyrit\n",
"import os\n",
"\n",
"# Technically, we don't need to initialize PyRIT locally as the job is running in Azure.\n",
"# However, we store environment variables in .env or .env.local files, which are read by PyRIT.\n",
"# If you set your environment variables differently, you can skip this step.\n",
"initialize_pyrit(memory_db_type=DUCK_DB)\n",
"\n",
"# Enter details of your AML workspace\n",
"subscription_id = os.environ.get(\"AZURE_SUBSCRIPTION_ID\")\n",
"resource_group = os.environ.get(\"AZURE_RESOURCE_GROUP\")\n",
"workspace = os.environ.get(\"AZURE_ML_WORKSPACE_NAME\")\n",
"print(workspace)"
"print(subscription_id, resource_group, workspace)"
]
},
{
Expand Down Expand Up @@ -101,18 +99,7 @@
"metadata": {
"lines_to_next_cell": 2
},
"outputs": [
{
"data": {
"text/plain": [
"Environment({'arm_type': 'environment_version', 'latest_version': None, 'image': None, 'intellectual_property': None, 'is_anonymous': False, 'auto_increment_version': False, 'auto_delete_setting': None, 'name': 'pyrit', 'description': 'PyRIT environment created from a Docker context.', 'tags': {}, 'properties': {'azureml.labels': 'latest'}, 'print_as_yaml': False, 'id': '/subscriptions/db1ba766-2ca3-42c6-a19a-0f0d43134a8c/resourceGroups/romanlutz/providers/Microsoft.MachineLearningServices/workspaces/romanlutz/environments/pyrit/versions/5', 'Resource__source_path': '', 'base_path': 'c:\\\\Users\\\\Roman\\\\git\\\\PyRIT\\\\doc\\\\code\\\\auxiliary_attacks', 'creation_context': <azure.ai.ml.entities._system_data.SystemData object at 0x0000024025678AD0>, 'serialize': <msrest.serialization.Serializer object at 0x0000024025671470>, 'version': '5', 'conda_file': None, 'build': <azure.ai.ml.entities._assets.environment.BuildContext object at 0x00000240256FC410>, 'inference_config': None, 'os_type': 'Linux', 'conda_file_path': None, 'path': None, 'datastore': None, 'upload_hash': None, 'translated_conda_file': None})"
]
},
"execution_count": null,
"metadata": {},
"output_type": "execute_result"
}
],
"outputs": [],
"source": [
"from pathlib import Path\n",
"\n",
Expand Down Expand Up @@ -186,38 +173,30 @@
"execution_count": null,
"id": "12",
"metadata": {},
"outputs": [
{
"name": "stderr",
"output_type": "stream",
"text": [
"Class AutoDeleteSettingSchema: This is an experimental class, and may change at any time. Please see https://aka.ms/azuremlexperimental for more information.\n",
"Class AutoDeleteConditionSchema: This is an experimental class, and may change at any time. Please see https://aka.ms/azuremlexperimental for more information.\n",
"Class BaseAutoDeleteSettingSchema: This is an experimental class, and may change at any time. Please see https://aka.ms/azuremlexperimental for more information.\n",
"Class IntellectualPropertySchema: This is an experimental class, and may change at any time. Please see https://aka.ms/azuremlexperimental for more information.\n",
"Class ProtectionLevelSchema: This is an experimental class, and may change at any time. Please see https://aka.ms/azuremlexperimental for more information.\n",
"Class BaseIntellectualPropertySchema: This is an experimental class, and may change at any time. Please see https://aka.ms/azuremlexperimental for more information.\n",
"Your file exceeds 100 MB. If you experience low speeds, latency, or broken connections, we recommend using the AzCopyv10 tool for this file transfer.\n",
"\n",
"Example: azcopy copy 'C:\\Users\\Roman\\git\\PyRIT' 'https://romanlutz0437468309.blob.core.windows.net/3f52e8b9-0bac-4c48-9e4a-a92e85a582c4-10s61nn9uso4b2p89xjypawyc7/PyRIT' \n",
"\n",
"See https://learn.microsoft.com/azure/storage/common/storage-use-azcopy-v10 for more information.\n",
"\u001b[32mUploading PyRIT (194.65 MBs): 100%|##########| 194652493/194652493 [01:19<00:00, 2447407.71it/s] \n",
"\u001b[39m\n",
"\n"
]
}
],
"outputs": [],
"source": [
"# Submit the command\n",
"returned_job = ml_client.create_or_update(job)"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "bfe5c544",
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
"jupytext": {
"cell_metadata_filter": "-all"
},
"kernelspec": {
"display_name": "pyrit-python313-fresh2",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
Expand Down
16 changes: 12 additions & 4 deletions doc/code/auxiliary_attacks/1_gcg_azure_ml.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@
# extension: .py
# format_name: percent
# format_version: '1.3'
# jupytext_version: 1.16.4
# jupytext_version: 1.17.1
# kernelspec:
# display_name: pyrit-dev
# display_name: pyrit-python313-fresh2
# language: python
# name: python3
# ---
Expand All @@ -31,13 +31,19 @@
# To connect to a workspace, we need identifier parameters - a subscription, resource group and workspace name. We will use these details in the `MLClient` from `azure.ai.ml` to get a handle to the required AML workspace. We use the [default Azure authentication](https://docs.microsoft.com/en-us/python/api/azure-identity/azure.identity.defaultazurecredential?view=azure-python) for this tutorial.

# %%
from pyrit.common import DUCK_DB, initialize_pyrit
import os

# Technically, we don't need to initialize PyRIT locally as the job is running in Azure.
# However, we store environment variables in .env or .env.local files, which are read by PyRIT.
# If you set your environment variables differently, you can skip this step.
initialize_pyrit(memory_db_type=DUCK_DB)

# Enter details of your AML workspace
subscription_id = os.environ.get("AZURE_SUBSCRIPTION_ID")
resource_group = os.environ.get("AZURE_RESOURCE_GROUP")
workspace = os.environ.get("AZURE_ML_WORKSPACE_NAME")
print(workspace)
print(subscription_id, resource_group, workspace)

# %%
from azure.ai.ml import MLClient
Expand Down Expand Up @@ -100,9 +106,11 @@
resources=JobResourceConfiguration(
instance_type="Standard_NC96ads_A100_v4",
instance_count=1,
),
)
)

# %%
# Submit the command
returned_job = ml_client.create_or_update(job)

# %%
Loading