Generating GCG adversarial suffixes with PyRIT on Azure Machine Learning

PyRIT can generate GCG adversarial suffixes as an Azure Machine Learning training job on GPU compute. This page explains the environment it builds, the setup sequence, and how the suffixes feed later red teaming attacks.

On this page

Generating GCG suffixes with PyRIT on Azure ML: what the job does and when to run it

Red teaming teams that want optimized adversarial suffixes without tying up local hardware can have PyRIT run GCG suffix generation as an Azure Machine Learning job on GPU compute. The workflow connects to an Azure ML workspace, builds an environment from a Dockerfile based on an NVIDIA CUDA image with Python 3.11 and the pyrit gcg extra installed, and submits a training job that runs the optimization. It is worth using when you need GCG suffixes at a scale or on hardware your workstations cannot supply, and when your team can accept that the feature is still experimental. PyRIT marked GCG as experimental in v0.14.0, which introduced the public GCG and GCGConfig API, so expect the interface to change between releases and pin your PyRIT version.

Before you submit anything, confirm three things with your own environment rather than assuming them. First, that your Azure subscription has GPU quota in the region of your workspace, since the job runs on that compute and the cost is billed to your subscription, not to PyRIT or DeployOpen. Second, that the identity running the job has the Azure ML roles needed to create environments and submit jobs in that workspace, and that its access to any storage holding inputs and outputs is scoped to the project. Third, that the CUDA base image and Python version you build against are supported by the PyRIT release you have installed. The setup guide in the PyRIT documentation is the reference for the exact configuration keys and workspace fields, and your Azure administrators should review them before the first run.

The job is a batch process. It consumes the compute you provision, produces suffixes as output, and stops, so the recurring costs are the GPU hours you consume, the storage for environments and results, and the engineering time to keep the environment current with PyRIT upgrades. Plan for the one-time work too: building and testing the Dockerfile, agreeing who owns the workspace, and deciding where generated suffixes are stored and reviewed. Ask any partner for a written scope that names the workspace, the GPU sku, the PyRIT version and the handover of the environment definition, so you can compare the cost against running the same job on your own team's hardware.

Configuration options for GCG runs and when each fits

This table compares the choices a team makes before submitting a GCG suffix job: where it runs, how the environment is built, and which GCGConfig settings define the attack. Read each row for when the option fits and what it costs in flexibility or operating effort. Confirm exact parameter names in the GCGConfig API reference before writing configuration code.

DecisionOptionTrade-offWhen it fits
Azure ML workspace and compute targetDedicated GPU compute target in an existing workspaceReuses your governance, networking and identity, but GPU quota and region availability must be confirmed firstYour team already runs Azure ML and needs runs logged and auditable
Azure ML workspace and compute targetNew workspace created only for red teamingIsolates test artifacts and access, but adds a workspace to govern and monitorSecurity testing must be separated from data science projects
Dockerfile and CUDA base imageProvided NVIDIA CUDA base image with Python 3.11Matches the documented setup, so troubleshooting is simplerYou want the documented path with few local changes
Dockerfile and CUDA base imageCustom base image pinned to your approved CUDA and driver versionsMatches internal patch policy, but you own rebuilds and compatibility checks with the GPU driverYour platform team requires approved base images from a private registry
Install methodpyrit gcg extra installed in the job environmentKeeps the job reproducible with the PyRIT version you tested, but pins the release you must upgrade deliberatelyRepeatable runs where the suffix generation code must match a known version
Install methodLocal run on your own GPU hostFast iteration and no cloud job overhead, but reproducibility and audit trails depend on your own processEarly experiments, small prompt sets or debugging GCG behavior
GCGConfig: objectiveHarmful objective taken from an approved datasetConsistent with other PyRIT results, but the choice determines what the suffix is optimized to elicitRegression testing a known objective set agreed in your test plan
GCGConfig: target modelOpen-weight model you host or can load into the jobGradient-based optimization needs model access, so closed API targets are not usable for this stepTesting a self-hosted model whose weights your team controls
GCGConfig: suffix and iteration settingsDefault settings from the API referenceLowest setup effort, but cost and success depend on iteration count and suffix lengthFirst runs, used to establish a baseline before tuning

Setup sequence for a GCG suffix job on Azure ML

