SYNTOLOGY HomeExplorerAtlasCodeMethodologyAboutDevelopersFeedPricing
Paper · 2307.08122 · ICLR · 2024

Tangent Transformers for Composition, Privacy and Removal

Stefano Soatto, Yu Tian, Liu, Aditya Golatkar

arXiv · PDF · Open in the Atlas

Code that ran

4 of 6 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, 0 violated it and 4 have no contract verdict; 0 failures of our instrument; 2 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/2307.08122.json · badge: /api/ran/2307.08122.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
tianyu139/tangent-model-composition canonical (classifier label)
classifier basis: classifier_2025
4 ran · 2 no recorded run
FunctionStatusWhere it lives
LinearAttention Ran
ran on a synthesized input
tianyu139/tangent-model-composition/models/linear_attention_layers.py
code served (permissive licence) · get_code("7e5129a3c76b00c8")
How it ran

Ran in Syntology's sandbox on this synthesized input (drafted by a language model, class construct-then-call prompt, model not recorded) and returned tuple. 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
import torch.nn.functional as F
from torch.nn import Parameter

NOISE_SCALE = 1e-12

class LinearLinear(nn.Linear):

    def __init__(self, in_features: int, out_features: int, bias: bool=True) -> None:
        super().__init__(in_features, out_features, bias)
        self.linear_weight = Parameter(torch.zeros_like(self.weight, requires_grad=True) + NOISE_SCALE)
        if bias:
            self.linear_bias = Parameter(torch.zeros_like(self.bias, requires_grad=True) + NOISE_SCALE)
        else:
            self.linear_bias = None

    def forward(self, input, input_jvp):
        output = super().forward(input)
        output_jvp = F.linear(input, self.linear_weight, self.linear_bias) + F.linear(input_jvp, self.weight, None)
        return (output, output_jvp)

class LinearAttention(nn.Module):

    def __init__(self, dim, num_heads=8, qkv_bias=False, qk_norm=False, attn_drop=0.0, proj_drop=0.0, norm_layer=nn.LayerNorm):
        super().__init__()
        assert dim % num_heads == 0, 'dim should be divisible by num_heads'
        assert qk_norm is False
        self.qk_norm = qk_norm
        self.num_heads = num_heads
        self.head_dim = dim // num_heads
        self.scale = self.head_dim ** (-0.5)
        self.qkv = LinearLinear(dim, dim * 3, bias=qkv_bias)
        self.q_norm = norm_layer(self.head_dim) if qk_norm else nn.Identity()
        self.k_norm = norm_layer(self.head_dim) if qk_norm else nn.Identity()
        self.attn_drop = nn.Dropout(attn_drop)
        self.proj = LinearLinear(dim, dim)
        self.proj_drop = nn.Dropout(proj_drop)

    def forward(self, input, input_jvp=None):
        B, N, C = input.shape
        x = input
        x_jvp = input_jvp
        qkv, qkv_jvp = self.qkv(x, x_jvp)
        qkv = qkv.reshape(B, N, 3, self.num_heads, self.head_dim).permute(2, 0, 3, 1, 4)
        qkv_jvp = qkv_jvp.reshape(B, N, 3, self.num_heads, self.head_dim).permute(2, 0, 3, 1, 4)
        q, k, v = qkv.unbind(0)
        q_jvp, k_jvp, v_jvp = qkv_jvp.unbind(0)
        if self.qk_norm:
            q, q_jvp = self.q_norm(q, q_jvp)
            k, k_jvp = self.k_norm(k, k_jvp)
        q = q * self.scale
        attn = q @ k.transpose(-2, -1)
        attn = attn.softmax(dim=-1)
        attn = self.attn_drop(attn)
        x = attn @ v
        x = x.transpose(1, 2).reshape(B, N, C)
        q_jvp = q_jvp * self.scale
        A_jvp = q_jvp @ k.transpose(-2, -1)
        B_jvp = q @ k_jvp.transpose(-2, -1)
        C_jvp = attn @ v_jvp
        dm_by_dr = A_jvp + B_jvp
        assert dm_by_dr.shape == attn.shape
        attn_filter_1 = dm_by_dr * attn
        attn_filter_2 = torch.diagonal(dm_by_dr @ attn.transpose(-2, -1), dim1=-2, dim2=-1).unsqueeze(dim=-1) * attn
        attn_filter = attn_filter_1 - attn_filter_2
        x_jvp = attn_filter @ v + C_jvp
        x_jvp = x_jvp.transpose(1, 2).reshape(B, N, C)
        x, x_jvp = self.proj(x, x_jvp)
        x = self.proj_drop(x)
        x_jvp = self.proj_drop(x_jvp)
        return (x, x_jvp)

