Metadata-Version: 2.4
Name: tensi-shapes
Version: 0.3.0
Summary: Named tensor shapes for unannotated PyTorch: hovers, shape errors and a CLI, built on Pyrefly.
Author: Tristan Farran
License-Expression: MIT
Project-URL: Homepage, https://github.com/tristan-farran/tensi
Project-URL: Issues, https://github.com/tristan-farran/tensi/issues
Project-URL: Changelog, https://github.com/tristan-farran/tensi/blob/main/CHANGELOG.md
Keywords: pytorch,tensor,shapes,type-checking,pyrefly,jaxtyping,einops,lsp
Classifier: Development Status :: 4 - Beta
Classifier: Environment :: Console
Classifier: Intended Audience :: Developers
Classifier: Intended Audience :: Science/Research
Classifier: Operating System :: OS Independent
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3 :: Only
Classifier: Topic :: Scientific/Engineering :: Artificial Intelligence
Classifier: Topic :: Software Development :: Quality Assurance
Requires-Python: >=3.12
Description-Content-Type: text/markdown
License-File: LICENSE
Requires-Dist: pyrefly==1.5.0
Requires-Dist: pyrefly-torch-stubs==1.5.0
Requires-Dist: pyrefly-einops-stubs==1.5.0
Requires-Dist: parso>=0.8.4
Provides-Extra: test
Requires-Dist: pytest>=8; extra == "test"
Requires-Dist: jaxtyping; extra == "test"
Requires-Dist: einops; extra == "test"
Dynamic: license-file

<p align="center">
  <img src="https://raw.githubusercontent.com/tristan-farran/tensi/main/brand/tensi-logo.svg" alt="tensi" width="440">
</p>

<p align="center">
  <b>tensi sees your tensors.</b><br>
  Hover any PyTorch tensor and see its shape, with every dimension named.
</p>

---

```python
def forward(self, x):
    B, T, C = x.size()
    q, k, v = self.c_attn(x).split(self.n_embd, dim=2)
    k = k.view(B, T, self.n_head, C // self.n_head).transpose(1, 2)
    #   hover k → Tensor[[b, n_head, t, n_embd // n_head]]
```


## Install

**VS Code:** install **tensi** from the Marketplace. It follows each project's interpreter (the Python
extension's choice, else `.venv`), so switching projects or running `uv sync` needs no setup. If tensi is
missing it offers `uv add --dev tensi-shapes` for the project, or `uv tool install tensi-shapes` once for
all projects. It runs beside Pylance and only adds shapes.

**Command line, CI, other editors:**

```bash
uv add --dev tensi-shapes      # or: pip install tensi-shapes, into the project's environment
uv tool install tensi-shapes   # or once for all projects; it reads torch from each project's .venv
tensi doctor                   # checks Pyrefly, the stubs and the interpreter Pyrefly picks, with one real probe
```

The package is `tensi-shapes` on PyPI; the command and the import are `tensi`. It brings Pyrefly 1.5.0
and its torch shape stubs; your project needs `torch` installed.

Any editor that speaks LSP can run `tensi lsp` as a language server for Python files. Python 3.12+;
`rearrange` and friends are shape-aware on Python 3.12+ (Pyrefly's einops stubs need it).

## Try it

```console
$ tensi peek model.py
tensi peek v0.3.0  model.py  2.0s

  CausalSelfAttention.forward
    56  q, k, v   [b, t, n_embd]
    57  k         [b, n_head, t, n_embd // n_head]
    67  att       [b, n_head, t, t]
    72  y         [b, t, n_embd]
  MLP.forward
    88  x         [b, t, 4 * n_embd]
  GPT.forward
   177  tok_emb   [b, t, n_embd]
   178  pos_emb   [t, n_embd]
   186  logits    [b, t, vocab_size]
  GPT.generate
   321  v, _      [b, int]
   326  idx_next  [b, 1]

  37 tensors, 32 fully named
```

```console
$ tensi check model.py
tensi check v0.3.0  model.py  2.0s
  ok no shape errors

$ tensi check bad.py
tensi check v0.3.0  bad.py  819ms
  x bad.py:17:9  Argument `Tensor[[b, 7, v]]` is not assignable to parameter `x` with type `Tensor[[b, 7, d]]` in function `Block.forward`
  x bad.py:18:9  `@` is not supported between `Tensor[[b, d]]` and `Tensor[[v, 3]]`

  2 shape errors
```

`tensi check src/` checks every Python file under a folder and exits 1 when it finds a shape error, so it
can gate CI.

## Contributing

See [CONTRIBUTING.md](https://github.com/tristan-farran/tensi/blob/main/CONTRIBUTING.md) for the development setup, tests and releases.

<sub>tensi is built on Pyrefly (MIT) and its torch stubs. The mascot is a small tensor that is very good at
looking.</sub>