This sequence takes a team from a clean machine to a finished GCG suffix job on Azure Machine Learning GPU compute, with a check at each step so failures surface before the expensive training run starts. The closing output is a stored suffix that later PyRIT attacks can consume.

  1. Install PyRIT on a supported Python version

    Create a virtual environment on Python 3.10 or later but below 3.15, and the documentation recommends Python 3.13. Install PyRIT with pip, using the GCG extra if your local setup needs it for testing. The check is that pyrit imports cleanly in that environment and the installed version matches the release you intend to use, such as 1.1.0 documented for this pillar. Record the version, because the Dockerfile and the job should reference the same release.

  2. Prepare the Azure ML workspace and access

    Confirm with your Azure administrator that an Azure Machine Learning workspace exists, that a GPU compute target is available to your subscription, and that the identity you will use can create environments and submit jobs in that workspace. Ask for the workspace name, resource group, subscription ID and the GPU SKU you are allowed to use. The check is that you can sign in from the local machine and list the workspace and its compute targets without errors.

  3. Configure credentials and settings for PyRIT

    Place Azure connection details in the credentials file at ~/.pyrit/.env and set the workspace and run options in ~/.pyrit/.pyrit_conf, keeping secrets out of shared repositories. Use the variable names given in the PyRIT documentation for the Azure ML example, and do not paste secret values into the job definition. The check is that a short Python script can read the configuration and reach the workspace, with the secret values never printed to logs.

  4. Build the Dockerfile environment

    Write or adopt a Dockerfile based on an NVIDIA CUDA image with Python 3.11, and install PyRIT with the gcg extra so the GCG code and its dependencies are present in the image. The image Python version is set by the documentation and differs from your local interpreter, which is expected. The check is a local build of the image that completes and a container run that imports the GCG module without errors before you register the environment.

  5. Register the environment in the workspace

    Create the Azure ML environment from the Dockerfile so the workspace builds and stores the image for the training job. Assign a clear name and version so the job can be traced back to the exact Dockerfile and PyRIT release used. The check is that the environment appears in the workspace with a build status of completed, and its image reference matches the one you tested locally.

  6. Submit the GCG training job

    Submit the GCG job through PyRIT's Azure ML path so it runs on the GPU compute target with the registered environment, the chosen GCG configuration and your objective inputs. Expect GPU time to be the main cost driver, so confirm with your team the compute SKU, the maximum run length and who approves the spend before submission. The check is that the job is accepted and appears in the workspace with a running or queued status and a job link.

  7. Verify completion and the stored suffix

    When the job finishes, confirm its status is completed in the Azure ML studio and review the logs for errors or early termination. Locate the output artifact that holds the generated suffix and copy its reference into your attack configuration or project notes, along with the PyRIT version and GCG settings. The check is that the artifact downloads, contains a suffix string, and that a short test prompt against your target runs with the suffix applied before you use it in a wider test.

Where GCG costs time and attention

GCG suffix generation spends GPU hours, depends on an experimental API, and produces suffixes tied to specific models. The cards below cover the decisions that decide whether a run is worth its cost and whether its output is useful against the model you actually serve.

GPU compute cost and payer

Each GCG job runs on GPU compute in your Azure subscription, so the cost lands on whoever owns that subscription and quota. Confirm which team pays for the GPU SKU, whether the run uses reserved or on-demand capacity, and who approves jobs. Ask for the cost per job from your own test run before scheduling a batch, because the figure depends on region, SKU and how long the optimization takes on your target.

GCG Azure ML docs

Experimental status and API change

PyRIT marked GCG as experimental in v0.14.0 and introduced the public GCG and GCGConfig API at that point. Pin the PyRIT version in your environment file and record it with each suffix, so a later release that changes the configuration does not silently alter results. Review the release notes before any upgrade and rerun a small job after moving versions.

v0.14.0 release notes

Matching the suffix to the target

A GCG suffix is optimized against a specific model and tokenizer, so a suffix found on an open-weight model is not guaranteed to work on the model your users reach. Decide which model the optimization targets and document it next to the suffix. Test the suffix against the exact model version, system prompt and filters in production, and treat a mismatch as a different test rather than a failed one.

Job duration and queue time

A GCG run occupies a GPU for the length of its optimization, and Azure ML adds time for environment build and queueing. Measure these phases on your own runs and record them separately, since image builds are paid once while optimization repeats. Plan the schedule around the slowest phase, and confirm the expected duration with the team that will run the job before committing a test window.

Transfer to the production model

A suffix that succeeds in optimization may fail against a production deployment, and a suffix that fails may still work after model updates. Decide in advance what a transfer result means for your risk assessment and whether you will rerun optimization per model. Score transfer attempts with the same scorers and objectives you use for other attacks so results can be compared.

How the GCG job flows from PyRIT to Azure ML and back into attacks

The flow starts on the team's local machine, where PyRIT connects to an Azure Machine Learning workspace and submits a training job after building an environment from a Dockerfile. The job runs on GPU compute inside the team's Azure subscription, and the generated suffix is saved as job output. A later PyRIT attack reads that suffix and sends it to the target endpoint, which sits outside the team's trust boundary. Check who can read the stored output and what leaves the subscription when the suffix is used.