INIT_ARGS = {
    'dim': 4,
    'num_heads': 2,
    'qkv_bias': False,
    'qk_norm': False,
    'attn_drop': 0.0,
    'proj_drop': 0.0,
    'norm_layer': nn.LayerNorm,
}

ARGS = {
    'input': torch.randn(2, 3, 4),
    'input_jvp': torch.randn(2, 3, 4),
}

if __name__ == '__main__':
    model = LinearAttention(**INIT_ARGS)
    output = model(**ARGS)
    print("Output shapes:", output[0].shape, output[1].shape)
    print("Success!")
Setup block drafted by
a language model, class construct-then-call prompt, model not recorded
Imports
timm, torch — import names as written, not package names to install; a name the repository itself provides is not a package
Returned
type tuple — a tuple output has no array shape of its own; none is 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: torch and numpy seeded to 0 by the harness immediately before the class was constructed from INIT_ARGS (fixture_check.py)
LinearGELU Ran
ran on a synthesized input
tianyu139/tangent-model-composition/models/linear_attention_layers.py
code served (permissive licence) · get_code("5732c505c946465f")
How it ran

Ran in Syntology's sandbox on this synthesized input (drafted by a language model, class construct-then-call prompt, model not recorded) 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 torch.nn as nn

EPS = 1e-08

class LinearGELU(nn.GELU):

    def __init__(self):
        super().__init__()

    def forward(self, input, input_jvp):
        output = super().forward(input)
        gauss = torch.distributions.normal.Normal(0, 1)
        output_jvp = input_jvp * (output / (input + EPS) + input * torch.exp(gauss.log_prob(input)))
        return (output, output_jvp)


INIT_ARGS = {}

ARGS = {
    'input': torch.randn(2, 4),
    'input_jvp': torch.randn(2, 4),
}

if __name__ == '__main__':
    model = LinearGELU(**INIT_ARGS)
    output, output_jvp = model(**ARGS)
    print("Output shape:", output.shape)
    print("Output JVP shape:", output_jvp.shape)
    print("Test passed!")
Setup block drafted by
a language model, class construct-then-call prompt, model not recorded
Imports
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: torch and numpy seeded to 0 by the harness immediately before the class was constructed from INIT_ARGS (fixture_check.py)
LinearLayerNorm Ran
ran on a synthesized input
tianyu139/tangent-model-composition/models/linear_attention_layers.py
code served (permissive licence) · get_code("3bfdde9f5c3478b6")
How it ran

Ran in Syntology's sandbox on this synthesized input (drafted by a language model, class construct-then-call prompt, model not recorded) and returned tuple. 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

# INIT_ARGS for LinearLayerNorm.__init__
INIT_ARGS = {
    'normalized_shape': 8,  # Single dimension for layer norm
    'eps': 1e-05,
    'elementwise_affine': True,
    'device': None,
    'dtype': None
}

