LabscoMCP early access ↗
Athe-kunalMCP SERVER

PyTorch-FX Shaper

Get the real tensor shape at every step of a PyTorch module, then rewrite the maths as einsum with the rewrite checked before you keep it.

by Athe-kunal ↗Code Generation, Scaffolding & MigrationCommunity

LABSCO SUMMARY

Shapes read off a real trace, then the rewrite checked.

Reading a transformer's forward pass usually means holding shapes in your head. This puts the measured shape on every line, and when your assistant rewrites matmuls and attention as einsum, the server checks the result against the original before you take it.

What it is

A shape-extraction and rewrite pipeline for PyTorch, exposed over MCP. It runs torch.export and ShapeProp across your nn.Module to capture the shape of every intermediate tensor, then returns your source annotated with those shapes and checks any einsum rewrite against the original.

What you get

  • Per-module tensor shapes for every intermediate in the forward pass, not just the inputs
  • Your source files back with those shapes inserted as inline comments on the lines they belong to
  • Shape-annotated snippets for each class and function, which your assistant reads before it rewrites the code with einsum or einops
  • Symbolic dimension names on request — pass a dim_names mapping and a shape reads (B, T) instead of (4, 16)
  • A rewrite validated before you accept it — whole file, single module or single function

Requirements

The repository checked out locally with PyTorch, and a module that torch.export can trace — the shapes come from a real forward pass, not from static analysis. The server rewrites nothing itself: your assistant writes the einsum version and the server confirms it produces identical outputs. The library's separate comment and einsum modes call an LLM of their own and are not part of the MCP server.

Setup effort

Build from source — get the source, then follow the steps on this page and add the configuration for your client