SYNTOLOGY HomeExplorerAtlasCodeMethodologyAboutDevelopersFeedPricing
Paper · 2006.10859 · 2020

MARS: Masked Automatic Ranks Selection in Tensor Decompositions

arXiv · PDF · Open in the Atlas

Code that ran

2 of 4 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 2 have no contract verdict; 0 failures of our instrument; 2 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/2006.10859.json · badge: /api/ran/2006.10859.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
maxbourdon/mars canonical (classifier label)
classifier basis: census
2 ran · 2 no recorded run
FunctionStatusWhere it lives
compute_cum_reg Ran
ran on a synthesized input
maxbourdon/mars/main/mars.py
code served (permissive licence) · get_code("5dc1bc877c27464d")
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 float, ndim 0, dtype family float, shape () 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 numpy as np
import torch.nn as nn
from torch.distributions.utils import logits_to_probs, probs_to_logits, clamp_probs
from functools import partial

torch.manual_seed(0)

# Define a minimal TensorizedModel that satisfies the interface used by MARS
class TensorizedModel(nn.Module):
    def __init__(self, ranks):
        super().__init__()
        self.ranks = ranks
        # Create dummy cores for the tensorized model
        self.cores = nn.ParameterList([
            nn.Parameter(torch.randn(rank, 4)) for rank in ranks
        ])
    
    def forward(self, x, masks=None):
        # Simple forward pass that returns a tensor
        if masks is None:
            return torch.sum(self.cores[0])
        else:
            result = torch.tensor(0.0)
            for i, (core, mask) in enumerate(zip(self.cores, masks)):
                result = result + torch.sum(core * mask.unsqueeze(-1))
            return result

# Define the MARS class (copied from the function signature)
class MARS(nn.Module):

    def __init__(self, tensorized_model, pi=0.01, alpha=-1.0, temperature=0.1, sigma_inv=0.1, gamma=-0.1, zeta=1.1, eval_sample=False, ste=False, eval_logits_threshold=0.0):
        super().__init__()
        self.tensorized_model = tensorized_model
        self.log_prior_prob = np.log(pi)
        self.log_prior_prob_c = np.log(1.0 - pi)
        self.temperature = temperature
        self.l2_weight = 0.5 * sigma_inv ** 2
        self.gamma = gamma
        self.zeta = zeta
        self.zmg = self.zeta - self.gamma
        self.eval_sample = eval_sample
        self.ste = ste
        self.eval_logits_threshold = eval_logits_threshold
        self.F = partial(logits_to_probs, is_binary=True)
        self.F_inv = partial(probs_to_logits, is_binary=True)
        self.warmup = False
        self.phi_logits_list = []
        for R in self.tensorized_model.ranks:
            logits = nn.Parameter(torch.Tensor(R))
            logits.data.normal_(alpha, 0.01)
            self.phi_logits_list.append(logits)
        self.phi_logits_list = nn.ParameterList(self.phi_logits_list)

    def get_mask(self, logits):
        if self.eval_sample or self.training:
            u = clamp_probs(torch.rand(logits.shape, dtype=logits.dtype, device=logits.device))
            logits = logits + self.F_inv(u)
            if self.training:
                s = self.F(logits / self.temperature)
                s = s * self.zmg + self.gamma
                s = torch.clamp(s, min=0.0, max=1.0)
                if self.ste:
                    s_ste = torch.round(s)
                    s = (s_ste - s).detach() + s
                return s
        return logits > self.eval_logits_threshold

    def forward(self, x):
        if self.warmup:
            return self.tensorized_model(x)
        masks = [self.get_mask(logits) for logits in self.phi_logits_list]
        return self.tensorized_model(x, masks)

    def compute_reg(self):
        reg = 0.0
        probs_list = [self.F(logits) for logits in self.phi_logits_list]
        for probs in probs_list:
            probs_c = 1 - probs
            reg += torch.sum(probs * self.log_prior_prob + probs_c * self.log_prior_prob_c)
        if self.l2_weight > 0:
            reg -= self.l2_weight * sum((torch.sum(core ** 2) for core in self.tensorized_model.cores))
        return reg

