SYNTOLOGY HomeExplorerAtlasCodeMethodologyAboutDevelopersFeedPricing
Paper · 2206.14157 · ICML · 2022

How to Steer Your Adversary: Targeted and Efficient Model Stealing Defenses with Gradient Redirection

Bo Li, Mantas Mazeika, David Forsyth

arXiv · PDF · Open in the Atlas

Code that ran

6 of 7 samples (functions and classes) lifted from this paper's linked repositories executed on a synthesized input in Syntology's jail (0 of them constructed an object rather than computing a result; 1 honoured the contract we drafted, 0 violated it and 1 has no contract verdict; 4 failures of our instrument; 1 no recorded run), measured 2026-11-23; repository links from the Papers with Code archive attributed under CC BY-SA, no affiliation; bodies inline only under a permissive licence as GitHub detects it. Not a reproduction of the paper's results.

"Ran" means the function executed on a synthesized input and returned a value. It is not a reproduction of the paper's results. This record, dated, as JSON: /api/ran/2206.14157.json · badge: /api/ran/2206.14157.svg

Each repository's role is a label: a classifier's output recorded on the link, or, where no role is recorded, what the Papers with Code archive marked. The line under it names its basis. Neither says who wrote the code.

RepositoryRoleRan
mmazeika/model-stealing-defenses canonical (classifier label)
classifier basis: classifier_2025
6 ran · 1 no recorded run
FunctionStatusWhere it lives
generate_perturbations Ran
ran on a synthesized input
mmazeika/model-stealing-defenses/batch_training/defenses.py
code served (permissive licence) · get_code("13e750f3398ad87c")
How it ran

Ran in Syntology's sandbox on this synthesized input (drafted by a language model, Claude Haiku 4.5, prompt python_fixture_v1) and returned Tensor, ndim 2, dtype family float; no output shape is stated. The image it ran in was not recorded. The code mentions cuda, and the harness aliases cuda to the CPU for every sample; whether this run needed that is not recorded. If your copy returns the same type and ndim on these inputs, it matched what we observed; nothing here checks that. It does NOT mean the output is correct: nothing has compared it to the paper.

import torch
import torch.nn as nn
import numpy as np

torch.manual_seed(0)
np.random.seed(0)

# Create a minimal dataset (list of (x, y) tuples)
class SimpleDataset(torch.utils.data.Dataset):
    def __init__(self, num_samples=8, input_dim=4, num_classes=3):
        self.num_samples = num_samples
        self.input_dim = input_dim
        self.num_classes = num_classes
    
    def __len__(self):
        return self.num_samples
    
    def __getitem__(self, idx):
        x = torch.randn(self.input_dim)
        y = torch.randint(0, self.num_classes, (1,)).item()
        return x, y

# Create minimal teacher network
class TeacherNet(nn.Module):
    def __init__(self, input_dim=4, num_classes=3):
        super().__init__()
        self.fc = nn.Linear(input_dim, num_classes)
    
    def forward(self, x):
        return self.fc(x)

# Create minimal student network
class StudentNet(nn.Module):
    def __init__(self, input_dim=4, num_classes=3):
        super().__init__()
        self.fc = nn.Linear(input_dim, num_classes)
    
    def forward(self, x):
        return self.fc(x)

# Create a minimal method function that takes (bx, teacher, student, epsilons, **kwargs)
def perturbation_method(bx, teacher, student, epsilons=None, **kwargs):
    """
    Minimal method that returns perturbed posteriors.
    Takes batch bx, teacher, student (list), and returns tensor of shape [batch_size, num_classes]
    """
    batch_size = bx.shape[0]
    num_classes = 3
    # Return a dummy tensor of perturbed posteriors
    return torch.randn(batch_size, num_classes)

# Instantiate components
dataset = SimpleDataset(num_samples=8, input_dim=4, num_classes=3)
teacher = TeacherNet(input_dim=4, num_classes=3)
student = [StudentNet(input_dim=4, num_classes=3)]

ARGS = {
    'dataset': dataset,
    'teacher': teacher,
    'student': student,
    'method': perturbation_method,
    'epsilons': [0.1, 0.2],
    'avg_posteriors': False,
    'sample_surrogates': False,
    'batch_size': 2,
    'num_workers': 0,
}
Setup block drafted by
a language model, Claude Haiku 4.5, prompt python_fixture_v1
Imports
numpy, torch, tqdm — import names as written, not package names to install; a name the repository itself provides is not a package
Returned
type Tensor, ndim 2, dtype family float — no output shape is stated: observe_signature.py could not observe it (call:AssertionError)
dtype family
int means an integer dtype; float means any other dtype the instrument saw, bool and complex included (fixture_check.py records only these two families)
Environment
image not recorded; re-verify against syntology-harvest-sandbox:v5-deps; not recorded for this sample: the harness installs a cuda-to-cpu shim (cuda_shim.py) before every sample and no run records whether a sample needed it; seed: none by the harness; any seed is in the setup block
get_Gty Ran
ran; our contract draft was wrong, not the code
mmazeika/model-stealing-defenses/batch_training/defenses.py
code served (permissive licence) · get_code("09f215fcca2c6687")
How it ran