Data path from the local client through the Azure ML job to a target.

How generated suffixes feed later PyRIT attacks

A GCG suffix is not a finished attack. It is an artifact that gets appended to prompts in later PyRIT attacks, so the generation record has to travel with it. Store the suffix together with the objective it was optimized for, the target model and version it was optimized against, and the exact GCG and GCGConfig settings used for the Azure Machine Learning job. Without that bundle, a suffix that looks effective in a later run cannot be explained, repeated or defended to a reviewer. Give each generated suffix an identifier in your own naming scheme and tie it to the job name and the environment version that produced it.

PyRIT memory is where the trace should live. It stores conversations and results in SQLite or Azure SQL, so configure the memory backend before the first run and point the suffix attack runs at the same store. Then each later attack can be linked to the suffix identifier, the target and the scorer output. This lets the team answer basic questions: which prompts used the suffix, which targets were tested, and whether the result changed after a model update. Confirm the current memory schema and query options in the PyRIT documentation for the version you run, since the fields available for filtering depend on that version.

Do not assume a suffix transfers. A suffix optimized against one model may not work against another model, a different system prompt, or the same model after a provider update. Treat every suffix as scoped to the target it was generated for until you have tested it against each other target you care about. Run the same objective against the generating model and against each candidate target, keep the results separate, and record any difference as a finding. Confirm transfer behavior in your own environment with your own targets and scorers rather than relying on a general expectation.

Security and operational controls for the GCG workspace

A GCG job touches model credentials, GPU compute, generated artifacts and conversation records, and each needs its own control. The cards below cover the controls to set before the first job runs, and what to confirm in your own Azure tenant and PyRIT deployment.

Credential handling in pyrit.env

PyRIT reads credentials from ~/.pyrit/.env and settings from ~/.pyrit/.pyrit_conf. On a shared build host or a job runner, that file is the first place a secret can leak. Keep the file readable only by the account that runs PyRIT, keep it out of container images and source control, and confirm which values the Azure ML job actually needs so that workspace secrets are not copied into the environment by default. Check who else can read the runner's home directory.

PyRIT docs

Least-privilege workspace access

Submitting a training job needs rights to the Azure Machine Learning workspace, its environments and its compute. Grant the submitting identity only those roles, scope them to the workspace rather than the subscription, and separate the people who can submit jobs from those who can change the compute cluster. Confirm the role assignments with your Azure administrator before the first run, and review them whenever the team that runs red teaming changes.

Protecting generated suffixes and conversations

A GCG suffix is an adversarial string that can make a model comply with requests it would otherwise refuse, so the suffixes and the conversations that used them are sensitive records. Store them in access-controlled locations, restrict who can read PyRIT memory, and decide whether the SQLite file or Azure SQL database will hold them. Ask who may export them and how long they are kept.

Network isolation of the GPU job

The GPU compute that runs GCG should sit in a network you control, with outbound paths limited to the model endpoints and package sources the job needs. Confirm whether the workspace uses a managed virtual network, private endpoints for storage and container registries, and whether the compute can reach the internet at all. Record the egress rules so a reviewer can see what the job could contact.

Logging and retention of job outputs

Each job run leaves logs, metrics and output artifacts in the workspace. Decide which diagnostic logs are sent to your monitoring platform, who can read them, and how long each class of output is kept. Set retention in line with your policy and confirm the default retention for workspace storage with Azure, since the retention settings are yours to choose and must be documented for reviewers.

Reporting PyRIT vulnerabilities

If testing shows a flaw in PyRIT itself, such as a defect in how it handles credentials or job submission, report it privately. PyRIT's README points to the Microsoft Security Response Center under the project's security policy. Do not post exploit details or suffix strings in public issues. Record the report route in your runbook so the on-call engineer knows where to send it.

PyRIT repository

Questions teams ask before running GCG suffixes on Azure ML

How much effort and cost does a GCG suffix run on Azure ML involve?

The main costs are GPU compute time on Azure ML, the engineer hours to build the environment and submit the job, and the time to review what the run produces. Compute is billed by Azure for the GPU capacity the training job uses, so the bill depends on the GPU size, how many optimization steps you run and how often you rerun with different settings. Engineering time is usually the larger one-time cost, since the first environment build, workspace permissions and job configuration take the most attention. Ask any quote to separate one-time setup from recurring compute, and to state which Azure ML workspace, GPU SKU and run configuration it assumes.

Can an internal team run GCG suffixes without outside help?