# ARGS for LinearLayerNorm.forward
# The forward method takes (input, input_jvp)
# input should have shape where last dimension matches normalized_shape
ARGS = {
    'input': torch.randn(2, 8),  # batch_size=2, feature_dim=8
    'input_jvp': torch.randn(2, 8)  # same shape as input for JVP computation
}
Setup block drafted by
a language model, class construct-then-call prompt, model not recorded
Imports
torch — import names as written, not package names to install; a name the repository itself provides is not a package
Returned
type tuple — a tuple output has no array shape of its own; none is 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: torch and numpy seeded to 0 by the harness immediately before the class was constructed from INIT_ARGS (fixture_check.py)
LinearLinear Ran
ran on a synthesized input
tianyu139/tangent-model-composition/models/linear_attention_layers.py
code served (permissive licence) · get_code("a57901e2f325ccc3")
How it ran

Ran in Syntology's sandbox on this synthesized input (drafted by a language model, class construct-then-call prompt, model not recorded) and returned tuple. 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
import torch.nn.functional as F
from torch.nn import Parameter
from torch import Tensor

NOISE_SCALE = 1e-12

class LinearLinear(nn.Linear):

    def __init__(self, in_features: int, out_features: int, bias: bool=True) -> None:
        super().__init__(in_features, out_features, bias)
        self.linear_weight = Parameter(torch.zeros_like(self.weight, requires_grad=True) + NOISE_SCALE)
        if bias:
            self.linear_bias = Parameter(torch.zeros_like(self.bias, requires_grad=True) + NOISE_SCALE)
        else:
            self.linear_bias = None

    def forward(self, input: Tensor, input_jvp: Tensor) -> Tensor:
        output = super().forward(input)
        output_jvp = F.linear(input, self.linear_weight, self.linear_bias) + F.linear(input_jvp, self.weight, None)
        return (output, output_jvp)


INIT_ARGS = {
    'in_features': 4,
    'out_features': 3,
    'bias': True
}

ARGS = {
    'input': torch.randn(2, 4),
    'input_jvp': torch.randn(2, 4)
}

if __name__ == '__main__':
    model = LinearLinear(**INIT_ARGS)
    output, output_jvp = model(**ARGS)
    print("Output shape:", output.shape)
    print("Output JVP shape:", output_jvp.shape)
    print("Test passed!")
Setup block drafted by
a language model, class construct-then-call prompt, model not recorded
Imports
torch — import names as written, not package names to install; a name the repository itself provides is not a package
Returned
type tuple — a tuple output has no array shape of its own; none is 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: torch and numpy seeded to 0 by the harness immediately before the class was constructed from INIT_ARGS (fixture_check.py)
LinearBlock Not yet run
unverified (harvested, no recorded run)
tianyu139/tangent-model-composition/models/linear_attention_layers.py
code served (permissive licence) · get_code("74db42c33268e884")
How it ran

no invocation recorded.

LinearMlp Not yet run
unverified (harvested, no recorded run)
tianyu139/tangent-model-composition/models/linear_attention_layers.py
code served (permissive licence) · get_code("0d0711f36c096c68")
How it ran

no invocation recorded.

Also present in other papers' code

Of 6 samples lifted from this paper's linked repositories, 6 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

We introduce Tangent Attention Fine-Tuning (TAFT), a method for fine-tuning linearized transformers obtained by computing a First-order Taylor Expansion around a pre-trained initialization. We show that the Jacobian-Vector Product resulting from linearization can be computed efficiently in a single forward pass, reducing training and inference cost to the same order of magnitude as its original non-linear counterpart, while using the same number of parameters. Furthermore, we show that, when applied to various downstream visual classification tasks, the resulting Tangent Transformer fine-tuned with TAFT can perform comparably with fine-tuning the original non-linear network. Since Tangent Transformers are linear with respect to the new set of weights, and the resulting fine-tuning loss is convex, we show that TAFT enjoys several advantages compared to non-linear finetuning when it comes to model composition, parallel training, machine unlearning, and differential privacy. Our code is available at: https://github.com/ tianyu139/tangent-model-composition * Denotes equal contribution 1

For agents

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

get_harvested_code_for_paper("2307.08122")
get_code_for_paper("2307.08122")
have("2307.08122")

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

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

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

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

Connect an agent — have() is free.