Ran in Syntology's sandbox on this synthesized input (drafted by a language model, Claude Haiku 4.5, prompt python_fixture_v1, through the batch API) and returned Tensor, ndim 1, dtype family float, shape (67,) as a later run recorded it. The image it ran in was not recorded. If your copy returns the same type, ndim and shape on these inputs, it matched what we observed; nothing here checks that. It does NOT mean the output is correct: nothing has compared it to the paper.

import torch
import torch.nn as nn

torch.manual_seed(0)

# Create a simple student network
class SimpleStudent(nn.Module):
    def __init__(self, input_dim=4, num_classes=3):
        super().__init__()
        self.linear1 = nn.Linear(input_dim, 8)
        self.linear2 = nn.Linear(8, num_classes)
    
    def forward(self, x):
        x = torch.relu(self.linear1(x))
        x = self.linear2(x)
        return x

# Create batch of inputs (batch_size=2, input_dim=4)
bx = torch.randn(2, 4)

# Create student model
student = SimpleStudent(input_dim=4, num_classes=3)

# Create posterior y (batch_size=2, num_classes=3)
# This should be a probability distribution over classes
y = torch.nn.functional.softmax(torch.randn(2, 3), dim=1)

ARGS = {
    "bx": bx,
    "student": student,
    "y": y,
    "create_graph": False
}
Setup block drafted by
a language model, Claude Haiku 4.5, prompt python_fixture_v1, through the batch API
Imports
torch — import names as written, not package names to install; a name the repository itself provides is not a package
Returned
type Tensor, ndim 1, dtype family float, shape (67,) — shape (67,) as a later run recorded it
dtype family
int means an integer dtype; float means any other dtype the instrument saw, bool and complex included (fixture_check.py records only these two families)
Environment
image not recorded; re-verify against syntology-harvest-sandbox:v5-deps; not recorded for this sample: the harness installs a cuda-to-cpu shim (cuda_shim.py) before every sample and no run records whether a sample needed it; seed: none by the harness; any seed is in the setup block
get_Gty_partial Ran
ran; our contract draft was wrong, not the code
mmazeika/model-stealing-defenses/batch_training/defenses.py
code served (permissive licence) · get_code("a32c258cc539c295")
How it ran

Ran in Syntology's sandbox on this synthesized input (drafted by a language model, Claude Haiku 4.5, prompt python_fixture_v1, through the batch API) and returned Tensor, ndim 1, dtype family float, shape (27,) as a later run recorded it. The image it ran in was not recorded. If your copy returns the same type, ndim and shape on these inputs, it matched what we observed; nothing here checks that. It does NOT mean the output is correct: nothing has compared it to the paper.

import torch
import torch.nn as nn

torch.manual_seed(0)

# Create a simple student network that takes input and produces logits
class StudentNetwork(nn.Module):
    def __init__(self, input_dim=4, num_classes=3):
        super().__init__()
        self.fc1 = nn.Linear(input_dim, 8)
        self.fc2 = nn.Linear(8, num_classes)
    
    def forward(self, x):
        x = torch.relu(self.fc1(x))
        x = self.fc2(x)
        return x

# Create student network
student = StudentNetwork(input_dim=4, num_classes=3)

# Create batch of image inputs (batch_size=2, features=4)
bx = torch.randn(2, 4)

# Create posterior y (batch_size=2, num_classes=3)
# Should be a probability distribution over classes
y = torch.nn.functional.softmax(torch.randn(2, 3), dim=1)

# Create backprop_modules - we'll use just the second layer
backprop_modules = [student.fc2]

# create_graph parameter
create_graph = False

