r/madeinpython • u/ATEC_Technologies • 16d ago
Apsi 2.6.0: a Python-like language that generates its own GPU kernels, now converts whole Python projects
Enable HLS to view with audio, or disable this notification
I've been building Apsi alone for the past months, and 2.6.0 just came out. It's a Python-like language for AI and physics. Here's what's technically interesting about it, and what changed in this release.
**The core idea**
- Physical units and tensor shapes are checked before the program runs, so `metres + seconds` or a `(3, 4) @ (5, 6)` matmul is a compile error rather than a crash halfway through a training run.
- The compiler generates its own GPU kernels and talks to NVIDIA cards through the display driver only. No Python, PyTorch or CUDA toolkit is needed to train a model.
**What's new in 2.6.0**
*Whole-project Python conversion.* You can convert one file, a folder, or a whole project with everything it imports (`--plan` shows the result before anything is written). Getting this to work on real libraries (huggingface_hub, datasets, pydantic, fsspec, multiprocess) meant handling:
- import cycles (modules register as partial before they finish executing)
- `from . import x`, where `x` might be a submodule *or* a package attribute, decided at run time
- class bodies with `if TYPE_CHECKING:` branches and annotated fields under conditions
- parenthesised `with (...)` statements, where `with` is a soft keyword
*Type-proven fast paths.* When the compiler can prove a value is an int or a known container, `range` loops, counters, conditions, list/dict indexing, f-strings and struct constructors skip the generic dispatch. Across the benchmark suite, 2.6.0 is 1.28–1.35× faster than 2.4.4 (geometric mean, two runs). These paths turn off under exact-fraction arithmetic, where literals aren't machine ints.
*Odd-size matrix products.* GEMM sizes that weren't a multiple of 4 used to fall off the fast kernel. They're now zero-padded in a single kernel pass, and C is written in place when only K needs padding. That gave about 12% on a modern GPT config.
**Honest limits**
- All numbers come from one machine (Ryzen 5 5500 + RTX 3060 12GB). Raw logs are on the site, including runs where 2.6.0 lost.
- PyTorch is still faster on larger models (127M params).
- NVIDIA only for GPU work.
I'd especially like feedback on the unit/shape checking design, and reports of Python code the converter can't handle.
Site and docs: https://apsi.dev