SYNTOLOGY HomeExplorerAtlasCodeMethodologyAboutDevelopersFeedPricing
Paper · 2409.18850 · 2024

Two Sparse Matrices are Better than One: Sparsifying Neural Networks with Double Sparse Factorization

arXiv · PDF · Open in the Atlas

Code that ran

6 of 12 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, 1 violated it and 0 have no contract verdict; 5 failures of our instrument; 6 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/2409.18850.json · badge: /api/ran/2409.18850.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
usamec/double_sparse canonical (classifier label)
classifier basis: census
6 ran · 6 no recorded run
FunctionStatusWhere it lives
ent Ran
ran, violated the contract we drafted
usamec/double_sparse/doublesparse.py
code served (permissive licence) · get_code("49a001a61f2633ae")
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 1, dtype family float, shape (3,) 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

def ent(p):
    return -(p * np.log2(p) + (1 - p) * np.log2(1 - p))

# The function takes a single parameter 'p' which should be a numpy array or scalar
# It computes binary entropy: -(p*log2(p) + (1-p)*log2(1-p))
# p should be between 0 and 1 (probability)

ARGS = {
    "p": np.array([0.25, 0.5, 0.75])
}
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 1, dtype family float, shape (3,) — shape (3,) 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
find_layers Ran
ran; our contract draft was wrong, not the code
usamec/double_sparse/modelutils.py
pointer only (licence: Apache-2.0); the stored copy get_code serves, from squeezeailab/kvquant, is pointer only (licence: NONE) · get_code("a9e7f2cdf016b88b")
How it ran

The body of this sample is withheld: this paper's link allows the body inline (Apache-2.0), but get_code serves the stored copy, first harvested from squeezeailab/kvquant, and GitHub detected no licence in that repository when it was checked. The setup block that called it is withheld with it, because it is written against that body. source_path and origin say where the code lives, to read under the repository's own terms. A run is recorded.

find_other2 Ran
ran; our contract draft was wrong, not the code
usamec/double_sparse/doublesparse.py
code served (permissive licence) · get_code("2c35e419392e5ae7")
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 torch.nn as nn

torch.manual_seed(0)

# Construct small tensors with distinct dimensions
# A: (m, n) - input matrix
# W: (m, k) - weight/target matrix
# Z: (n, k) - sparse coefficient matrix
# U: (n, k) - dual variable

m, n, k = 5, 4, 3

A = torch.randn(m, n)
W = torch.randn(m, k)
Z = torch.randn(n, k)
U = torch.randn(n, k)

# nnz: number of non-zero elements
nnz = max(1, int(0.3 * (n * k)))

# print_sc: a callable that accepts a tensor (for debug printing)
def print_sc(tensor):
    pass

# fixmask: optional mask tensor with same shape as Z
fixmask = None

ARGS = {
    "A": A,
    "W": W,
    "nnz": nnz,
    "Z": Z,
    "U": U,
    "print_sc": print_sc,
    "debug": False,
    "reg": 0.01,
    "rho_start": 0.03,
    "iters": 5,
    "prune_iters": 2,
    "fixmask": fixmask,
}
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 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
get_imagenet Ran
ran; our contract draft was wrong, not the code
usamec/double_sparse/other_experiments/datautils.py
code served (permissive licence) · get_code("0723e2735373f4d8")
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. 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 os
import tempfile
import torch
import torchvision.datasets as datasets
import torchvision.transforms as transforms
from PIL import Image
import numpy as np

torch.manual_seed(0)

# Create a temporary directory structure with minimal ImageNet-like data
temp_dir = tempfile.mkdtemp()
train_dir = os.path.join(temp_dir, 'train')
val_dir = os.path.join(temp_dir, 'val')

os.makedirs(train_dir, exist_ok=True)
os.makedirs(val_dir, exist_ok=True)