ARGS = {
    "bx": bx,
    "student": student,
    "y": y,
    "backprop_modules": backprop_modules,
    "create_graph": create_graph,
}
Setup block drafted by
a language model, Claude Haiku 4.5, prompt python_fixture_v1, through the batch API
Imports
torch — import names as written, not package names to install; a name the repository itself provides is not a package
Returned
type Tensor, ndim 1, dtype family float, shape (27,) — shape (27,) as a later run recorded it
dtype family
int means an integer dtype; float means any other dtype the instrument saw, bool and complex included (fixture_check.py records only these two families)
Environment
image not recorded; re-verify against syntology-harvest-sandbox:v5-deps; not recorded for this sample: the harness installs a cuda-to-cpu shim (cuda_shim.py) before every sample and no run records whether a sample needed it; seed: none by the harness; any seed is in the setup block
inner_product Ran
ran, honoured the contract we drafted
mmazeika/model-stealing-defenses/batch_training/defenses.py
code served (permissive licence) · get_code("48adfe61c28e64c8")
How it ran

Ran in Syntology's sandbox on this synthesized input (drafted by a language model, Claude Haiku 4.5, prompt python_fixture_v1) and returned Tensor, ndim 0, dtype family float, shape () as a later run recorded it. The image it ran in was not recorded. If your copy returns the same type, ndim and shape on these inputs, it matched what we observed; nothing here checks that. It does NOT mean the output is correct: nothing has compared it to the paper.

import torch

torch.manual_seed(0)

# The function inner_product takes two arguments x1 and x2
# It performs element-wise multiplication and sums the result
# Both arguments should be tensors that can be multiplied together

x1 = torch.randn(2, 4)
x2 = torch.randn(2, 4)

ARGS = {
    "x1": x1,
    "x2": x2,
}
Setup block drafted by
a language model, Claude Haiku 4.5, prompt python_fixture_v1
Imports
torch — import names as written, not package names to install; a name the repository itself provides is not a package
Returned
type Tensor, ndim 0, dtype family float, shape () — shape () as a later run recorded it
dtype family
int means an integer dtype; float means any other dtype the instrument saw, bool and complex included (fixture_check.py records only these two families)
Environment
image not recorded; re-verify against syntology-harvest-sandbox:v5-deps; not recorded for this sample: the harness installs a cuda-to-cpu shim (cuda_shim.py) before every sample and no run records whether a sample needed it; seed: none by the harness; any seed is in the setup block
make_param_generator Ran
ran; our contract draft was wrong, not the code
mmazeika/model-stealing-defenses/batch_training/defenses.py
code served (permissive licence) · get_code("6a1f70487d995667")
How it ran

Ran in Syntology's sandbox on this synthesized input (drafted by a language model, Claude Haiku 4.5, prompt python_fixture_v1) and returned chain. The image it ran in was not recorded. If your copy returns the same type on these inputs, it matched what we observed; nothing here checks that. It does NOT mean the output is correct: nothing has compared it to the paper.

import torch
import torch.nn as nn
from itertools import chain

torch.manual_seed(0)

# Create small nn.Module instances
class SimpleModel1(nn.Module):
    def __init__(self):
        super().__init__()
        self.linear = nn.Linear(4, 3)
    
    def forward(self, x):
        return self.linear(x)

class SimpleModel2(nn.Module):
    def __init__(self):
        super().__init__()
        self.linear = nn.Linear(3, 2)
    
    def forward(self, x):
        return self.linear(x)

class SimpleModel3(nn.Module):
    def __init__(self):
        super().__init__()
        self.conv = nn.Conv1d(2, 5, kernel_size=3)
    
    def forward(self, x):
        return self.conv(x)

# Instantiate models
model1 = SimpleModel1()
model2 = SimpleModel2()
model3 = SimpleModel3()

# Create list of modules
modules = [model1, model2, model3]

ARGS = {
    "modules": modules
}
Setup block drafted by
a language model, Claude Haiku 4.5, prompt python_fixture_v1
Imports
torch — import names as written, not package names to install; a name the repository itself provides is not a package
Returned
type chain — a chain output has no array shape of its own; none is stated — the instrument coerces any output to an array; for a chain output the recorded ndim 0 and dtype family float describe that coercion, not the output, and are not stated
Environment
image not recorded; re-verify against syntology-harvest-sandbox:v5-deps; not recorded for this sample: the harness installs a cuda-to-cpu shim (cuda_shim.py) before every sample and no run records whether a sample needed it; seed: none by the harness; any seed is in the setup block
make_param_generator Ran
ran; our contract draft was wrong, not the code
mmazeika/model-stealing-defenses/batch_training/defenses.py
code served (permissive licence) · get_code("58447667322eda73")
How it ran

Ran in Syntology's sandbox on this synthesized input (drafted by a language model, Claude Haiku 4.5, prompt python_fixture_v1, through the batch API) and returned chain. The image it ran in was not recorded. If your copy returns the same type on these inputs, it matched what we observed; nothing here checks that. It does NOT mean the output is correct: nothing has compared it to the paper.

