Back to browse
GitHub Repository

let types trickle from runtime to compile time

12 starsTypeScript

Trickle – See PyTorch tensor shapes inline in VSCode as you code

by chaiyihein·Mar 18, 2026·7 points·1 comment

AI Analysis

●●●BangerWizardrySolve My ProblemZero to One

AST rewriting for runtime types without code changes — why didn't this exist before.

Strengths
  • Error snapshots show exact variable state at crash time for debugging.
  • Zero code changes required — just run through trickle run python.
  • Tensor shape annotations flow inline like type hints for PyTorch models.
Weaknesses
  • AST rewriting approach may have performance overhead on large codebases.
  • VSCode extension dependency limits adoption to one editor.
Target Audience

ML engineers, PyTorch developers

Similar To

Pyright · mypy · pdb

Post Description

As a beginner learning to build ML models, I found it annoying to have to keep printing tensor shapes every other line, having to step through the debugger to check where did I mess up the shapes again.

So I built Trickle, it takes the data that flows through your code, caches the types and display them inline (as if you have type annotations).

The idea is: "Let types trickle from runtime into your IDE". You get types in Python without having the write them manually.

It works by rewriting your Python AST at import time — after every variable assignment, it inserts a lightweight call that records the type and value. No decorators, no code changes. Just run your script through trickle run python train.py and every variable gets its type visible.

One cool feature is Error snapshots, by toggling it in VSCode status bar, you can see the exact data that is in each variable when the error happened.

For AI agents, trickle-cli outputs the inline runtime types together with the source code so agent can better diagnose the issue.

For Jupyter notebooks: %load_ext trickle as your first cell, and every cell after is traced.

Quick try: pip install trickle-observe npm install -g trickle-cli code --install-extension yiheinchai.trickle-vscode

trickle run python demo/demo.py trickle hints demo/demo.py

Limitations: - Expect 2-5x slowdown — designed for development, not production.

Also supports JavaScript/TypeScript (Express, Fastify, Koa, Hono) though the Python/ML side is where I've focused most effort.

In the future, I imagine there to be potential for using this as runtime observability in production via probabilistic sampling of types. Now, we know the code, we know the data, which is all the information we need to debug.

Happy to answer questions

Similar Projects

AI/ML●●Solid

PyTorch on Java

LibTorch bindings bring CUDA and MPS backends to Java with LLaMA-3 inference included.

Niche GemBig Brain
pdsminer
202d ago
AI/ML●●Solid

Macrograd – Micrograd, but with Tensors

Takes micrograd's toy autodiff idea and scales it to real tensor operations with NumPy and optional CuPy GPU support. The repo exposes an nn-like module, common activations (ReLU/Softmax), self-attention and an MNIST MLP example, so it's excellent as a learning resource. It's explicitly flagged as WIP — expect performance and OOM rough edges, so treat it as a study tool rather than a training backbone.

Niche GemShip It
polyrhachis
104mo ago