Replies: 5 comments 6 replies
-
cc @crusaderky |
Beta Was this translation helpful? Give feedback.
-
I cannot even compile a function because of E torch.jit.frontend.NotSupportedError: Compiled functions can't take variable number of arguments or use keyword-only arguments with defaults:
E File ".venv/lib/python3.13/site-packages/array_api_compat/common/_helpers.py", line 489
E def array_namespace(
E *xs: Array | complex | None,
E ~~~ <--- HERE
E api_version: str | None = None,
E use_compat: bool | None = None, If I manually assign EDIT: torch.compile worked! |
Beta Was this translation helpful? Give feedback.
-
Don't. There is enough nuance in the keywords needed by each jit function that it's territory I really would not want to venture in. A package that supports multiple Array API compatible libraries
For example, jax.jit is a net loss in terms of performance if you're only going to call each function once, change the shape of your array, and do it again. JAX does offer a way to move away from Another point: I am not overly familiar with torch.compile, but I expect the same amount of different nuance for it. You can read an informative discussion here: #284 |
Beta Was this translation helpful? Give feedback.
-
That's not how
|
Beta Was this translation helpful? Give feedback.
-
Numba
Attempt 1import numba
import numpy as np
from array_api_compat import array_namespace
@numba.njit
def sinplus1(x):
xp = array_namespace(x)
return xp.sin(x) + 1
print(sinplus1(np.arange(10)))
Attempt 2import numba
import numpy as np
from array_api_compat import array_namespace
from numba.extending import overload
@overload(array_namespace)
def array_namespace_overload(*args):
def inner(*args):
return np
return inner
@numba.njit
def sinplus1(x):
xp = array_namespace(x)
return xp.sin(x) + 1
print(sinplus1(np.arange(10))) [1. 1.84147098 1.90929743 1.14112001 0.2431975 0.04107573
0.7205845 1.6569866 1.98935825 1.41211849] Attempt 3(Add
Attempt 4(Add
|
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
I am not sure how to define a JIT decorator which support multiple libraries. Maybe like this?
Beta Was this translation helpful? Give feedback.
All reactions