Yes, if the team already operates Azure ML, can build a CUDA-based Docker environment and is comfortable with Python and GPU jobs. The PyRIT documentation describes the full path: connect to a workspace, create an environment from a Dockerfile, and submit a training job. A partner helps when the team lacks Azure ML or GPU experience, needs the run to fit an approved landing zone and subscription policy, or wants the suffixes wired into a repeatable test program that other attacks can consume. Teams often split the work, with internal staff owning the objective and review and an outside team handling environment and pipeline setup.

How long does a first GCG run take to set up?

The duration depends on your environment, so confirm it with your own team before planning a date. The main variables are how quickly you get workspace and subscription access, whether a GPU quota is already available in your region, how familiar the team is with Docker and Azure ML environments, and whether the first job exposes dependency or permission problems. A team with an existing Azure ML workspace and approved GPU quota will move much faster than one starting from a new subscription. Ask for a written milestone plan that separates access approval, environment build, a first small job and review of the output.

What does the work need from our side?

Expect to provide access and decisions before any job runs. You will need:

  • An Azure ML workspace, or permission to create one, in a subscription that allows GPU compute
  • Approval for the GPU SKU and quota in the target region, which your cloud or finance owners may need to sign off
  • Network and identity access for the workspace, including the storage and container registry the environment uses
  • Access to the target endpoint that the generated suffixes will later be tested against, with a named owner who can answer questions about its behavior
  • An agreed objective and a named reviewer for the results

Confirm the exact permissions your Azure policy requires with your cloud administrators before the engagement starts.

Is GCG production-ready given its experimental status?

No, treat it as an experimental research technique for controlled testing. PyRIT v0.14.0 marked GCG as experimental and introduced the GCG and GCGConfig public API, so its interface and behavior may still change between releases. Pin the PyRIT version you test with, record it in your evidence, and expect to revalidate results after an upgrade. Use GCG suffixes to probe a deployment you own and are authorized to test, not as a gate that a release must pass. Your security owner should decide how GCG results fit into the broader red teaming program.

How are the generated suffixes evaluated afterward?

A generated suffix is only useful if you measure what it does against a target. Run each suffix against the same objectives you use in other attacks, using the same target configuration, and score the responses with a defined scorer. Record the suffix, the PyRIT version, the target model version and the scorer output in memory so the result can be reproduced. Keep a holdout set of objectives the suffix was not optimized on, since a suffix that only works on its training prompts says little about the deployment. Ask your team to define the pass or fail criteria before the first run, not after.

How do generated suffixes feed later attacks in PyRIT?

Once a suffix is generated, it becomes an input string that other attacks can append to prompts sent to the target. The practical flow is to store the suffix with its run metadata, load it into the attack that sends your objectives, and compare the target's responses with and without it. Engineers should confirm how their PyRIT version exposes the suffix and whether the attack they plan to use expects a single string or a set. Keep suffix runs and attack runs in the same memory store so the link between them is traceable.

How DeployOpen scopes and delivers GCG suffix generation on Azure ML

DeployOpen scopes GCG suffix generation in writing before any work starts, because the job touches your Azure subscription, GPU quota, data and access model. The first step is to confirm the Azure Machine Learning workspace, the resource group it sits in, the compute target that will run the training job, and which identities may create environments, submit jobs and read outputs. We also agree the target model or endpoint the suffixes will be generated against, the objective strings and the success criteria, and who receives the results. Engagements are fixed-scope, so the deliverables, the environment, the number of runs and the handover items are set out in a written scope that you approve before we begin.

Delivery follows the sequence in the PyRIT documentation. We connect to your workspace, build the environment from a Dockerfile based on an NVIDIA CUDA image with Python 3.11 and the pyrit gcg extra, and test the image on a small job before any long GCG run. The GCG job is then submitted against the agreed target, and we check its logs, output and resource use against the scope. Results are recorded in PyRIT memory, which uses SQLite or Azure SQL, so that each suffix can be traced to the job, configuration and target that produced it. Because GCG is marked experimental in PyRIT v0.14.0, we also confirm the version you pin and the API it exposes before relying on it.

At handover you receive the environment definition, job configuration, memory records, a runbook covering reruns, quota and cost checks, and a list of open items for your team to confirm. Ongoing support, upgrades and retesting as PyRIT changes are available as a retainer, which is a separate written agreement. Before accepting a quote, ask who owns the Azure resources and the generated data at the end of the engagement, how access is removed afterwards, and which costs are billed directly by Azure and which are included in the DeployOpen fee.

Sources and further reading

Talk to our team.

Tell us what you're working on, whether it's a deployment, an audit, a security test or a cyber range. You'll speak with an engineer who can help you scope it.

  • 30-minute call: free, with no obligation.
  • NDA on request: we can sign before you share details.
  • Clear next steps: a scope and plan after the call.