SYNTOLOGY HomeExplorerAtlasCodeMethodologyAboutDevelopersFeedPricing
Paper · 2111.04706 · 2021

Bayesian Framework for Gradient Leakage

arXiv · PDF · Open in the Atlas

Code that ran

8 of 15 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; 2 honoured the contract we drafted, 0 violated it and 4 have no contract verdict; 2 failures of our instrument; 7 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/2111.04706.json · badge: /api/ran/2111.04706.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
eth-sri/bayes-framework-leakage canonical (classifier label)
classifier basis not recorded on the link
8 ran · 7 no recorded run
FunctionStatusWhere it lives
aggregate_batch_metrics Ran
ran; our contract draft was wrong, not the code
eth-sri/bayes-framework-leakage/bayes_optimal_attack/train_fed.py
code served (permissive licence) · get_code("7a8d40473bad4f08")
How it ran

Ran in Syntology's sandbox on this synthesized input (drafted by a language model, Claude Sonnet 4.5, prompt python_fixture_v1) and returned dict. 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 numpy as np

# Create a list of batch metrics dictionaries
# Each dictionary contains metric names as keys and scalar values
batch_metrics = [
    {'loss': 0.5, 'accuracy': 0.85, 'f1_score': 0.82},
    {'loss': 0.4, 'accuracy': 0.88, 'f1_score': 0.84},
    {'loss': 0.6, 'accuracy': 0.82, 'f1_score': 0.80},
]

ARGS = {
    'batch_metrics': batch_metrics
}
Setup block drafted by
a language model, Claude Sonnet 4.5, prompt python_fixture_v1
Imports
jax, numpy — import names as written, not package names to install; a name the repository itself provides is not a package
Returned
type dict — a dict output has no array shape of its own; none is stated — the instrument coerces any output to an array; for a dict 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
clip_prior Ran
ran on a synthesized input
eth-sri/bayes-framework-leakage/bayes_optimal_attack/utils/flax_losses.py
code served (permissive licence) · get_code("25d27557c295f410")
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 ArrayImpl, 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 jax
import jax.numpy as jnp

# Create small JAX arrays for the function parameters
# The function expects x, mean, and std as arrays
# x should be a batch of data with shape (batch_size, feature_dim)
# mean and std should have shape (feature_dim,) for broadcasting

batch_size = 2
feature_dim = 4

# Create random arrays
key = jax.random.PRNGKey(0)
key, subkey1, subkey2, subkey3 = jax.random.split(key, 4)

x = jax.random.normal(subkey1, (batch_size, feature_dim))
mean = jax.random.normal(subkey2, (feature_dim,))
std = jnp.abs(jax.random.normal(subkey3, (feature_dim,))) + 0.1  # ensure positive

ARGS = {
    "x": x,
    "mean": mean,
    "std": std
}
Setup block drafted by
a language model, Claude Haiku 4.5, prompt python_fixture_v1, through the batch API
Imports
jax — import names as written, not package names to install; a name the repository itself provides is not a package
Returned
type ArrayImpl, 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
get_flax_network Ran
ran on a synthesized input
eth-sri/bayes-framework-leakage/bayes_optimal_attack/models/base_flax.py
code served (permissive licence) · get_code("fe68615417093add")
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 MLP_Flax. 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 jax
import jax.numpy as jnp
from flax import linen as nn

# Test the get_flax_network function with different network names
ARGS = {
    "name": "mlp_128_64_10"
}
Setup block drafted by
a language model, Claude Haiku 4.5, prompt python_fixture_v1, through the batch API
Imports
flax, jax — import names as written, not package names to install; a name the repository itself provides is not a package
Returned
type MLP_Flax — a MLP_Flax output has no array shape of its own; none is stated — the instrument coerces any output to an array; for a MLP_Flax 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
l2_loss Ran
ran, honoured the contract we drafted
eth-sri/bayes-framework-leakage/bayes_optimal_attack/utils/losses.py
code served (permissive licence) · get_code("85e8d399b0c6a236")
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 ArrayImpl, 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 jax
import jax.numpy as jnp

# Construct a small iterable of JAX arrays
# The function sums the squared elements of each array, so we need valid jnp.ndarray objects
params = [
    jnp.array([[1.0, 2.0, 3.0], [4.0, 5.0, 6.0]]),  # shape (2, 3)
    jnp.array([0.5, 1.5, 2.5, 3.5]),  # shape (4,)
    jnp.array([[[1.0, 2.0], [3.0, 4.0]]])  # shape (1, 2, 2)
]

