Static AST-based PyTorch tensor shape analysis.
Project description
TorchShapeFlow
TorchShapeFlow is a static, AST-based shape analyzer for PyTorch. It reads your Python source — no execution required — infers tensor shapes through your code, and reports mismatches as structured diagnostics.
from typing import Annotated
import torch
import torch.nn as nn
from torchshapeflow import Shape
class Net(nn.Module):
def __init__(self):
self.conv = nn.Conv2d(3, 8, 3, padding=1)
self.linear = nn.Linear(8 * 32 * 32, 10)
def forward(self, x: Annotated[torch.Tensor, Shape("B", 3, 32, 32)]):
y = self.conv(x) # inferred: [B, 8, 32, 32]
z = y.flatten(1) # inferred: [B, 8192]
return self.linear(z) # inferred: [B, 10]
$ tsf check mymodel.py
mymodel.py: ok
Install
pip install torchshapeflow
Documentation
Full docs at davidxswang.github.io/torchshapeflow
- Quickstart — install and run your first check
- Annotation syntax — how to annotate your tensors
- Supported operators — what is analyzed and what shapes are inferred
- Limitations — what the analyzer does not handle
Contributing
git clone https://github.com/Davidxswang/torchshapeflow
cd torchshapeflow
make install # uv sync --extra dev
make check # format + lint + typecheck + tests
See docs/development.md for the full development guide: all make targets, CI workflow descriptions, and how to add new operators.
Release
See RELEASING.md for the full release procedure.
Build commands:
make python-dist— wheel and sdist intodist/make extension-package— VS Code extension.vsixmake build— both
Marketplace publishing in the release workflow is gated on GitHub Actions secrets:
VSCE_PATfor the VS Code MarketplaceOVSX_PATfor Open VSX
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 torchshapeflow-0.2.1.tar.gz.
File metadata
- Download URL: torchshapeflow-0.2.1.tar.gz
- Upload date:
- Size: 58.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
df82044a0640c089eb19be06baccadabdec79865e56656ac70b94a56bb3d5efc
|
|
| MD5 |
e50fc67b1c8dcdcb6b6734f325666a1d
|
|
| BLAKE2b-256 |
5d39ece56ae54af9e095101736497f0f5423ddb5efdba434779674286870ca84
|
Provenance
The following attestation bundles were made for torchshapeflow-0.2.1.tar.gz:
Publisher:
release.yml on Davidxswang/torchshapeflow
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
torchshapeflow-0.2.1.tar.gz -
Subject digest:
df82044a0640c089eb19be06baccadabdec79865e56656ac70b94a56bb3d5efc - Sigstore transparency entry: 1101494953
- Sigstore integration time:
-
Permalink:
Davidxswang/torchshapeflow@82c40a66e87a44d2b61e30438f33a531c1d4b28e -
Branch / Tag:
refs/tags/v0.2.1 - Owner: https://github.com/Davidxswang
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@82c40a66e87a44d2b61e30438f33a531c1d4b28e -
Trigger Event:
push
-
Statement type:
File details
Details for the file torchshapeflow-0.2.1-py3-none-any.whl.
File metadata
- Download URL: torchshapeflow-0.2.1-py3-none-any.whl
- Upload date:
- Size: 39.1 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
4a1b4d4e616ffedb9fe7233367a614694e16d9e80133fbd7ce3c6018d79b6b0c
|
|
| MD5 |
0007c59f1e089712be5a6838b07c71b7
|
|
| BLAKE2b-256 |
8be6e2a344c9577ac906c86d5d3e3f9b056b7d2c98e572911f2bd515929f45f9
|
Provenance
The following attestation bundles were made for torchshapeflow-0.2.1-py3-none-any.whl:
Publisher:
release.yml on Davidxswang/torchshapeflow
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
torchshapeflow-0.2.1-py3-none-any.whl -
Subject digest:
4a1b4d4e616ffedb9fe7233367a614694e16d9e80133fbd7ce3c6018d79b6b0c - Sigstore transparency entry: 1101495030
- Sigstore integration time:
-
Permalink:
Davidxswang/torchshapeflow@82c40a66e87a44d2b61e30438f33a531c1d4b28e -
Branch / Tag:
refs/tags/v0.2.1 - Owner: https://github.com/Davidxswang
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@82c40a66e87a44d2b61e30438f33a531c1d4b28e -
Trigger Event:
push
-
Statement type: