SYNTOLOGY HomeExplorerAtlasCodeMethodologyAboutDevelopersFeedPricing
Paper · 2310.13225 · ICLR · 2024

Scalable Neural Network Kernels

Krzysztof Choromanski, Arijit Sehanobish, Valerii Likhosherstov, Avinava Dubey, Yunfan Zhao

arXiv · PDF · Open in the Atlas

Code that ran

6 of 6 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; 2 honoured the contract we drafted, 0 violated it and 1 has no contract verdict; 3 failures of our instrument; 0 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/2310.13225.json · badge: /api/ran/2310.13225.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
arijitthegame/neural-network-kernels canonical (classifier label)
classifier basis: classifier_2025
6 ran · 0 no recorded run
FunctionStatusWhere it lives
NNK_Relu Ran
ran on a synthesized input
arijitthegame/neural-network-kernels/src/nnk/nnk.py
code served (permissive licence) · get_code("07257301af3ee38e")
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, 2) 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
from torch import nn
from distutils.version import LooseVersion

TORCH_GE_1_8_0 = LooseVersion(torch.__version__) >= LooseVersion('1.8.0')

def gaussian_orthogonal_random_matrix(nb_rows, nb_columns, scaling=0, device=None):
    nb_full_blocks = int(nb_rows / nb_columns)
    block_list = []
    for _ in range(nb_full_blocks):
        q = orthogonal_matrix_chunk(nb_columns, device=device)
        block_list.append(q)
    remaining_rows = nb_rows - nb_full_blocks * nb_columns
    if remaining_rows > 0:
        q = orthogonal_matrix_chunk(nb_columns, device=device)
        block_list.append(q[:remaining_rows])
    final_matrix = torch.cat(block_list)
    if scaling == 0:
        multiplier = torch.randn((nb_rows, nb_columns), device=device).norm(dim=1)
    elif scaling == 1:
        multiplier = math.sqrt(float(nb_columns)) * torch.ones((nb_rows,), device=device)
    else:
        raise ValueError(f'Invalid scaling {scaling}')
    return torch.diag(multiplier) @ final_matrix

def orthogonal_matrix_chunk(cols, device=None):
    unstructured_block = torch.randn((cols, cols), device=device)
    if TORCH_GE_1_8_0:
        q, r = torch.linalg.qr(unstructured_block.cpu(), mode='reduced')
    else:
        q, r = torch.qr(unstructured_block.cpu(), some=True)
    q, r = map(lambda t: t.to(device), (q, r))
    return q.t()

def phi_relu_mapping_torch(xw, num_rand_features, dim=None, seed=0, device='cpu', proj_matrix=None, constant=0, orthogonal=False, normalize=False, normalization_constant=None):
    """
    Args :
        xw : Tensor of shape [b, s, dim] or [b, dim]
        dim : input dimension of xw
        proj_matrix : matrix of size (num_rfs, dim)
    """
    if normalize:
        if normalization_constant is None:
            xw = torch.nn.functional.normalize(xw)
        else:
            xw = normalization_constant * torch.nn.functional.normalize(xw)
    if proj_matrix is None:
        torch.manual_seed(seed)
        if orthogonal:
            gs = gaussian_orthogonal_random_matrix(num_rand_features, dim, scaling=0, device=device)
        else:
            gs = torch.randn(num_rand_features, dim).to(device)
    else:
        gs = proj_matrix.to(device)
    if len(xw.shape) == 2:
        dot_products = torch.einsum('ij,jk->ik', xw, gs.t())
    elif len(xw.shape) == 3:
        dot_products = torch.einsum('bij,jk->bik', xw, gs.t())
    else:
        raise ValueError('Unsuported Tensor shape')
    return 1.0 / math.sqrt(num_rand_features) * torch.maximum(dot_products, constant * torch.ones_like(dot_products))

