News for hackers. Stuff that matters.
Re:Decorator JITs: Python as a DSL by sega_sai on Monday February 03, 2025 @10:20AM (#42919037)
I hope this is the future for Python. Write in pure Python, but if needed, the code can be JIT (or not JIT) compiled into something faster (provided your code does not rely too much on low-level python stuff, such as __ functions).
Re:Decorator JITs: Python as a DSL by Scene_Cast2 on Monday February 03, 2025 @10:34AM (#42919195)
If this is the way forward, I'd love for a better developer experience.

I'm currently wrangling with pytorch.compile (flex attention doesn't like bias terms - see issues 145869 and 144511 if curious). As much as I love speed and optimization, JIT (at least the pytorch flavor) currently has weird return types that break VS Code's intellisense, weird stack traces, limitations around printing, and random issues like the bias term, and limitations such as not supporting sparsity.

Speaking of pytorch JIT workflows - what's a nice way of having a flag to turn off compilation?

Re:Decorator JITs: Python as a DSL by dleeftink on Monday February 03, 2025 @11:12AM (#42919681)
> random issues like the bias term

I'd like to know more about this!

Re:Decorator JITs: Python as a DSL by Scene_Cast2 on Monday February 03, 2025 @02:45PM (#42922016)
Re:Decorator JITs: Python as a DSL by singhrac on Monday February 03, 2025 @03:20PM (#42922477)
You can decorate a function with @torch.compiler.disable() to disable a specific function (and anything further down the call stack).
Re:Decorator JITs: Python as a DSL by dec0dedab0de on Monday February 03, 2025 @10:44AM (#42919314)
I would rather a JIT just built into the reference implementation. a JIT would help way more programs than removing the GIL but everyone thinks the GIL affects them for some reason.
Re:Decorator JITs: Python as a DSL by masklinn on Monday February 03, 2025 @10:54AM (#42919436)
They serve different use cases. The function JIT pattern being a manual opt in it can be much more aggressive by only supporting restricted language patterns rather than... the entire thing. They can also use bespoke annotations for better codegen e.g. you can tell numba to only codegen for i32 -> i32 -> i32, rather than lazily codegen for any a -> b -> c.
Re:Decorator JITs: Python as a DSL by O5vYtytb on Monday February 03, 2025 @10:48AM (#42919367)
Re:Decorator JITs: Python as a DSL by sevensor on Monday February 03, 2025 @12:24PM (#42920547)
The misleading thing about this approach is that the decorated function is no longer Python at all. It’s another language with Python syntax. Which is a neat way to get a parser for free, but it’s going to set up expectations about semantics that are bound to be incorrect.
Re:Decorator JITs: Python as a DSL by dragonwriter on Monday February 03, 2025 @03:48PM (#42922875)
> The misleading thing about this approach is that the decorated function is no longer Python at all. It’s another language with Python syntax.

Some of the current implementations are either strict Python subsets or very nearly so, but, yes, DSLs are distinct languages, that's what the L stands for.

Re:Decorator JITs: Python as a DSL by almostgotcaught on Monday February 03, 2025 @02:55PM (#42922134)
worse is you can't set a breakpoint inside the "jitted" function (maybe can't print either...)
Re:Decorator JITs: Python as a DSL by cl3misch on Monday February 03, 2025 @04:13PM (#42923216)
Re:Decorator JITs: Python as a DSL by almostgotcaught on Monday February 03, 2025 @04:53PM (#42923756)
> In JAX you can

I'm alway shocked when people in this line of work either take things at face-value or just lie by omission/imprecision. this is not python breakpoints - it's a wholeass other system they had to re-roll that emulates python breakpoints:

> Unlike pdb, you will not be able to step through the execution, but you are allowed to resume it.

you think it works with pycharm/vscode/any other tooling? spoiler alert: of course not.

so no in JAX you can not.

Re:Decorator JITs: Python as a DSL by ByteMe95 on Monday February 03, 2025 @09:09PM (#42926686)
You can in CSP nodes https://github.com/Point72/csp
Re:Decorator JITs: Python as a DSL by richard_shelton on Monday February 03, 2025 @04:20PM (#42923330)
It's funny how close it is to the title of my talk "Python already has a frontend for your compiler": https://github.com/true-grue/python-dsls