SYNTOLOGY HomeExplorerAtlasCodeMethodologyAboutDevelopersFeedPricing
Paper · 2401.07159 · ACL · 2024

Quantized Side Tuning: Fast and Memory-Efficient Tuning of Quantized Large Language Models

Qing Li, Yong Jiang, Zhihao Jia, Gabriele Oliaro, Xupeng Miao, Zhihao Zhang, Dan Zhao, Zhengxin Zhang

arXiv · PDF · Open in the Atlas

Code that ran

5 of 10 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; 1 failure of our instrument; 5 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/2401.07159.json · badge: /api/ran/2401.07159.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
youarespecialtome/qst marked official in Papers with Code
Papers with Code archive
5 ran · 5 no recorded run
FunctionStatusWhere it lives
Activations Ran
ran on a synthesized input
youarespecialtome/qst/modeling_llama_qst.py
code served (permissive licence) · get_code("62859370cfe52b3c")
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, 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
from torch import nn
from transformers.activations import get_activation

class Activations(nn.Module):

    def __init__(self, activation_type):
        super().__init__()
        self.f = get_activation(activation_type)

    def forward(self, x):
        return self.f(x)


INIT_ARGS = {
    'activation_type': 'relu'
}

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

if __name__ == '__main__':
    model = Activations(**INIT_ARGS)
    output = model(**ARGS)
    print(output)
Setup block drafted by
a language model, class construct-then-call prompt, model not recorded
Imports
torch, transformers — 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, 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: torch and numpy seeded to 0 by the harness immediately before the class was constructed from INIT_ARGS (fixture_check.py)
AdapterLinear Ran
ran on a synthesized input
youarespecialtome/qst/modeling_llama_qst.py
code served (permissive licence) · get_code("f66240187e4c4ad0")
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; 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
from transformers.activations import get_activation
import math

class Activations(nn.Module):

    def __init__(self, activation_type):
        super().__init__()
        self.f = get_activation(activation_type)

    def forward(self, x):
        return self.f(x)

class AdapterLinear(nn.Module):

    def __init__(self, in_features: int, out_features: int, r: int, alpha_r: int, activation=None, add_layer_norm_before_adapter=False, add_layer_norm_after_adapter=False, dropout=0.0, bias=False):
        super(AdapterLinear, self).__init__()
        self.adapter_A = nn.Linear(in_features, r, bias=bias)
        nn.init.kaiming_uniform_(self.adapter_A.weight, a=math.sqrt(5))
        self.adapter_B = nn.Linear(r, out_features, bias=bias)
        nn.init.kaiming_uniform_(self.adapter_B.weight, a=math.sqrt(5))
        if activation is not None:
            self.activation = Activations(activation.lower())
        else:
            self.activation = None
        self.add_layer_norm_before_adapter = add_layer_norm_before_adapter
        self.add_layer_norm_after_adapter = add_layer_norm_after_adapter
        if self.add_layer_norm_before_adapter:
            self.pre_layer_norm = nn.LayerNorm(in_features)
        if self.add_layer_norm_after_adapter:
            self.post_layer_norm = nn.LayerNorm(out_features)
        if dropout > 0.0:
            self.dropout_layer = nn.Dropout(p=dropout)
        else:
            self.dropout_layer = nn.Identity()
        self.scaling = r / alpha_r

    def set_bias(self, enabled=False):
        self.adapter_A.bias.requires_grad = enabled
        self.adapter_B.bias.requires_grad = enabled

    def forward(self, x):
        x = self.dropout_layer(x)
        if self.add_layer_norm_before_adapter:
            x = self.pre_layer_norm(x)
        x = self.adapter_A(x)
        if self.activation is not None:
            x = self.activation(x)
        y = self.adapter_B(x)
        if self.add_layer_norm_after_adapter:
            y = self.post_layer_norm(y)
        return y


INIT_ARGS = {
    'in_features': 4,
    'out_features': 3,
    'r': 2,
    'alpha_r': 2,
    'activation': 'relu',
    'add_layer_norm_before_adapter': False,
    'add_layer_norm_after_adapter': False,
    'dropout': 0.0,
    'bias': False,
}

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

if __name__ == '__main__':
    adapter = AdapterLinear(**INIT_ARGS)
    output = adapter(**ARGS)
    print(f"Output shape: {output.shape}")
    print(f"Output: {output}")
Setup block drafted by
a language model, class construct-then-call prompt, model not recorded
Imports
torch, transformers — 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 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)
LlamaDecoderLayer Ran
ran on a synthesized input
youarespecialtome/qst/modeling_llama_qst.py
code served (permissive licence) · get_code("6ef27137c2104cdd")
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
from transformers.models.llama.configuration_llama import LlamaConfig

