Skip to content

Commit 6ea1442

Browse files
stroxlermeta-codesync[bot]
authored andcommitted
Document tensor-shape stub packages
Summary: Give prospective tensor-shape users an early inventory of supported libraries and their exact PyPI distribution names, including the non-obvious `jax-pyrefly-stubs` name. Explain that Pyrefly's shape packages share a release version and pin one another exactly while leaving runtime library versions to the project. ___ landed-with-radar-review Differential Revision: D125223853 fbshipit-source-id: 0a28570a50aaa1a576f6b91b3536cfadd7b66e55
1 parent a1f2ef8 commit 6ea1442

1 file changed

Lines changed: 24 additions & 13 deletions

File tree

‎website/docs/tensor-shapes-setup.mdx‎

Lines changed: 24 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -29,24 +29,35 @@ getting your first shape-annotated code running.
2929

3030
## Installation
3131

32-
Tensor shape checking requires shape-aware stubs to be available through normal
33-
import resolution. Install them from PyPI:
32+
Pyrefly publishes shape-aware stub packages for these libraries:
33+
34+
- **PyTorch:** `pyrefly-torch-stubs`
35+
- **JAX:** `jax-pyrefly-stubs` (not `pyrefly-jax-stubs`)
36+
- **NumPy:** `pyrefly-numpy-stubs`
37+
- **einops:** `pyrefly-einops-stubs` (currently for PyTorch tensors)
38+
39+
Coverage is partial and growing. Install the packages for the libraries your
40+
project uses. For example, to enable PyTorch shape checking:
3441

3542
```bash
3643
pip install pyrefly-torch-stubs
3744
```
3845

39-
`pyrefly-torch-stubs` is a PEP 561 stub-only package: it carries type
40-
information for PyTorch, and leaves the runtime `torch` package alone. PyTorch's
41-
own type stubs don't carry shape information, so these stubs take precedence
42-
over them and provide shape-aware versions (e.g., `nn.Conv2d.__init__` that
43-
captures kernel size, stride, and padding as type-level values, and a `forward`
44-
that computes the output spatial dimensions).
45-
46-
Installing it also pulls in `pyrefly-shape-extensions`, which provides the
47-
`shape_extensions` package. `shape_extensions` exports `Int` — the bridge
48-
between runtime integer values and type-level symbols. Both packages are
49-
versioned in lockstep with Pyrefly.
46+
The packages are PEP 561 stub-only distributions: they provide shape-aware type
47+
information without replacing or shadowing the runtime libraries. For example,
48+
`pyrefly-torch-stubs` provides versions of APIs such as `nn.Conv2d.__init__`
49+
that capture kernel size, stride, and padding as type-level values, plus a
50+
`forward` method that computes the output spatial dimensions.
51+
52+
All tensor-shape packages are released with the same version number as Pyrefly.
53+
The stub packages pin their Pyrefly shape dependencies to that exact version,
54+
including `pyrefly-shape-extensions`, so upgrade Pyrefly and its shape packages
55+
together. The PyTorch, JAX, and NumPy runtime dependencies remain unpinned, so
56+
your project can choose the runtime library versions it needs.
57+
58+
`pyrefly-shape-extensions` provides the `shape_extensions` import. It exports
59+
`Int` — the bridge between runtime integer values and type-level symbols — and
60+
other runtime helpers used by shape annotations.
5061

5162
Tensor shape support is enabled automatically when Pyrefly can resolve the
5263
`shape_extensions` package, so nothing else needs configuring, as long as

0 commit comments

Comments
 (0)