Get the latest tech news

Decorator JITs: Python as a DSL


pend enough time looking at Python programs and packages for machine learning, and you'll notice that the "JIT decorator" pattern is pretty popular. For example, this JAX snippet: import jax.numpy as jnp import jax @jax.jit def add(a, b): return jnp.add(a, b) # Use "add" as a regular Python function ...

Instead, the code inside is more like a DSL (Domain Specific Language) processed by a special purpose compiler built into the library (JAX or Triton). On the other hand, we could have just trivially evaluated the Expr without resorting to LLVM IR; I do want to show a more complete compilation pipeline, though, to demonstrate that an arbitrary amount of complexity can be hidden behind these simple interfaces. Note that Triton lets us import names from the triton.language package and use them inside kernels; these serve as the intrinsics for the language - special calls the compiler handles directly.

Get the Android app

Or read this on Hacker News

Read more on:

Photo of DSL

DSL

Photo of python

python

Photo of decorator jits

decorator jits

Related news:

News photo

Python 3, Pygame, and Debian Bookworm on the Miyoo A30

News photo

Show HN: Reactive Signals for Python – inspired by Angular's reactivity model

News photo

"We're building a new static type checker for Python"