# Mock classes needed for LlamaAttention
class LlamaRotaryEmbedding(nn.Module):
    def __init__(self, dim, max_position_embeddings=2048, base=10000):
        super().__init__()
        self.dim = dim
        self.max_position_embeddings = max_position_embeddings
        self.base = base

    def forward(self, x, seq_len=None):
        if seq_len is None:
            seq_len = x.shape[-2]
        inv_freq = 1.0 / (self.base ** (torch.arange(0, self.dim, 2).float() / self.dim))
        t = torch.arange(seq_len, dtype=inv_freq.dtype)
        freqs = torch.einsum("i,j->ij", t, inv_freq)
        emb = torch.cat((freqs, freqs), dim=-1)
        return emb.cos()[None, None, :, :], emb.sin()[None, None, :, :]

class LlamaLinearScalingRotaryEmbedding(LlamaRotaryEmbedding):
    def __init__(self, dim, max_position_embeddings=2048, scaling_factor=1.0, base=10000):
        super().__init__(dim, max_position_embeddings, base)
        self.scaling_factor = scaling_factor

class LlamaDynamicNTKScalingRotaryEmbedding(LlamaRotaryEmbedding):
    def __init__(self, dim, max_position_embeddings=2048, scaling_factor=1.0, base=10000):
        super().__init__(dim, max_position_embeddings, base)
        self.scaling_factor = scaling_factor

def apply_rotary_pos_emb(q, k, cos, sin, position_ids):
    cos = cos.squeeze(0).squeeze(0)  # [seq_len, dim]
    sin = sin.squeeze(0).squeeze(0)  # [seq_len, dim]
    cos = cos[position_ids].unsqueeze(1)  # [bs, 1, seq_len, dim]
    sin = sin[position_ids].unsqueeze(1)  # [bs, 1, seq_len, dim]
    q_embed = (q * cos) + (rotate_half(q) * sin)
    k_embed = (k * cos) + (rotate_half(k) * sin)
    return q_embed, k_embed