class NNK_Relu(nn.Module):

    def __init__(self, input_weights, num_rfs, dim, model_device, seed=0, normalize=False, normalization_constant=None, orthogonal=False, constant=0):
        """ "
        Args :
            input_weights : [b, s, dim] or [b, dim]
            dim : dimension of the input tensor
            proj_matrix : matrix of shape (num_rf, dim)
        """
        super().__init__()
        self.input_weights = input_weights
        self.num_rfs = num_rfs
        self.dim = dim
        self.model_device = model_device
        self.seed = seed
        self.normalize = normalize
        self.normalization_constant = normalization_constant
        self.orthogonal = orthogonal
        self.constant = constant
        if self.orthogonal:
            self.projection_matrix = gaussian_orthogonal_random_matrix(self.num_rfs, self.dim, scaling=0, device=self.model_device)
        else:
            self.projection_matrix = torch.randn(self.num_rfs, self.dim).to(self.model_device)
        self.weights = phi_relu_mapping_torch(xw=self.input_weights, num_rand_features=self.num_rfs, dim=self.dim, device=self.model_device, seed=self.seed, normalize=self.normalize, normalization_constant=self.normalization_constant, orthogonal=self.orthogonal, constant=self.constant, proj_matrix=self.projection_matrix)
        self.weights = nn.Parameter(self.weights)

    def forward(self, x):
        output_x = phi_relu_mapping_torch(xw=x, num_rand_features=self.num_rfs, dim=self.dim, device=self.model_device, seed=self.seed, normalize=self.normalize, normalization_constant=self.normalization_constant, orthogonal=self.orthogonal, constant=self.constant, proj_matrix=self.projection_matrix)
        return output_x @ self.weights.t()


INIT_ARGS = {
    'input_weights': torch.randn(2, 4),
    'num_rfs': 8,
    'dim': 4,
    'model_device': 'cpu',
    'seed': 0,
    'normalize': False,
    'normalization_constant': None,
    'orthogonal': False,
    'constant': 0,
}

