Skip to main content

Parallel Stacked Linear Modules for PyTorch

Tests Documentation Codecov

Efficient implementation of stacked linear modules in PyTorch, with support for output and stack subsetting.

Features

  • LinearLayer: A linear layer with support for efficient output subsetting.
  • StackedLinearLayer: A parallelized linear layer that applies multiple independent transformations across different input stacks simultaneously. This is significantly more efficient than for loop over multiple nn.Linear layers. This is useful for specialized neural architectures like Additive Decoders.
  • Subsetting Support: Both layers allow for subsetting output features during the forward pass, and StackedLinearLayer additionally supports subsetting stacks.

Installation

pip install stacked-linear

Or install from source:

pip install git+https://github.com/moinfar/stacked-linear.git

Quick Start

Linear Layer with Output Subsetting

import torch
from stacked_linear import LinearLayer

# Initialize a layer (10 inputs, 5 outputs)
layer = LinearLayer(10, 5)
x = torch.randn(2, 10)

# Forward pass on a subset of output features (indices 0, 2, and 4)
subset = torch.tensor([0, 2, 4])
output = layer(x, output_subset=subset)  # Shape: (2, 3)

Stacked Linear Layer

import torch
from stacked_linear import StackedLinearLayer

# 3 parallel stacks, each mapping 10 inputs to 5 outputs
layer = StackedLinearLayer(n_stacks=3, in_features=10, out_features=5)
x = torch.randn(2, 3, 10)  # (batch, stacks, features)

# Efficient parallel forward pass
output = layer(x)  # Shape: (2, 3, 5)

# Forward pass on a subset of output features across all stacks
subset = torch.tensor([1, 3])
output_subset = layer(x, output_subset=subset)  # Shape: (2, 3, 2)

# Forward pass on a subset of stacks
stack_subset = torch.tensor([[0, 2], [1, 2]]) # Indices for each batch item
x_subset = torch.randn(2, 2, 10)
output_stack_subset = layer(x_subset, stack_subset=stack_subset) # Shape: (2, 2, 5)

Metadata

Release files for stacked-linear 0.2.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for stacked-linear 0.2.0
File Size Uploaded
stacked_linear-0.2.0.tar.gz 16.5 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for stacked-linear 0.2.0
File Interpreter ABI Platform
stacked_linear-0.2.0-py3-none-any.whl Python 3 none any Details

Total release size: 24.2 kB

Release files / stacked_linear-0.2.0.tar.gz

Download URL stacked_linear-0.2.0.tar.gz
Size 16.5 kB
Tags Source
SHA-256 checksum
How to use checksums
5baf4f1195ebdfa265b6efeb6f5a4f82ae60f6fd2b663b5cf971aa8222fb9f8b
BLAKE2b-256 checksum
How to use checksums
bc278600a1bfbd8a1e4af7220d092fd2537846d940d3fc1020322f27607ab0ec
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.12

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Jun 19, 2026.

Transparency log

Release files / stacked_linear-0.2.0-py3-none-any.whl

Download URL stacked_linear-0.2.0-py3-none-any.whl
Size 7.7 kB
Tags Python 3
SHA-256 checksum
How to use checksums
3e5ae126ec6ca3315999b58792645605f159cf314a2aa9a861d9e21aa5459d08
BLAKE2b-256 checksum
How to use checksums
ce4a44d6f8e6f849a20b0bf6f6560d020f0fcbdf353eb14b486eb108512e97bc
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.12

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Jun 19, 2026.

Transparency log

Release history Release notifications | RSS feed

This release

0.2.0 This release

2 release files

0.1.3

2 release files

0.1.2

2 release files

0.1.1

2 release files

0.1.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page