# Create dummy class directories
for split_dir in [train_dir, val_dir]:
    for class_id in ['class_0', 'class_1']:
        class_dir = os.path.join(split_dir, class_id)
        os.makedirs(class_dir, exist_ok=True)
        
        # Create a couple of dummy images for each class
        for img_id in range(2):
            # Create a small dummy image (224x224 RGB)
            img_array = np.random.randint(0, 256, (224, 224, 3), dtype=np.uint8)
            img = Image.fromarray(img_array, 'RGB')
            img_path = os.path.join(class_dir, f'img_{img_id}.jpg')
            img.save(img_path)

ARGS = {
    'path': temp_dir,
    'noaug': False,
}
Setup block drafted by
a language model, Claude Haiku 4.5, prompt python_fixture_v1, through the batch API
Imports
PIL, numpy, torch, torchvision — 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: none by the harness; any seed is in the setup block
get_llama Ran
ran; the contract check could not run (RAISES, DEP_MISSING or TIMEOUT)
usamec/double_sparse/llama.py
code served (permissive licence) · get_code("bf5b0ce87ee19903")
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 LlamaForCausalLM. 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
from transformers import LlamaConfig, LlamaForCausalLM

# Mock the from_pretrained to avoid actual model download
original_from_pretrained = LlamaForCausalLM.from_pretrained

def mock_from_pretrained(model_name, **kwargs):
    # Create a minimal LlamaForCausalLM with tiny config
    config = LlamaConfig(
        vocab_size=100,
        hidden_size=64,
        intermediate_size=128,
        num_hidden_layers=2,
        num_attention_heads=2,
        max_position_embeddings=512,
    )
    model = LlamaForCausalLM(config)
    return model

LlamaForCausalLM.from_pretrained = mock_from_pretrained

# Set random seed for reproducibility
torch.manual_seed(0)

# The function takes a single parameter 'model' which is a model identifier string
# that gets passed to LlamaForCausalLM.from_pretrained()
ARGS = {
    "model": "meta-llama/Llama-2-7b"
}
Setup block drafted by
a language model, Claude Haiku 4.5, prompt python_fixture_v1, through the batch API
Imports
torch, transformers — import names as written, not package names to install; a name the repository itself provides is not a package
Returned
type LlamaForCausalLM — a LlamaForCausalLM output has no array shape of its own; none is stated — the instrument coerces any output to an array; for a LlamaForCausalLM 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
mag_prune Ran
ran; our contract draft was wrong, not the code
usamec/double_sparse/doublesparse.py
code served (permissive licence) · get_code("a1c5a6a697a88d18")
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 2, dtype family float, shape (4, 3) 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

torch.manual_seed(0)

# W is a tensor that has methods: .abs(), .flatten(), .sort(), .numel()
# and supports multiplication with a boolean mask
W = torch.randn(4, 3)

# sp is a sparsity parameter (float between 0 and 1)
sp = 0.6

ARGS = {
    "W": W,
    "sp": sp
}
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 2, dtype family float, shape (4, 3) — shape (4, 3) 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_coco Not yet run
unverified (harvested, no recorded run)
usamec/double_sparse/other_experiments/datautils.py
code served (permissive licence) · get_code("75dbb95badb47b1a")
How it ran

no invocation recorded.

get_ptb Not yet run
unverified (harvested, no recorded run)
usamec/double_sparse/datautils.py
pointer only (licence: Apache-2.0); the stored copy get_code serves, from Aaronhuang-778/MC-MoE, is pointer only (licence: NONE) · get_code("a7cbf4fc49c71e03")
How it ran

The body of this sample is withheld: this paper's link allows the body inline (Apache-2.0), but get_code serves the stored copy, first harvested from Aaronhuang-778/MC-MoE, and GitHub detected no licence in that repository when it was checked. The setup block that called it is withheld with it, because it is written against that body. source_path and origin say where the code lives, to read under the repository's own terms. No invocation recorded.

get_tokenizer Not yet run
unverified (harvested, no recorded run)
usamec/double_sparse/datautils.py
code served (permissive licence) · get_code("729f957048af4a3f")
How it ran

no invocation recorded.