def rotate_half(x):
    x1, x2 = x[..., :x.shape[-1]//2], x[..., x.shape[-1]//2:]
    return torch.cat((-x2, x1), dim=-1)

def repeat_kv(hidden_states: torch.Tensor, n_rep: int) -> torch.Tensor:
    batch, num_key_value_heads, seq_len, head_dim = hidden_states.shape
    if n_rep == 1:
        return hidden_states
    hidden_states = hidden_states[:, :, None, :, :].expand(batch, num_key_value_heads, n_rep, seq_len, head_dim)
    return hidden_states.reshape(batch, num_key_value_heads * n_rep, seq_len, head_dim)

# Define INIT_ARGS
INIT_ARGS = {
    'config': LlamaConfig(
        hidden_size=8,
        num_attention_heads=2,
        num_key_value_heads=1,
        max_position_embeddings=32,
        rope_theta=10000.0,
        rope_scaling=None,
        pretraining_tp=1
    )
}

# Define ARGS
ARGS = {
    'hidden_states': torch.randn(2, 4, 8),  # batch_size=2, seq_len=4, hidden_size=8
    'attention_mask': None,
    'position_ids': torch.arange(4).unsqueeze(0).repeat(2, 1),  # batch_size=2, seq_len=4
    'past_key_value': None,
    'output_attentions': False,
    'use_cache': False
}
Setup block drafted by
a language model, class construct-then-call prompt, model not recorded
Imports
torch, transformers — 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)
LlamaMLP Ran
ran on a synthesized input
youarespecialtome/qst/modeling_llama_qst.py
code served (permissive licence) · get_code("393706ac28a3215a")
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 3, dtype family float, shape (2, 3, 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 as nn
from transformers.activations import ACT2FN

class Config:
    def __init__(self, hidden_size, intermediate_size, hidden_act, pretraining_tp):
        self.hidden_size = hidden_size
        self.intermediate_size = intermediate_size
        self.hidden_act = hidden_act
        self.pretraining_tp = pretraining_tp

config = Config(
    hidden_size=4,
    intermediate_size=8,
    hidden_act='silu',
    pretraining_tp=1
)

INIT_ARGS = {
    'config': config
}

ARGS = {
    'x': torch.randn(2, 3, 4)
}
Setup block drafted by
a language model, class construct-then-call prompt, model not recorded
Imports
torch, transformers — import names as written, not package names to install; a name the repository itself provides is not a package
Returned
type Tensor, ndim 3, dtype family float, shape (2, 3, 4) — shape (2, 3, 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: torch and numpy seeded to 0 by the harness immediately before the class was constructed from INIT_ARGS (fixture_check.py)
apply_rotary_pos_emb Ran
ran; the contract check could not run (RAISES, DEP_MISSING or TIMEOUT)
youarespecialtome/qst/modeling_llama_qst.py
code served (permissive licence) · get_code("3c9f7e87051e9272")
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 tuple, ndim 5, 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

torch.manual_seed(0)

# Construct tiny tensors for q and k
# batch_size=2, seq_len=3, hidden_dim=4
batch_size = 2
seq_len = 3
hidden_dim = 4

q = torch.randn(batch_size, seq_len, hidden_dim)
k = torch.randn(batch_size, seq_len, hidden_dim)

# cos and sin tensors need shape that allows:
# cos.squeeze(1).squeeze(0) to work, then indexing by position_ids
# After squeeze(1).squeeze(0), shape should be (seq_len, hidden_dim) or similar
# Before squeezes, shape is (1, 1, seq_len, hidden_dim)
cos = torch.randn(1, 1, seq_len, hidden_dim)
sin = torch.randn(1, 1, seq_len, hidden_dim)

# position_ids should index into the seq_len dimension
# Shape: (batch_size, seq_len)
position_ids = torch.tensor([[0, 1, 2], [0, 1, 2]], dtype=torch.long)

ARGS = {
    "q": q,
    "k": k,
    "cos": cos,
    "sin": sin,
    "position_ids": position_ids,
}
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 tuple, ndim 5, 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
LlamaAttention Not yet run
unverified (harvested, no recorded run)
youarespecialtome/qst/modeling_llama_qst.py
code served (permissive licence) · get_code("49bff92fc40bac47")
How it ran

no invocation recorded.

LlamaModel Not yet run
unverified (harvested, no recorded run)
youarespecialtome/qst/modeling_llama_qst.py
code served (permissive licence) · get_code("e4df1ae4f39faa71")
How it ran

no invocation recorded.

QSTBaseModelOutputWithPast Not yet run
unverified (harvested, no recorded run)
youarespecialtome/qst/modeling_llama_qst.py
code served (permissive licence) · get_code("c394ff56984f4c10")
How it ran

no invocation recorded.

QSTConfig Not yet run
unverified (harvested, no recorded run)
youarespecialtome/qst/modeling_llama_qst.py
code served (permissive licence) · get_code("fb6c4a667149f2a3")
How it ran

no invocation recorded.

QSTLlamaModel Not yet run
unverified (harvested, no recorded run)
youarespecialtome/qst/modeling_llama_qst.py
code served (permissive licence) · get_code("4410d9c227d25d07")
How it ran

no invocation recorded.

Also present in other papers' code

Of 10 samples lifted from this paper's linked repositories, 10 carry a function identity and 0 do not. Of the 10 distinct functions with an identity, 1 are also present in other papers whose code we hold (1 with at least one paper dated earlier, 0 the same month, 0 later) and 9 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
Activations
brick of this paper's assembly: helper
2 other papers
2 dated earlier · 1 only as an assembly brick
2012.15723 (2020-12)
Making Pre-trained Language Models Better Few-shot Learners
2205.11961 (2022-05)
ATTEMPT: Parameter-Efficient Multi-task Tuning via Attentional Mixtures of Soft Prompts

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

Finetuning large language models (LLMs) has been empirically effective on a variety of downstream tasks. Existing approaches to finetuning an LLM either focus on parameter-efficient finetuning, which only updates a small number of trainable parameters, or attempt to reduce the memory footprint during the training phase of the finetuning. Typically, the memory footprint during finetuning stems from three contributors: model weights, optimizer states, and intermediate activations. However, existing works still require considerable memory, and none can simultaneously mitigate the memory footprint of all three sources. In this paper, we present quantized side tuing (QST), which enables memory-efficient and fast finetuning of LLMs by operating through a dual-stage process. First, QST quantizes an LLM's model weights into 4-bit to reduce the memory footprint of the LLM's original weights. Second, QST introduces a side network separated from the LLM, which utilizes the hidden states of the LLM to make task-specific predictions. Using a separate side network avoids performing backpropagation through the LLM, thus reducing the memory requirement of the intermediate activations. Finally, QST leverages several lowrank adaptors and gradient-free downsample modules to significantly reduce the trainable parameters, so as to save the memory footprint of the optimizer states. Experiments show that QST can reduce the total memory footprint by up to 2.3× and speed up the finetuning process by up to 3× while achieving competent performance compared with the state-of-theart. When it comes to full finetuning, QST can reduce the total memory footprint up to 7×.

For agents

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

get_harvested_code_for_paper("2401.07159")
get_code_for_paper("2401.07159")
have("2401.07159")

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

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

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

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

Connect an agent — have() is free.