SYNTOLOGY HomeExplorerAtlasCodeMethodologyAboutDevelopersFeedPricing
Paper · 2410.20197 · 2024

Transferable Adversarial Attacks on SAM and Its Downstream Models

arXiv · PDF · Open in the Atlas

Code that ran

8 of 11 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; 0 honoured the contract we drafted, 1 violated it and 0 have no contract verdict; 7 failures of our instrument; 3 no recorded run), measured 2026-11-22; 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/2410.20197.json · badge: /api/ran/2410.20197.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
xiasong0501/grat canonical (classifier label)
classifier basis: census
8 ran · 3 no recorded run
FunctionStatusWhere it lives
Minimize_domain_mean Ran
ran; our contract draft was wrong, not the code
xiasong0501/grat/one_sample_train.py
code served (permissive licence) · get_code("81afe23ae24a41b1")
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 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)

# Analyze the function:
# - features: used with .repeat() implicitly via len(), indexing, and multiplication
#   Expected to be a tensor with shape that allows len() and supports element-wise ops
# - targets: used with .repeat(len(features), 1, 1, 1) suggesting 3D or 4D tensor
#   The repeat call suggests targets is 3D (batch, height, width) or similar
#   After repeat, it becomes 4D to match features

# From the repeat pattern: targets.repeat(len(features), 1, 1, 1)
# This means targets should be 3D, and after repeat becomes 4D
# features should be 4D to match after repeat

# Let's construct:
# - features: shape (2, 4, 3, 5) - batch=2, channels=4, height=3, width=5
# - targets: shape (4, 3, 5) - will be repeated to (2, 4, 3, 5)

features = torch.randn(2, 4, 3, 5)
targets = torch.randn(4, 3, 5)

ARGS = {
    "features": features,
    "targets": targets,
}
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 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
common_direct_loss Ran
ran; our contract draft was wrong, not the code
xiasong0501/grat/Sam_attack_universal.py
code served (permissive licence) · get_code("63a5df1373ee6cc1")
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 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
import torch.nn as nn

torch.manual_seed(0)

# The function performs:
# 1. Subtracts selected_targets_layer from selected_features_layer
# 2. Divides by input_mean element-wise
# 3. Takes mean across dim=0
# 4. Computes absolute value and mean
# All inputs must be tensors that support arithmetic operations

# Create small tensors with distinct dimensions
# batch_size=2, feature_dim=4
batch_size = 2
feature_dim = 4

selected_features_layer = torch.randn(batch_size, feature_dim)
selected_targets_layer = torch.randn(batch_size, feature_dim)
input_mean = torch.ones(batch_size, feature_dim) * 0.5  # Non-zero to avoid division issues

ARGS = {
    "selected_features_layer": selected_features_layer,
    "selected_targets_layer": selected_targets_layer,
    "input_mean": input_mean,
}
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 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
common_direct_loss_weighted Ran
ran; our contract draft was wrong, not the code
xiasong0501/grat/Sam_attack_universal.py
code served (permissive licence) · get_code("1a6a138af1a89077")
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 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
import torch.nn as nn

torch.manual_seed(0)

# The function expects:
# - selected_features_layer: tensor that will be subtracted from selected_targets_layer
# - selected_targets_layer: tensor to subtract from selected_features_layer
# - input_mean: scalar or tensor used for division
# - gradient2: tensor that will be permuted (0, 3, 1, 2)
# - gradient1: tensor that will be permuted (0, 3, 1, 2)

# For permute(0, 3, 1, 2) to work, we need 4D tensors with shape (batch, height, width, channels)
# Let's use batch=2, height=4, width=3, channels=5
# After permute(0, 3, 1, 2): (2, 5, 4, 3)

batch_size = 2
height = 4
width = 3
channels = 5

selected_features_layer = torch.randn(batch_size, channels, height, width)
selected_targets_layer = torch.randn(batch_size, channels, height, width)

# input_mean is used for division, should be a scalar or broadcastable tensor
input_mean = torch.tensor(2.0)

# gradient2 and gradient1 need to be in (batch, height, width, channels) format before permute
gradient2 = torch.randn(batch_size, height, width, channels)
gradient1 = torch.randn(batch_size, height, width, channels)

ARGS = {
    "selected_features_layer": selected_features_layer,
    "selected_targets_layer": selected_targets_layer,
    "input_mean": input_mean,
    "gradient2": gradient2,
    "gradient1": gradient1,
}
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 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
input_diversity Ran
ran; our contract draft was wrong, not the code
xiasong0501/grat/Sam_attack.py
code served (permissive licence) · get_code("2a73ff4ab33a222f")
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 4, dtype family float, shape (2, 3, 4, 4) 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.functional as F

torch.manual_seed(0)

# The function takes a single parameter 'x' which is a tensor
# Looking at the function body:
# - x.shape[-1] is accessed (last dimension)
# - F.interpolate is called with x (needs at least 4D: batch, channels, height, width)
# - F.pad is called on the result
# - torch.rand(1) < diversity_prob comparison
# So x should be a 4D tensor (batch, channels, height, width)

x = torch.randn(2, 3, 4, 4)  # batch=2, channels=3, height=4, width=4

ARGS = {
    "x": x
}
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 4, dtype family float, shape (2, 3, 4, 4) — shape (2, 3, 4, 4) 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
normalize_tensor Ran
ran; the contract check could not run (RAISES, DEP_MISSING or TIMEOUT)
xiasong0501/grat/Sam_attack.py
code served (permissive licence) · get_code("1ad6a46df9edf55e")
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 5, dtype family float, shape (2, 3, 4, 5, 6) 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)

