SYNTOLOGY HomeExplorerAtlasCodeMethodologyAboutDevelopersFeedPricing
Paper · 2106.10199 · 2021

BitFit: Simple Parameter-efficient Fine-tuning for Transformer-based Masked Language-models

Yoav Goldberg, Shauli Ravfogel, Elad Ben-Zaken

arXiv · PDF · Open in the Atlas

Code that ran

4 of 13 samples (functions and classes) lifted from this paper's linked repositories executed on a synthesized input in Syntology's jail (1 of them constructed an object rather than computing a result; 0 honoured the contract we drafted, 0 violated it and 3 have no contract verdict; 1 failure of our instrument; 9 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/2106.10199.json · badge: /api/ran/2106.10199.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
mkshing/DiffFit-pytorch community
Papers with Code archive
2 ran · 9 no recorded run
piero2c/BitInfer community
Papers with Code archive
1 ran · 0 no recorded run
Aradhye2002/selective-peft-toolkit community
Papers with Code archive
1 ran · 0 no recorded run
FunctionStatusWhere it lives
BitAdditiveBias Ran
ran on a synthesized input · constructed an object; no result was computed
piero2c/BitInfer/bitinfer/wrappers/bert_modeling.py
code served (permissive licence) · get_code("fd7783a0f859595f")
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 an instance of its own class, BitAdditiveBias: the run constructed the object and did not call it, so no result was computed. 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

torch.manual_seed(0)

# Create a simple module that acts like BertEmbeddings, Linear, or LayerNorm
class SimpleModule(nn.Module):
    def __init__(self):
        super().__init__()
        self.linear = nn.Linear(4, 5)
    
    def forward(self, x):
        return self.linear(x)

# Create the module and set it to eval mode (since forward asserts not self.module.training)
module = SimpleModule()
module.eval()

# Create a parameter name to track
param_name = "weight"

# Create expand_seq_axis flag
expand_seq_axis = False

ARGS = {
    "module": module,
    "param_name": param_name,
    "expand_seq_axis": expand_seq_axis,
}
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 BitAdditiveBias — the run constructed an instance of its own class and did not call it; no shape is stated — the instrument coerces any output to an array; for a BitAdditiveBias 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
LoRALinearLayer Ran
ran on a synthesized input
mkshing/DiffFit-pytorch/difffit_pytorch/diffusers_models/attention_processor.py
code served (permissive licence) · get_code("fc4cbb21fd52d41e")
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 Tensor, ndim 2, dtype family float, shape (2, 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
from torch import nn

class LoRALinearLayer(nn.Module):

    def __init__(self, in_features, out_features, rank=4):
        super().__init__()
        if rank > min(in_features, out_features):
            raise ValueError(f'LoRA rank {rank} must be less or equal than {min(in_features, out_features)}')
        self.down = nn.Linear(in_features, rank, bias=False)
        self.up = nn.Linear(rank, out_features, bias=False)
        nn.init.normal_(self.down.weight, std=1 / rank)
        nn.init.zeros_(self.up.weight)

    def forward(self, hidden_states):
        orig_dtype = hidden_states.dtype
        dtype = self.down.weight.dtype
        down_hidden_states = self.down(hidden_states.to(dtype))
        up_hidden_states = self.up(down_hidden_states)
        return up_hidden_states.to(orig_dtype)


INIT_ARGS = {
    'in_features': 8,
    'out_features': 6,
    'rank': 3,
}

ARGS = {
    'hidden_states': torch.randn(2, 8),
}
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 Tensor, ndim 2, dtype family float, shape (2, 6) — shape (2, 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: torch and numpy seeded to 0 by the harness immediately before the class was constructed from INIT_ARGS (fixture_check.py)
SlicedAttnAddedKVProcessor Ran
ran on a synthesized input
mkshing/DiffFit-pytorch/difffit_pytorch/diffusers_models/attention_processor.py
code served (permissive licence) · get_code("99828ec14262bca0")
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 Tensor, ndim 4, 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

# Mock Attention class to support the SlicedAttnAddedKVProcessor
class MockAttention(nn.Module):
    def __init__(self, dim, num_heads, only_cross_attention=False, norm_cross=False):
        super().__init__()
        self.dim = dim
        self.heads = num_heads
        self.only_cross_attention = only_cross_attention
        self.norm_cross = norm_cross
        
        self.to_q = nn.Linear(dim, dim)
        self.to_k = nn.Linear(dim, dim)
        self.to_v = nn.Linear(dim, dim)
        self.add_k_proj = nn.Linear(dim, dim)
        self.add_v_proj = nn.Linear(dim, dim)
        self.group_norm = nn.GroupNorm(num_channels=dim, num_groups=1)
        self.to_out = nn.Sequential(
            nn.Linear(dim, dim),
            nn.Identity()
        )
        
        if norm_cross:
            self.norm_encoder_hidden_states = nn.LayerNorm(dim)
    
    def prepare_attention_mask(self, attention_mask, sequence_length, batch_size):
        if attention_mask is None:
            return None
        return attention_mask
    
    def head_to_batch_dim(self, tensor):
        batch_size, seq_len, dim = tensor.shape
        return tensor.reshape(batch_size * self.heads, seq_len, dim // self.heads)
    
    def batch_to_head_dim(self, tensor):
        batch_size_times_heads, seq_len, dim_per_head = tensor.shape
        batch_size = batch_size_times_heads // self.heads
        return tensor.reshape(batch_size, seq_len, dim_per_head * self.heads)
    
    def get_attention_scores(self, query, key, attention_mask):
        scores = torch.bmm(query, key.transpose(1, 2))
        scores = scores / (query.shape[-1] ** 0.5)
        if attention_mask is not None:
            scores = scores + attention_mask
        return torch.softmax(scores, dim=-1)


class SlicedAttnAddedKVProcessor:

    def __init__(self, slice_size):
        self.slice_size = slice_size

    def __call__(self, attn: 'Attention', hidden_states, encoder_hidden_states=None, attention_mask=None):
        residual = hidden_states
        hidden_states = hidden_states.view(hidden_states.shape[0], hidden_states.shape[1], -1).transpose(1, 2)
        batch_size, sequence_length, _ = hidden_states.shape
        attention_mask = attn.prepare_attention_mask(attention_mask, sequence_length, batch_size)
        if encoder_hidden_states is None:
            encoder_hidden_states = hidden_states
        elif attn.norm_cross:
            encoder_hidden_states = attn.norm_encoder_hidden_states(encoder_hidden_states)
        hidden_states = attn.group_norm(hidden_states.transpose(1, 2)).transpose(1, 2)
        query = attn.to_q(hidden_states)
        dim = query.shape[-1]
        query = attn.head_to_batch_dim(query)
        encoder_hidden_states_key_proj = attn.add_k_proj(encoder_hidden_states)
        encoder_hidden_states_value_proj = attn.add_v_proj(encoder_hidden_states)
        encoder_hidden_states_key_proj = attn.head_to_batch_dim(encoder_hidden_states_key_proj)
        encoder_hidden_states_value_proj = attn.head_to_batch_dim(encoder_hidden_states_value_proj)
        if not attn.only_cross_attention:
            key = attn.to_k(hidden_states)
            value = attn.to_v(hidden_states)
            key = attn.head_to_batch_dim(key)
            value = attn.head_to_batch_dim(value)
            key = torch.cat([encoder_hidden_states_key_proj, key], dim=1)
            value = torch.cat([encoder_hidden_states_value_proj, value], dim=1)
        else:
            key = encoder_hidden_states_key_proj
            value = encoder_hidden_states_value_proj
        batch_size_attention, query_tokens, _ = query.shape
        hidden_states = torch.zeros((batch_size_attention, query_tokens, dim // attn.heads), device=query.device, dtype=query.dtype)
        for i in range(batch_size_attention // self.slice_size):
            start_idx = i * self.slice_size
            end_idx = (i + 1) * self.slice_size
            query_slice = query[start_idx:end_idx]
            key_slice = key[start_idx:end_idx]
            attn_mask_slice = attention_mask[start_idx:end_idx] if attention_mask is not None else None
            attn_slice = attn.get_attention_scores(query_slice, key_slice, attn_mask_slice)
            attn_slice = torch.bmm(attn_slice, value[start_idx:end_idx])
            hidden_states[start_idx:end_idx] = attn_slice
        hidden_states = attn.batch_to_head_dim(hidden_states)
        hidden_states = attn.to_out[0](hidden_states)
        hidden_states = attn.to_out[1](hidden_states)
        hidden_states = hidden_states.transpose(-1, -2).reshape(residual.shape)
        hidden_states = hidden_states + residual
        return hidden_states


INIT_ARGS = {
    'slice_size': 2
}

ARGS = {
    'attn': MockAttention(dim=8, num_heads=2, only_cross_attention=False, norm_cross=False),
    'hidden_states': torch.randn(2, 8, 3, 4),
    'encoder_hidden_states': None,
    'attention_mask': None
}

METHOD = '__call__'
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 Tensor, ndim 4, dtype family float — no output shape is stated: observe_signature.py observed this class with its constructor sizes canonicalised where it could, which the node does not record, so its shape is not stated as this setup block's
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)
get_bitfit Ran
ran; our contract draft was wrong, not the code
Aradhye2002/selective-peft-toolkit/selective_optimizers/optimizers/bitfit.py
code served (permissive licence) · get_code("3e842c5dc40c0417")
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 type. 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 torch.optim import SGD

torch.manual_seed(0)

# Create a simple model with bias parameters
class SimpleModel(nn.Module):
    def __init__(self):
        super().__init__()
        self.linear1 = nn.Linear(4, 3)
        self.linear2 = nn.Linear(3, 2)
    
    def forward(self, x):
        x = self.linear1(x)
        x = self.linear2(x)
        return x

model = SimpleModel()

# Create optimizer instance to pass as base_optimizer
base_optimizer = SGD

ARGS = {
    'base_optimizer': base_optimizer
}
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 type — a type output has no array shape of its own; none is stated — the instrument coerces any output to an array; for a type 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
AttnAddedKVProcessor Not yet run
unverified (harvested, no recorded run)
mkshing/DiffFit-pytorch/difffit_pytorch/diffusers_models/attention_processor.py
code served (permissive licence) · get_code("5936bf677f1ca5e6")
How it ran

no invocation recorded.

AttnProcessor Not yet run
unverified (harvested, no recorded run)
mkshing/DiffFit-pytorch/difffit_pytorch/diffusers_models/attention_processor.py
code served (permissive licence) · get_code("2772c67fd48b070d")
How it ran

no invocation recorded.

AttnProcessor2_0 Not yet run
unverified (harvested, no recorded run)
mkshing/DiffFit-pytorch/difffit_pytorch/diffusers_models/attention_processor.py
code served (permissive licence) · get_code("22a4995cd018342d")
How it ran

no invocation recorded.

DiffFitAttnProcessor Not yet run
unverified (harvested, no recorded run)
mkshing/DiffFit-pytorch/difffit_pytorch/diffusers_models/attention_processor.py
code served (permissive licence) · get_code("9dc8c249e25cc758")
How it ran

no invocation recorded.

DiffFitXFormersAttnProcessor Not yet run
unverified (harvested, no recorded run)
mkshing/DiffFit-pytorch/difffit_pytorch/diffusers_models/attention_processor.py
code served (permissive licence) · get_code("f986040d6b978c1a")
How it ran

no invocation recorded.

LoRAAttnProcessor Not yet run
unverified (harvested, no recorded run)
mkshing/DiffFit-pytorch/difffit_pytorch/diffusers_models/attention_processor.py
code served (permissive licence) · get_code("b684827fec968595")
How it ran

no invocation recorded.

LoRAXFormersAttnProcessor Not yet run
unverified (harvested, no recorded run)
mkshing/DiffFit-pytorch/difffit_pytorch/diffusers_models/attention_processor.py
code served (permissive licence) · get_code("7886240878f393a4")
How it ran

no invocation recorded.

SlicedAttnProcessor Not yet run
unverified (harvested, no recorded run)
mkshing/DiffFit-pytorch/difffit_pytorch/diffusers_models/attention_processor.py
code served (permissive licence) · get_code("63bf91f1802952a1")
How it ran

no invocation recorded.

XFormersAttnProcessor Not yet run
unverified (harvested, no recorded run)
mkshing/DiffFit-pytorch/difffit_pytorch/diffusers_models/attention_processor.py
code served (permissive licence) · get_code("921edfd779ddeac7")
How it ran

no invocation recorded.

Also present in other papers' code

Of 13 samples lifted from this paper's linked repositories, 13 carry a function identity and 0 do not. Of the 13 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 13 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-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

We introduce BitFit, a sparse-finetuning method where only the bias-terms of the model (or a subset of them) are being modified. We show that with small-to-medium training data, applying BitFit on pre-trained BERT models is competitive with (and sometimes better than) fine-tuning the entire model. For larger data, the method is competitive with other sparse fine-tuning methods. Besides their practical utility, these findings are relevant for the question of understanding the commonly-used process of finetuning: they support the hypothesis that finetuning is mainly about exposing knowledge induced by language-modeling training, rather than learning new task-specific linguistic knowledge.

For agents

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

get_harvested_code_for_paper("2106.10199")
get_code_for_paper("2106.10199")
have("2106.10199")

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

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

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

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

Connect an agent — have() is free.