Efficient implementation of stacked linear modules
Project description
Parallel Stacked Linear Modules for PyTorch
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 multiplenn.Linearlayers. This is useful for specialized neural architectures like Additive Decoders.- Subsetting Support: Both layers allow for subsetting output features during the forward pass, and
StackedLinearLayeradditionally 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)
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file stacked_linear-0.1.1.tar.gz.
File metadata
- Download URL: stacked_linear-0.1.1.tar.gz
- Upload date:
- Size: 15.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
8db3750c0e4afd6af31932749f1662bf27639a9190a6ad81d428d573df4e7aed
|
|
| MD5 |
f9e1de1561c8bfdaa18449372b977958
|
|
| BLAKE2b-256 |
98c85fd17a48ba2458913b6a089f2305b939b7dcf0e724ebbff99961bf4f00a6
|
Provenance
The following attestation bundles were made for stacked_linear-0.1.1.tar.gz:
Publisher:
release.yaml on moinfar/stacked-linear
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
stacked_linear-0.1.1.tar.gz -
Subject digest:
8db3750c0e4afd6af31932749f1662bf27639a9190a6ad81d428d573df4e7aed - Sigstore transparency entry: 1270988650
- Sigstore integration time:
-
Permalink:
moinfar/stacked-linear@23089af0fafd297a8706c932b9e062c6d492dc12 -
Branch / Tag:
refs/tags/v0.1.1 - Owner: https://github.com/moinfar
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yaml@23089af0fafd297a8706c932b9e062c6d492dc12 -
Trigger Event:
release
-
Statement type:
File details
Details for the file stacked_linear-0.1.1-py3-none-any.whl.
File metadata
- Download URL: stacked_linear-0.1.1-py3-none-any.whl
- Upload date:
- Size: 7.5 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
1e1521073467ca4843ecdd6b075ca347ca4ef1862b6534b1da4e95b6e862fe63
|
|
| MD5 |
18975e989416035bdee870370448f235
|
|
| BLAKE2b-256 |
0f870699df40a69dc88d8f80aaa02db16eb7513549a298ba39b00dc7477cd6cc
|
Provenance
The following attestation bundles were made for stacked_linear-0.1.1-py3-none-any.whl:
Publisher:
release.yaml on moinfar/stacked-linear
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
stacked_linear-0.1.1-py3-none-any.whl -
Subject digest:
1e1521073467ca4843ecdd6b075ca347ca4ef1862b6534b1da4e95b6e862fe63 - Sigstore transparency entry: 1270988676
- Sigstore integration time:
-
Permalink:
moinfar/stacked-linear@23089af0fafd297a8706c932b9e062c6d492dc12 -
Branch / Tag:
refs/tags/v0.1.1 - Owner: https://github.com/moinfar
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yaml@23089af0fafd297a8706c932b9e062c6d492dc12 -
Trigger Event:
release
-
Statement type: