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.1.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.1-py3-none-any.whl (39.1 kB view details)

Uploaded Python 3

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

Hashes for torchshapeflow-0.2.1.tar.gz
Algorithm Hash digest
SHA256 df82044a0640c089eb19be06baccadabdec79865e56656ac70b94a56bb3d5efc
MD5 e50fc67b1c8dcdcb6b6734f325666a1d
BLAKE2b-256 5d39ece56ae54af9e095101736497f0f5423ddb5efdba434779674286870ca84

See more details on using hashes here.

Provenance

The following attestation bundles were made for torchshapeflow-0.2.1.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.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

Hashes for torchshapeflow-0.2.1-py3-none-any.whl
Algorithm Hash digest
SHA256 4a1b4d4e616ffedb9fe7233367a614694e16d9e80133fbd7ce3c6018d79b6b0c
MD5 0007c59f1e089712be5a6838b07c71b7
BLAKE2b-256 8be6e2a344c9577ac906c86d5d3e3f9b056b7d2c98e572911f2bd515929f45f9

See more details on using hashes here.

Provenance

The following attestation bundles were made for torchshapeflow-0.2.1-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