ARGS = {
    "params": params
}
Setup block drafted by
a language model, Claude Haiku 4.5, prompt python_fixture_v1, through the batch API
Imports
jax — import names as written, not package names to install; a name the repository itself provides is not a package
Returned
type ArrayImpl, 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
numpy_collate Ran
ran, honoured the contract we drafted
eth-sri/bayes-framework-leakage/bayes_optimal_attack/datasets/common.py
code served (permissive licence) · get_code("b683ce54519b23b0")
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 ndarray, ndim 2, dtype family int, shape (2, 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 numpy as np

# Test case 1: batch of numpy arrays
batch_arrays = [np.array([1, 2, 3, 4]), np.array([5, 6, 7, 8])]

# Test case 2: batch of tuples (each tuple contains arrays and scalars)
batch_tuples = [
    (np.array([1, 2, 3, 4]), np.array([10, 20])),
    (np.array([5, 6, 7, 8]), np.array([30, 40]))
]

# Test case 3: batch of lists
batch_lists = [
    [np.array([1.0, 2.0, 3.0]), 100],
    [np.array([4.0, 5.0, 6.0]), 200]
]

# Choose one batch to test - using arrays as the primary test case
ARGS = {
    "batch": batch_arrays
}
Setup block drafted by
a language model, Claude Haiku 4.5, prompt python_fixture_v1, through the batch API
Imports
numpy — import names as written, not package names to install; a name the repository itself provides is not a package
Returned
type ndarray, ndim 2, dtype family int, shape (2, 4) — shape (2, 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
slugify Ran
ran; our contract draft was wrong, not the code
eth-sri/bayes-framework-leakage/bayes_optimal_attack/tune_attacks_dp.py
code served (permissive licence) · get_code("7c683413a2f8a345")
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 str. 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 unicodedata
import re

def slugify(value, allow_unicode=False):
    """
    Taken from https://github.com/django/django/blob/master/django/utils/text.py
    Convert to ASCII if 'allow_unicode' is False. Convert spaces or repeated
    dashes to single dashes. Remove characters that aren't alphanumerics,
    underscores, or hyphens. Convert to lowercase. Also strip leading and
    trailing whitespace, dashes, and underscores.
    """
    value = str(value)
    if allow_unicode:
        value = unicodedata.normalize('NFKC', value)
    else:
        value = unicodedata.normalize('NFKD', value).encode('ascii', 'ignore').decode('ascii')
    value = re.sub('[^\\w\\s-]', '', value.lower())
    return re.sub('[-\\s]+', '-', value).strip('-_')


ARGS = {
    'value': 'Hello World --- Test_String!!!',
    'allow_unicode': False
}
Setup block drafted by
a language model, Claude Haiku 4.5, prompt python_fixture_v1, through the batch API
Imports
none outside the standard library — import names as written, not package names to install; a name the repository itself provides is not a package
Returned
type str — a str output has no array shape of its own; none is stated — the instrument coerces any output to an array; for a str 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
softmax_cross_entropy Ran
ran on a synthesized input
eth-sri/bayes-framework-leakage/bayes_optimal_attack/models/base.py
code served (permissive licence) · get_code("9db81cd4705c0a8e")
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 ArrayImpl, ndim 1, dtype family float, shape (2,) 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 jax
import jax.numpy as jnp

# Set seed for reproducibility
jax.config.update('jax_default_prng_impl', 'threefry2x32')

# Create small example data
batch_size = 2
num_classes = 4

# logits: shape (batch_size, num_classes)
logits = jnp.array([
    [2.0, 1.0, 0.5, -1.0],
    [1.5, 2.5, 0.1, 0.2]
], dtype=jnp.float32)

# labels: shape (batch_size,) with class indices
labels = jnp.array([0, 2], dtype=jnp.int32)

ARGS = {
    'logits': logits,
    'labels': labels
}
Setup block drafted by
a language model, Claude Haiku 4.5, prompt python_fixture_v1, through the batch API
Imports
jax — import names as written, not package names to install; a name the repository itself provides is not a package
Returned
type ArrayImpl, ndim 1, dtype family float, shape (2,) — shape (2,) 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
split_data Ran
ran on a synthesized input
eth-sri/bayes-framework-leakage/bayes_optimal_attack/datasets/common.py
code served (permissive licence) · get_code("454c71689e31244d")
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 tuple, ndim 3, dtype family float; 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
import numpy as np

torch.manual_seed(0)

# Create small dummy datasets
# Each sample is a tuple of (features, label)
class DummyDataset(torch.utils.data.Dataset):
    def __init__(self, num_samples=20, num_features=4):
        self.num_samples = num_samples
        self.num_features = num_features
    
    def __len__(self):
        return self.num_samples
    
    def __getitem__(self, idx):
        # Return numpy arrays as the function expects them
        features = np.random.randn(self.num_features).astype(np.float32)
        label = np.array(idx % 2, dtype=np.int64)
        return (features, label)

# Create train and test datasets
train_data = DummyDataset(num_samples=20, num_features=4)
test_data = DummyDataset(num_samples=12, num_features=4)

ARGS = {
    'train_data': train_data,
    'test_data': test_data,
    'train_batch_size': 2,
    'test_batch_size': 2,
    'k_batches': 2,
    'n_clients': 2
}
Setup block drafted by
a language model, Claude Haiku 4.5, prompt python_fixture_v1, through the batch API
Imports
numpy, torch — import names as written, not package names to install; a name the repository itself provides is not a package
Returned
type tuple, ndim 3, dtype family float — a tuple 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
cos_sim Not yet run
unverified (harvested, no recorded run)
eth-sri/bayes-framework-leakage/bayes_optimal_attack/utils/flax_losses.py
code served (permissive licence) · get_code("3f3c599d7fe199df")
How it ran

no invocation recorded.

get_distribution Not yet run
unverified (harvested, no recorded run)
eth-sri/bayes-framework-leakage/bayes_optimal_attack/datasets/distributions.py
code served (permissive licence) · get_code("1983fcb2f9da6520")
How it ran

no invocation recorded.

get_network Not yet run
unverified (harvested, no recorded run)
eth-sri/bayes-framework-leakage/bayes_optimal_attack/models/base.py
code served (permissive licence) · get_code("4458f214379338dd")
How it ran

no invocation recorded.

get_prior Not yet run
unverified (harvested, no recorded run)
eth-sri/bayes-framework-leakage/bayes_optimal_attack/datasets/distributions.py
code served (permissive licence) · get_code("4e59ac519c076777")
How it ran

no invocation recorded.

l2_dist Not yet run
unverified (harvested, no recorded run)
eth-sri/bayes-framework-leakage/bayes_optimal_attack/utils/flax_losses.py
code served (permissive licence) · get_code("edec3fc5a4c166ca")
How it ran

no invocation recorded.

l2_inner_gradient_matching_loss Not yet run
unverified (harvested, no recorded run)
eth-sri/bayes-framework-leakage/bayes_optimal_attack/utils/losses.py
code served (permissive licence) · get_code("de11a821f432c229")
How it ran

no invocation recorded.

l2_outer_gradient_matching_loss Not yet run
unverified (harvested, no recorded run)
eth-sri/bayes-framework-leakage/bayes_optimal_attack/utils/losses.py
code served (permissive licence) · get_code("64c43772c9934bda")
How it ran

no invocation recorded.

Also present in other papers' code

Of 15 samples lifted from this paper's linked repositories, 15 carry a function identity and 0 do not. Of the 15 distinct functions with an identity, 4 are also present in other papers whose code we hold (1 with at least one paper dated earlier, 0 the same month, 3 later) and 11 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
numpy_collate 5 other papers
5 later
2304.04307 (2023-04)
PriorCVAE: scalable MCMC parameter inference with Bayesian deep generative modelling
2307.01583 (2023-07)
Learning Lie Group Symmetry Transformations with Neural Networks
2406.12378 (2024-06)
Efficient mapping of phase diagrams with conditional Boltzmann Generators
and 2 more not named here
aggregate_batch_metrics 1 other paper
1 later
2206.12395 (2022-06)
Data Leakage in Federated Averaging
l2_loss 1 other paper
1 dated earlier
2110.04328 (2021-10)
Distinguishing rule-and exemplar-based generalization in learning systems
slugify 1 other paper
1 later
2604.22562 (2026-04)
Data-Free Contribution Estimation in Federated Learning using Gradient von Neumann Entropy

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

Federated learning is an established method for training machine learning models without sharing training data. However, recent work has shown that it cannot guarantee data privacy as shared gradients can still leak sensitive information. To formalize the problem of gradient leakage, we propose a theoretical framework that enables, for the first time, analysis of the Bayes optimal adversary phrased as an optimization problem. We demonstrate that existing leakage attacks can be seen as approximations of this optimal adversary with different assumptions on the probability distributions of the input data and gradients. Our experiments confirm the effectiveness of the Bayes optimal adversary when it has knowledge of the underlying distribution. Further, our experimental evaluation shows that several existing heuristic defenses are not effective against stronger attacks, especially early in the training process. Thus, our findings indicate that the construction of more effective defenses and their evaluation remains an open problem.

For agents

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

get_harvested_code_for_paper("2111.04706")
get_code_for_paper("2111.04706")
have("2111.04706")

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

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

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

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

Connect an agent — have() is free.