ARGS = {
    'x': torch.randn(2, 4),
}
Setup block drafted by
a language model, class construct-then-call prompt, model not recorded
Imports
distutils, 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, 2) — shape (2, 2) 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)
gaussian_orthogonal_random_matrix Ran
ran, honoured the contract we drafted
arijitthegame/neural-network-kernels/src/nnk/nnk.py
code served (permissive licence) · get_code("2c0818e72b25c605")
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 Tensor, ndim 2, dtype family float, shape (8, 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 math

torch.manual_seed(0)

ARGS = {
    'nb_rows': 8,
    'nb_columns': 4,
    'scaling': 0,
    'device': None,
}
Setup block drafted by
a language model, Claude Haiku 4.5, prompt python_fixture_v1
Imports
distutils, 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 (8, 4) — shape (8, 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: none by the harness; any seed is in the setup block
orthogonal_matrix_chunk Ran
ran, honoured the contract we drafted
arijitthegame/neural-network-kernels/src/nnk/nnk.py
code served (permissive licence) · get_code("97b8b7b080cf8316")
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 Tensor, ndim 2, dtype family float, shape (4, 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

torch.manual_seed(0)

ARGS = {
    'cols': 4,
    'device': None,
}
Setup block drafted by
a language model, Claude Haiku 4.5, prompt python_fixture_v1
Imports
distutils, 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, 4) — shape (4, 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: none by the harness; any seed is in the setup block
phi_relu_mapping_torch Ran
ran; the contract check could not run (RAISES, DEP_MISSING or TIMEOUT)
arijitthegame/neural-network-kernels/src/nnk/nnk.py
code served (permissive licence) · get_code("12d992bada5a8f1f")
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 Tensor, ndim 2, dtype family float, shape (2, 5) 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)

# Create small test tensors
xw_2d = torch.randn(2, 4)  # [b, dim]
xw_3d = torch.randn(2, 3, 4)  # [b, s, dim]

# Create a projection matrix
proj_matrix = torch.randn(5, 4)  # [num_rand_features, dim]

ARGS = {
    'xw': xw_2d,
    'num_rand_features': 5,
    'dim': 4,
    'seed': 0,
    'device': 'cpu',
    'proj_matrix': None,
    'constant': 0,
    'orthogonal': False,
    'normalize': False,
    'normalization_constant': None,
}
Setup block drafted by
a language model, Claude Haiku 4.5, prompt python_fixture_v1
Imports
distutils, 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, 5) — shape (2, 5) 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
torch_apply_along_axis Ran
ran; our contract draft was wrong, not the code
arijitthegame/neural-network-kernels/src/nnk/nnk.py
code served (permissive licence) · get_code("20927dc12ec540d0")
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 Tensor, ndim 1, dtype family float, shape (2,) 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

torch.manual_seed(0)

# Define a simple function that will be applied along an axis
def sum_function(x):
    """Simple function that sums a tensor"""
    return x.sum()

# Create a small tensor with distinct dimensions
x = torch.randn(2, 4, 3)

# Define the arguments dictionary
ARGS = {
    "function": sum_function,
    "x": x,
    "axis": 0
}
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 Tensor, ndim 1, dtype family float, shape (2,) — shape (2,) 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
torch_apply_along_axis_asym_kernel Ran
ran; the contract check could not run (RAISES, DEP_MISSING or TIMEOUT)
arijitthegame/neural-network-kernels/src/nnk/nnk.py
code served (permissive licence) · get_code("018c1037643f8259")
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 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
import torch.nn as nn

torch.manual_seed(0)

# Define a simple function that will be vmapped
def simple_function(x):
    return x * 2

def simple_function_with_bias(x, b):
    return x + b

# Test case 1: b_term is None
ARGS = {
    "function": simple_function,
    "x": torch.randn(2, 4),
    "axis": 0,
    "b_term": None,
    "device": torch.device("cpu")
}

# Alternative test case 2: b_term is a 1D vector
ARGS_WITH_BIAS = {
    "function": simple_function_with_bias,
    "x": torch.randn(2, 4),
    "axis": 0,
    "b_term": torch.randn(2),
    "device": torch.device("cpu")
}

# Use the first case as the main ARGS
ARGS = {
    "function": simple_function,
    "x": torch.randn(2, 4),
    "axis": 0,
    "b_term": None,
    "device": torch.device("cpu")
}
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 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: none by the harness; any seed is in the setup block

Also present in other papers' code

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

FunctionAlso present inEarliest-datedOthers named
gaussian_orthogonal_random_matrix
brick of this paper's assembly: helper
2 other papers
2 dated earlier
2009.14794 (2020-09)
Rethinking Attention with Performers
2201.03794 (2022-01)
Efficient Non-local Contrastive Attention for Image Super-resolution
orthogonal_matrix_chunk
brick of this paper's assembly: helper
1 other paper
1 dated earlier · 1 only as an assembly brick
2009.14794 (2020-09)
Rethinking Attention with Performers

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

We introduce the concept of scalable neural network kernels (SNNKs), the replacements of regular feedforward layers (FFLs), capable of approximating the latter, but with favorable computational properties. SNNKs effectively disentangle the inputs from the parameters of the neural network in the FFL, only to connect them in the final computation via the dot-product kernel. They are also strictly more expressive, as allowing to model complicated relationships beyond the functions of the dot-products of parameter-input vectors. We also introduce the neural network bundling process that applies SNNKs to compactify deep neural network architectures, resulting in additional compression gains. In its extreme version, it leads to the fully bundled network whose optimal parameters can be expressed via explicit formulae for several loss functions (e.g. mean squared error), opening a possibility to bypass backpropagation. As a by-product of our analysis, we introduce the mechanism of the universal random features (or URFs), applied to instantiate several SNNK variants, and interesting on its own in the context of scalable kernel methods. We provide rigorous theoretical analysis of all these concepts as well as an extensive empirical evaluation, ranging from point-wise kernel estimation to Transformers' fine-tuning with novel adapter layers inspired by SNNKs. Our mechanism provides up to 5x reduction in the number of trainable parameters, while maintaining competitive accuracy.

For agents

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

get_harvested_code_for_paper("2310.13225")
get_code_for_paper("2310.13225")
have("2310.13225")

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

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

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

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

Connect an agent — have() is free.