# Construct a 5D input tensor with shape (batch=2, channels=3, depth=4, height=5, width=6)
# The function expects a 5D tensor based on the final reshape to (len_tensor, 1, 1, 1, 1)
input_tensor = torch.randn(2, 3, 4, 5, 6)

ARGS = {
    "input_tensor": input_tensor
}
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 5, dtype family float, shape (2, 3, 4, 5, 6) — shape (2, 3, 4, 5, 6) 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
return_mean_value Ran
ran; our contract draft was wrong, not the code
xiasong0501/grat/Sam_attack.py
code served (permissive licence) · get_code("d64cb63ef26668bd")
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 5, dtype family float, shape (2, 1, 1, 1, 1) 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)

# The function expects a tensor that:
# 1. Has a len() (so it must be iterable along first dimension)
# 2. Each element input_tensor[i] must have a .mean() method
# 3. The result needs to support torch.stack()
# 4. The final result is reshaped to (-1, 1, 1, 1, 1)

# Create a small tensor with batch size 2, and some other dimensions
# Using distinct sizes: batch=2, dim1=4, dim2=3, dim3=5 for clarity
input_tensor = torch.randn(2, 4, 3, 5)

ARGS = {
    "input_tensor": input_tensor
}
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 5, dtype family float, shape (2, 1, 1, 1, 1) — shape (2, 1, 1, 1, 1) 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
select_op Ran
ran; the contract check could not run (RAISES, DEP_MISSING or TIMEOUT)
xiasong0501/grat/l2t.py
code served (permissive licence) · get_code("28ce88cbcad7b395")
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 list, ndim 1, dtype family int; no output shape is stated. The image it ran in was 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

torch.manual_seed(0)

# op_params: a tensor that will be passed through softmax
# Should be 1D tensor with num_elements to sample from
op_params = torch.randn(5)

# num_ops: number of operations to sample
num_ops = 3

ARGS = {
    "op_params": op_params,
    "num_ops": num_ops,
}
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 list, ndim 1, dtype family int — a list output has no array shape of its own; none is stated
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
trace_prob Ran
ran, violated the contract we drafted
xiasong0501/grat/l2t.py
code served (permissive licence) · get_code("29e23c69b7369fa0")
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 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)

# op_params: a tensor that will be passed to softmax
# The softmax is applied with dim=0, so we need a 1D tensor
# We'll create a small tensor of size 4
op_params = torch.randn(4)

# op_ids: a list/sequence of indices that index into the softmax output
# These indices should be valid (0-3 for a tensor of size 4)
op_ids = [0, 2, 1]

ARGS = {
    "op_params": op_params,
    "op_ids": op_ids,
}
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 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
attack Not yet run
unverified (harvested, no recorded run)
xiasong0501/grat/anda_ct.py
code served (permissive licence) · get_code("3c57221d88208eb2")
How it ran

no invocation recorded.

calc_loss Not yet run
unverified (harvested, no recorded run)
xiasong0501/grat/one_sample_train.py
code served (permissive licence) · get_code("40f56fce40b517b1")
How it ran

no invocation recorded.

vertical_shift Not yet run
unverified (harvested, no recorded run)
xiasong0501/grat/l2t.py
code served (permissive licence) · get_code("e7248679b9338973")
How it ran

no invocation recorded.

Also present in other papers' code

Of 11 samples lifted from this paper's linked repositories, 11 carry a function identity and 0 do not. Of the 11 distinct functions with an identity, 3 are also present in other papers whose code we hold (2 with at least one paper dated earlier, 0 the same month, 1 later) and 8 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.

FunctionAlso present inEarliest-datedOthers named
select_op 1 other paper
1 dated earlier
2405.14077 (2024-05)
Learning to Transform Dynamically for Better Adversarial Transferability
trace_prob 1 other paper
1 dated earlier
2405.14077 (2024-05)
Learning to Transform Dynamically for Better Adversarial Transferability
vertical_shift 1 other paper
1 later
Guo_Boosting_Adversarial_Transferability_through_Augmentation_in_Hypothesis_Space_CVPR_2025_paper (2025 (year only))
Boosting Adversarial Transferability through Augmentation in Hypothesis Space

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-22.

Repositories linked to this paper

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

Abstract

The utilization of large foundational models has a dilemma: while fine-tuning downstream tasks from them holds promise for making use of the well-generalized knowledge in practical applications, their open accessibility also poses threats of adverse usage. This paper, for the first time, explores the feasibility of adversarial attacking various downstream models fine-tuned from the segment anything model (SAM), by solely utilizing the information from the open-sourced SAM. In contrast to prevailing transfer-based adversarial attacks, we demonstrate the existence of adversarial dangers even without accessing the downstream task and dataset to train a similar surrogate model. To enhance the effectiveness of the adversarial attack towards models fine-tuned on unknown datasets, we propose a universal meta-initialization (UMI) algorithm to extract the intrinsic vulnerability inherent in the foundation model, which is then utilized as the prior knowledge to guide the generation of adversarial perturbations. Moreover, by formulating the gradient difference in the attacking process between the open-sourced SAM and its fine-tuned downstream models, we theoretically demonstrate that a deviation occurs in the adversarial update direction by directly maximizing the distance of encoded feature embeddings in the open-sourced SAM. Consequently, we propose a gradient robust loss that simulates the associated uncertainty with gradient-based noise augmentation to enhance the robustness of generated adversarial examples (AEs) towards this deviation, thus improving the transferability. Extensive experiments demonstrate the effectiveness of the proposed universal meta-initialized and gradient robust adversarial attack (UMI-GRAT) toward SAMs and their downstream models. Code is available at https://github.com/xiasong0501/GRAT.

For agents

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

get_harvested_code_for_paper("2410.20197")
get_code_for_paper("2410.20197")
have("2410.20197")

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

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

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

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

Connect an agent — have() is free.