import torch
import torch.nn as nn
from itertools import chain

torch.manual_seed(0)

# Create a few simple PyTorch modules
class SimpleModule1(nn.Module):
    def __init__(self):
        super().__init__()
        self.linear = nn.Linear(4, 3)
    
    def forward(self, x):
        return self.linear(x)

class SimpleModule2(nn.Module):
    def __init__(self):
        super().__init__()
        self.linear = nn.Linear(3, 2)
    
    def forward(self, x):
        return self.linear(x)

class SimpleModule3(nn.Module):
    def __init__(self):
        super().__init__()
        self.conv = nn.Conv1d(2, 5, 3)
    
    def forward(self, x):
        return self.conv(x)

# Instantiate modules
module1 = SimpleModule1()
module2 = SimpleModule2()
module3 = SimpleModule3()

# Create the modules list argument
modules = [module1, module2, module3]

ARGS = {
    "modules": modules
}
Setup block drafted by
a language model, Claude Haiku 4.5, prompt python_fixture_v1, through the batch API
Imports
torch — import names as written, not package names to install; a name the repository itself provides is not a package
Returned
type chain — a chain output has no array shape of its own; none is stated — the instrument coerces any output to an array; for a chain output the recorded ndim 0 and dtype family float describe that coercion, not the output, and are not stated
Environment
image not recorded; re-verify against syntology-harvest-sandbox:v5-deps; not recorded for this sample: the harness installs a cuda-to-cpu shim (cuda_shim.py) before every sample and no run records whether a sample needed it; seed: none by the harness; any seed is in the setup block
method_gradient_redirection Not yet run
unverified (harvested, no recorded run)
mmazeika/model-stealing-defenses/batch_training/defenses.py
code served (permissive licence) · get_code("d425100e749a4c35")
How it ran

no invocation recorded.

Also present in other papers' code

Of 7 samples lifted from this paper's linked repositories, 7 carry a function identity and 0 do not. Of the 6 distinct functions with an identity, 0 are also present in other papers whose code we hold (0 with at least one paper dated earlier, 0 the same month, 0 later) and 6 are only here among the 52,977 papers whose code Syntology holds (as of 2026-09-26).

Only here means: among the 52,977 papers whose code Syntology holds (51,887 with lifted samples, 1,090 through their assemblies only), as of 2026-09-26, no other paper's lifted samples or current assembly bricks contain an identical function body after normalisation.

Presence, not direction: an identical function body in two papers' repositories does not say who wrote it, which came from which, or that either paper's method rests on it. Matching is exact after normalisation, so a renamed or edited function is not matched. Dates are when papers appeared, not when code was written. Only .py files the harvester lifted are covered; notebooks are not read. A new-style arXiv id YYMM.NNNN dates a paper to the month 20YY-MM; otherwise Paper.year dates it to the year; otherwise it is undated. Dates are when the paper appeared, not when the code was written. Read 2026-11-23.

Repositories linked to this paper

Some links come from the archived Papers with Code dataset (CC BY-SA 4.0): attribution and licence.

Abstract

Model stealing attacks present a dilemma for public machine learning APIs. To protect financial investments, companies may be forced to withhold important information about their models that could facilitate theft, including uncertainty estimates and prediction explanations. This compromise is harmful not only to users but also to external transparency. Model stealing defenses seek to resolve this dilemma by making models harder to steal while preserving utility for benign users. However, existing defenses have poor performance in practice, either requiring enormous computational overheads or severe utility tradeoffs. To meet these challenges, we present a new approach to model stealing defenses called gradient redirection. At the core of our approach is a provably optimal, efficient algorithm for steering an adversary's training updates in a targeted manner. Combined with improvements to surrogate networks and a novel coordinated defense strategy, our gradient redirection defense, called GRAD 2 , achieves small utility trade-offs and low computational overhead, outperforming the best prior defenses. Moreover, we demonstrate how gradient redirection enables reprogramming the adversary with arbitrary behavior, which we hope will foster work on new avenues of defense.

For agents

The same record, over MCP at https://syntology.ai/mcp:

get_harvested_code_for_paper("2206.14157")
get_code_for_paper("2206.14157")
have("2206.14157")

The run record, dated, one paper per request, free:

curl https://syntology.ai/api/ran/2206.14157.json

A badge for a README (the split and the date, never a ratio):

[![Syntology run record](https://syntology.ai/api/ran/2206.14157.svg)](https://syntology.ai/paper/2206.14157)

Connect an agent — have() is free.