get_wikitext2 Not yet run
unverified (harvested, no recorded run)
usamec/double_sparse/datautils.py
pointer only (licence: Apache-2.0); the stored copy get_code serves, from Aaronhuang-778/MC-MoE, is pointer only (licence: NONE) · get_code("011909315dfdbc2e")
How it ran

The body of this sample is withheld: this paper's link allows the body inline (Apache-2.0), but get_code serves the stored copy, first harvested from Aaronhuang-778/MC-MoE, and GitHub detected no licence in that repository when it was checked. The setup block that called it is withheld with it, because it is written against that body. source_path and origin say where the code lives, to read under the repository's own terms. No invocation recorded.

llama_sequential Not yet run
unverified (harvested, no recorded run)
usamec/double_sparse/llama.py
code served (permissive licence) · get_code("14961351f5344dc1")
How it ran

no invocation recorded.

random_subset Not yet run
unverified (harvested, no recorded run)
usamec/double_sparse/other_experiments/datautils.py
code served (permissive licence) · get_code("52ba3cdd84734157")
How it ran

no invocation recorded.

Also present in other papers' code

Of 12 samples lifted from this paper's linked repositories, 12 carry a function identity and 0 do not. Of the 12 distinct functions with an identity, 4 are also present in other papers whose code we hold (4 with at least one paper dated earlier, 0 the same month, 4 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.

FunctionAlso present inEarliest-datedOthers named
find_layers 27 other papers
19 dated earlier, 6 later, 1 same year, order not determinable, 1 undated
2203.13474 (2022-03)
CodeGen: An Open Large Language Model for Code with Multi-Turn Program Synthesis
2023.emnlp-main.892 (2023 (year only))
Z-FOLD: A Frustratingly Easy Post-Training Quantization Scheme for LLMs
2307.09288 (2023-07)
Llama 2: Open Foundation and Fine-Tuned Chat Models
and 24 more not named here
get_ptb 7 other papers
4 dated earlier, 3 later
2310.00034 (2023-10)
PB-LLM: Partially Binarized Large Language Models
2402.04291 (2024-02)
BiLLM: Pushing the Limit of Post-Training Quantization for LLMs
2402.17946 (2024-02)
SparseLLM: Towards Global Pruning of Pre-trained Language Models
and 4 more not named here
get_tokenizer 6 other papers
3 dated earlier, 3 later
2310.00034 (2023-10)
PB-LLM: Partially Binarized Large Language Models
2402.04291 (2024-02)
BiLLM: Pushing the Limit of Post-Training Quantization for LLMs
2402.17946 (2024-02)
SparseLLM: Towards Global Pruning of Pre-trained Language Models
and 3 more not named here
get_wikitext2 6 other papers
3 dated earlier, 3 later
2310.00034 (2023-10)
PB-LLM: Partially Binarized Large Language Models
2402.04291 (2024-02)
BiLLM: Pushing the Limit of Post-Training Quantization for LLMs
2402.17946 (2024-02)
SparseLLM: Towards Global Pruning of Pre-trained Language Models
and 3 more not named here

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

Neural networks are often challenging to work with due to their large size and complexity. To address this, various methods aim to reduce model size by sparsifying or decomposing weight matrices, such as magnitude pruning and low-rank or block-diagonal factorization. In this work, we present Double Sparse Factorization (DSF), where we factorize each weight matrix into two sparse matrices. Although solving this problem exactly is computationally infeasible, we propose an efficient heuristic based on alternating minimization via ADMM that achieves state-of-the-art results, enabling unprecedented sparsification of neural networks. For instance, in a one-shot pruning setting, our method can reduce the size of the LLaMA2-13B model by 50% while maintaining better performance than the dense LLaMA2-7B model. We also compare favorably with Optimal Brain Compression, the state-of-the-art layer-wise pruning approach for convolutional neural networks. Furthermore, accuracy improvements of our method persist even after further model fine-tuning. Code available at: https://github.com/usamec/double_sparse.

For agents

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

get_harvested_code_for_paper("2409.18850")
get_code_for_paper("2409.18850")
have("2409.18850")

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

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

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

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

Connect an agent — have() is free.