JIT often recompiles bound methods
See original GitHub issueI’m going close this issue. I just want to save a record of it in case I come up with a reasonable solution one day.
If a method is always jitted, then Jax compiles it once:
from jax import jit
from functools import partial
class X:
@partial(jit, static_argnums=(0,))
def f(self):
print("Recompiling")
x = X()
for i in range(3):
x.f()
However, if the caller wants to jit the method, then Jax compiles it every time:
from jax import jit
class X:
def f(self):
print("Recompiling")
x = X()
for i in range(3):
jit(x.f)()
It would be nice if jit
detected the case when the function f
is a bound method (use inspect.ismethod(f)
), and maybe emit a warning.
If you wanted to fix it automatically, you could use replace the function with function.__func__
, and add a positional argument function.__self__
. The issue with this is whether that argument should be static or not is impossible to know. That’s why the warning makes sense: it forces the caller to explicitly choose whether the argument is static or dynamic.
Issue Analytics
- State:
- Created 2 years ago
- Comments:13 (12 by maintainers)
Top Results From Across the Web
Just-in-time compilation - Wikipedia
JIT compilation is a combination of the two traditional approaches to translation to machine code—ahead-of-time compilation (AOT), and interpretation—and ...
Read more >Just-in-Time compilation — Numba 0.50.1 documentation
JIT functions. Compile the decorated function on-the-fly to produce efficient machine code. All parameters are optional. If present, the signature is either a ......
Read more >JIT Compilers for Ruby and Rails: An Overview - AppSignal Blog
JIT compilation is a type of dynamic compilation that enables adaptive optimization techniques, including dynamic recompilation and ...
Read more >Chapter 4. Working with the JIT Compiler - O'Reilly
If a method runs often enough, it will get compiled at level 4 (and the level 3 code will be made not entrant)....
Read more >What is Just-In-Time(JIT) Compiler in .NET - GeeksforGeeks
The cache memory is heavily used by the JIT compiler to store the source code methods that are required at run-time. Note: Much...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Just me! 😄
FYI, there is now a section in the FAQ addressing jit compilation of methods: https://jax.readthedocs.io/en/latest/faq.html#how-to-use-jit-with-methods