Skip to main content

Static AST-based PyTorch tensor shape analysis.

Project description

TorchShapeFlow

CI PyPI Python License: MIT

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

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 into dist/
  • make extension-package — VS Code extension .vsix
  • make build — both

Marketplace publishing in the release workflow is gated on GitHub Actions secrets:

  • VSCE_PAT for the VS Code Marketplace
  • OVSX_PAT for Open VSX

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

torchshapeflow-0.2.0.tar.gz (58.1 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

torchshapeflow-0.2.0-py3-none-any.whl (39.1 kB view details)

Uploaded Python 3

File details

Details for the file torchshapeflow-0.2.0.tar.gz.

File metadata

  • Download URL: torchshapeflow-0.2.0.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

Hashes for torchshapeflow-0.2.0.tar.gz
Algorithm Hash digest
SHA256 ee9b7146d61fae4878150ab748298d235f73d9e9a3411656c17a13ddd9bceef4
MD5 7d7776422753f6bdd6378abc9d5c894c
BLAKE2b-256 79eb495a743d0ae9fbd2fea52b3e95f85c2d8471b7f574787a85f7a2b85cbd2c

See more details on using hashes here.

Provenance

The following attestation bundles were made for torchshapeflow-0.2.0.tar.gz:

Publisher: release.yml on Davidxswang/torchshapeflow

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file torchshapeflow-0.2.0-py3-none-any.whl.

File metadata

  • Download URL: torchshapeflow-0.2.0-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

Hashes for torchshapeflow-0.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 0eb80977ec4e4d73dca0b594ce7d394cdccf6540b25965f1762035f0052800fe
MD5 0e86fc51c4ba358db31e911ad5a0e160
BLAKE2b-256 e482b94f5104e29efa067df50fd6db782128b16251db26021f0b507393cf35a7

See more details on using hashes here.

Provenance

The following attestation bundles were made for torchshapeflow-0.2.0-py3-none-any.whl:

Publisher: release.yml on Davidxswang/torchshapeflow

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page