SYNTOLOGY HomeExplorerAtlasCodeMethodologyAboutDevelopersFeedPricing
Paper · 2407.20584 · 2024

Pruning Large Language Models with Semi-Structural Adaptive Sparse Training

arXiv · PDF · Open in the Atlas

Code that ran

6 of 8 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 0 have no contract verdict; 6 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/2407.20584.json · badge: /api/ran/2407.20584.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
thu-ml/adaptive-sparse-trainer canonical (classifier label)
classifier basis: census
6 ran · 2 no recorded run
FunctionStatusWhere it lives
get_linear_list Ran
ran; our contract draft was wrong, not the code
thu-ml/adaptive-sparse-trainer/LLaMA-2-7B/llmshearing/sparse/sparse_utils.py
code served (permissive licence) · get_code("35c39367fa876cb1")
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 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

torch.manual_seed(0)

# Build a minimal model that has some Linear layers
# The function iterates through named_modules() and checks:
# 1. isinstance(module, nn.Linear)
# 2. not name.endswith('output')

class SimpleModel(nn.Module):
    def __init__(self):
        super().__init__()
        self.hidden1 = nn.Linear(4, 3)
        self.hidden2 = nn.Linear(3, 2)
        self.output = nn.Linear(2, 1)  # This should be excluded
        self.classifier = nn.Linear(2, 5)  # This should be included
    
    def forward(self, x):
        return x

model = SimpleModel()

ARGS = {
    'model': model
}
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 float — 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
get_nested_attr Ran
ran; our contract draft was wrong, not the code
thu-ml/adaptive-sparse-trainer/LLaMA-2-7B/llmshearing/sparse/sparse_utils.py
code served (permissive licence) · get_code("e30216d468c41586")
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 Linear. 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)

class NestedModule(nn.Module):
    def __init__(self):
        super().__init__()
        self.layer1 = nn.Linear(4, 3)
        self.layer2 = nn.Linear(3, 2)

class DeepNestedModule(nn.Module):
    def __init__(self):
        super().__init__()
        self.nested = NestedModule()

obj = DeepNestedModule()
attr_path = "nested.layer1"

ARGS = {
    "obj": obj,
    "attr_path": attr_path
}
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 Linear — a Linear output has no array shape of its own; none is stated — the instrument coerces any output to an array; for a Linear 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
get_raw_model Ran
ran; our contract draft was wrong, not the code
thu-ml/adaptive-sparse-trainer/utils.py
code served (permissive licence) · get_code("dbbaeceaff4ae2ef")
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 SimpleModel. 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)

class SimpleModel(nn.Module):
    def __init__(self):
        super().__init__()
        self.linear = nn.Linear(4, 3)
    
    def forward(self, x):
        return self.linear(x)

class StudentModel(nn.Module):
    def __init__(self):
        super().__init__()
        self.student = SimpleModel()
    
    def forward(self, x):
        return self.student(x)

class WrappedModel(nn.Module):
    def __init__(self, inner_model):
        super().__init__()
        self.module = inner_model
    
    def forward(self, x):
        return self.module(x)

# Test case 1: Direct model (no wrapper, no student)
model1 = SimpleModel()

# Test case 2: Model with student attribute (no wrapper)
model2 = StudentModel()

# Test case 3: Model wrapped with module attribute containing student
model3 = WrappedModel(StudentModel())

ARGS = {
    "model": model1
}
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 SimpleModel — a SimpleModel output has no array shape of its own; none is stated — the instrument coerces any output to an array; for a SimpleModel 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
normal_attn_fn Ran
ran; the contract check could not run (RAISES, DEP_MISSING or TIMEOUT)
thu-ml/adaptive-sparse-trainer/LLaMA-2-7B/llmshearing/models/composer_llama.py
code served (permissive licence) · get_code("be527ff62ff13c04")
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 3, dtype family float, shape (2, 4, 18) 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 math

torch.manual_seed(0)

# Set up dimensions
bsz = 2           # batch size
n_heads = 3       # number of heads
q_len = 4         # query length
kv_len = 5        # key/value length
head_dim = 6      # head dimension

# Create query, key, value tensors
# query shape: (bsz, n_heads, q_len, head_dim)
query = torch.randn(bsz, n_heads, q_len, head_dim)

# key shape: (bsz, n_heads, kv_len, head_dim)
key = torch.randn(bsz, n_heads, kv_len, head_dim)

# value shape: (bsz, n_heads, kv_len, head_dim)
value = torch.randn(bsz, n_heads, kv_len, head_dim)

# Create attention mask
# Shape should be broadcastable to (bsz, n_heads, q_len, kv_len)
attention_mask = torch.zeros(bsz, n_heads, q_len, kv_len)

# Create head_z scaling factors
# Shape: (bsz, n_heads, q_len) based on how it's used in the function
head_z = torch.ones(bsz, n_heads, q_len)

ARGS = {
    "query": query,
    "key": key,
    "value": value,
    "attention_mask": attention_mask,
    "head_z": head_z,
}
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 3, dtype family float, shape (2, 4, 18) — shape (2, 4, 18) 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
turn_head_z Ran
ran; our contract draft was wrong, not the code
thu-ml/adaptive-sparse-trainer/LLaMA-2-7B/llmshearing/models/composer_llama.py
code served (permissive licence) · get_code("d3bdf5250c6d2cd9")
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)

# Construct arguments for turn_head_z function
# The function expects:
# - head_z: a tensor that will be squeezed and cloned
# - head_layer_z: optional tensor to multiply with head_z, or None

# Create head_z as a tensor with some dimensions
# Using shape (1, 4) so squeeze() reduces it to (4,)
head_z = torch.tensor([[1.0, 0.0, 2.0, 0.0]])

# Create head_layer_z as an optional tensor
# Using shape (4,) to match the squeezed head_z for element-wise multiplication
head_layer_z = torch.tensor([1.0, 1.0, 1.0, 1.0])

ARGS = {
    "head_z": head_z,
    "head_layer_z": head_layer_z,
}
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
turn_mlp_z Ran
ran; our contract draft was wrong, not the code
thu-ml/adaptive-sparse-trainer/LLaMA-2-7B/llmshearing/models/composer_llama.py
code served (permissive licence) · get_code("86e85f31c3cef174")
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)

# intermediate_z: a tensor that will be squeezed and cloned
# The function calls .squeeze(), .clone(), and checks for != 0
# We'll create a small tensor with some zero and non-zero values
intermediate_z = torch.tensor([[1.0, 0.0, 2.0, 0.0]])  # shape (1, 4) -> (4,) after squeeze

# mlp_z: either None or a tensor that can be multiplied element-wise with intermediate_z
# Since it's used in multiplication with intermediate_z, it should be broadcastable
mlp_z = torch.tensor([1.0, 0.5, 1.0, 0.0])  # shape (4,) to match squeezed intermediate_z

ARGS = {
    "intermediate_z": intermediate_z,
    "mlp_z": mlp_z,
}
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
eval_ppl Not yet run
unverified (harvested, no recorded run)
thu-ml/adaptive-sparse-trainer/LLaMA-2-7B/llmshearing/sparse/sparse_utils.py
code served (permissive licence) · get_code("96c9abdf6be0e778")
How it ran

no invocation recorded.

eval_ppl Not yet run
unverified (harvested, no recorded run)
thu-ml/adaptive-sparse-trainer/utils.py
code served (permissive licence) · get_code("95170b214d3dd627")
How it ran

no invocation recorded.

Also present in other papers' code

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

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

The remarkable success of Large Language Models (LLMs) relies heavily on their substantial scale, which poses significant challenges during model deployment in terms of latency and memory consumption. Recently, numerous studies have attempted to compress LLMs using one-shot pruning methods. However, these methods often suffer from considerable performance degradation on complex language understanding tasks, raising concerns about the feasibility of pruning in LLMs. To address this issue, we propose Adaptive Sparse Trainer (AST), a novel and efficient retraining framework tailored for semi-structured sparse models. AST enables models to learn optimal masks during the weight update process without incurring additional computational overhead. Furthermore, we demonstrate that incorporating knowledge distillation significantly improves retraining efficiency and enhances model performance under fixed computational constraints. Additionally, a supplementary set of well-initialized parameters is integrated to further augment the model's efficacy. AST achieves state-of-the-art performance with minimal training cost. When applied to the LLaMA2-7B model, AST reduces the perplexity and zero-shot accuracy gap between dense and 2:4 semi-structured sparse models to 0.6 and 1.16%, respectively, utilizing less than 0.4% of the pretraining tokens and GPU hours. Our work demonstrates the feasibility of deploying semi-structured sparse LLMs and offers a promising alternative for achieving highly compressed models when combined with existing quantization techniques.

For agents

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

get_harvested_code_for_paper("2407.20584")
get_code_for_paper("2407.20584")
have("2407.20584")

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

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

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

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

Connect an agent — have() is free.