# Define compute_cum_reg function (copied from the function signature)
def compute_cum_reg(model):
    reg = 0.0
    for layer in model.modules():
        if isinstance(layer, MARS):
            reg += layer.compute_reg()
    return reg

# Create a model with MARS layers
tensorized_model_1 = TensorizedModel(ranks=[3, 4])
tensorized_model_2 = TensorizedModel(ranks=[2, 3])

mars_layer_1 = MARS(tensorized_model_1, pi=0.01, alpha=-1.0, temperature=0.1)
mars_layer_2 = MARS(tensorized_model_2, pi=0.01, alpha=-1.0, temperature=0.1)

class TestModel(nn.Module):
    def __init__(self, mars1, mars2):
        super().__init__()
        self.mars1 = mars1
        self.mars2 = mars2
    
    def forward(self, x):
        return self.mars1(x) + self.mars2(x)

model = TestModel(mars_layer_1, mars_layer_2)

ARGS = {
    "model": model
}
Setup block drafted by
a language model, Claude Haiku 4.5, prompt python_fixture_v1, through the batch API
Imports
numpy, torch — import names as written, not package names to install; a name the repository itself provides is not a package
Returned
type float, ndim 0, dtype family float, shape () — shape () 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
masked_full Ran
ran on a synthesized input
maxbourdon/mars/main/tensorized_models.py
code served (permissive licence) · get_code("9f60be7520b1ad63")
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 (4, 5, 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
import torch.nn as nn

torch.manual_seed(0)

class MockTTWeight:
    """Mock TT-weight object with required attributes."""
    def __init__(self, ndims, ranks, shape, raw_shape, tt_cores, is_tt_matrix):
        self.ndims = ndims
        self.ranks = ranks
        self.shape = shape
        self.raw_shape = raw_shape
        self.tt_cores = tt_cores
        self.is_tt_matrix = is_tt_matrix

# Create a simple TT-tensor (not a matrix)
# TT-tensor with 3 dimensions, ranks [1, 2, 3, 1]
ndims = 3
ranks = [1, 2, 3, 1]
shape = [4, 5, 6]
raw_shape = None
is_tt_matrix = False

# Build tt_cores
tt_cores = []
# Core 0: shape (1, 4*2) = (1, 8)
tt_cores.append(torch.randn(1, 4*2))
# Core 1: shape (2, 5*3) = (2, 15)
tt_cores.append(torch.randn(2, 5*3))
# Core 2: shape (3, 6*1) = (3, 6)
tt_cores.append(torch.randn(3, 6*1))

tt_weight = MockTTWeight(
    ndims=ndims,
    ranks=ranks,
    shape=shape,
    raw_shape=raw_shape,
    tt_cores=tt_cores,
    is_tt_matrix=is_tt_matrix
)

# Create masks (optional) - one mask for each contraction step
masks = None

ARGS = {
    "tt_weight": tt_weight,
    "masks": masks
}
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 (4, 5, 6) — shape (4, 5, 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: none by the harness; any seed is in the setup block
get_MARS_attr Not yet run
unverified (harvested, no recorded run)
maxbourdon/mars/main/mars.py
code served (permissive licence) · get_code("8dd5732a5e8510ec")
How it ran

no invocation recorded.

masked_dense_tt_matmul Not yet run
unverified (harvested, no recorded run)
maxbourdon/mars/main/tensorized_models.py
code served (permissive licence) · get_code("1ce09009659054ee")
How it ran

no invocation recorded.

Also present in other papers' code

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

Tensor decomposition methods have proven effective in various applications, including compression and acceleration of neural networks. At the same time, the problem of determining optimal decomposition ranks, which present the crucial parameter controlling the compression-accuracy trade-off, is still acute. In this paper, we introduce MARS -- a new efficient method for the automatic selection of ranks in general tensor decompositions. During training, the procedure learns binary masks over decomposition cores that "select" the optimal tensor structure. The learning is performed via relaxed maximum a posteriori (MAP) estimation in a specific Bayesian model and can be naturally embedded into the standard neural network training routine. Diverse experiments demonstrate that MARS achieves better results compared to previous works in various tasks.

For agents

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

get_harvested_code_for_paper("2006.10859")
get_code_for_paper("2006.10859")
have("2006.10859")

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

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

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

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

Connect an agent — have() is free.