EnzymeAD / EnzymeAD/Enzyme-JAX
Default example in README does not work
- Dominant language
- MLIR
- Stars
- 131
- Forks
- 53
- Avg merge
- 1d 10h
- Merged PRs (30d)
- 193
Description
Hey all, thanks for the work on integrating enzyme with JAX.
I was trying to run the example mentioned in the readme, but this doesnt work. I'm running it with [uv](https://docs.astral.sh/uv/), via `uv run test.py`.
Here's the code:
```python
# /// script
# requires-python = "<=3.11"
# dependencies = [
# "enzyme-ad",
# "jax<0.6.0"
# ]
# ///
from enzyme_ad.jax import cpp_call
import jax
import jax.numpy as jnp
# Forward-mode C++ AD example
@jax.jit
def something(inp):
y = cpp_call(
inp,
out_shapes=[jax.core.ShapedArray([2, 3], jnp.float32)],
source="""
template
void myfn(enzyme::tensor& out0, const enzyme::tensor& in0) {
out0 = 56.0f + in0(0, 0);
}
""",
fn="myfn",
)
return y
ones = jnp.ones((2, 3), jnp.float32)
primals, tangents = jax.jvp(something, (ones,), (ones,))
# Reverse-mode C++ AD example
# primals, f_vjp = jax.vjp(something, ones)
# (grads,) = f_vjp((x,))
```
This gives me the error:
```
/enzyme_call/source.cpp:7:24: error: no matching function for call to object of type 'const enzyme::tensor'
7 | out0 = 56.0f + in0(0, 0);
| ^~~
/enzyme_call/source.cpp:11:3: note: in instantiation of function template specialization 'myfn<2UL, 3UL>' requested here
11 | myfn( out_0, in_0);
| ^
/enzyme/enzyme/tensor:140:8: note: candidate function not viable: requires single argument 'i', but 2 arguments were provided
140 | ST& operator()(size_t i) {
| ^ ~~~~~~~~
/enzyme/enzyme/tensor:144:14: note: candidate function not viable: requires single argument 'i', but 2 arguments were provided
144 | const ST& operator()(size_t i) const {
| ^ ~~~~~~~~
1 error generated.
failed execute
Traceback (most recent call last):
File "/Users/rohan/Desktop/Research_files/profile-ratio-analysis/experiments/llvm_sim/test.py", line 33, in
primals, tangents = jax.jvp(something, (ones,), (ones,))
File "/Users/rohan/Desktop/Research_files/profile-ratio-analysis/experiments/llvm_sim/test.py", line 18, in something
y = cpp_call(
File "/Users/rohan/.cache/uv/environments-v2/test-682afcde6c59793b/lib/python3.10/site-packages/enzyme_ad/jax/primitives.py", line 1145, in cpp_call
return ffi_call(
File "/Users/rohan/.cache/uv/environments-v2/test-682afcde6c59793b/lib/python3.10/site-packages/enzyme_ad/jax/primitives.py", line 1126, in ffi_call
return _enzyme_primal_p.bind(
jax._src.source_info_util.JaxStackTraceBeforeTransformation: ValueError: failed to compile C++
The preceding stack trace is the source of the JAX operation that, once transformed by JAX, triggered the following exception.
--------------------
The above exception was the direct cause of the following exception:
jax.errors.SimplifiedTraceback: For simplicity, JAX has removed its internal frames from the traceback of the following exception. Set JAX_TRACEBACK_FILTERING=off to include these.
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "/Users/rohan/Desktop/Research_files/profile-ratio-analysis/experiments/llvm_sim/test.py", line 33, in
primals, tangents = jax.jvp(something, (ones,), (ones,))
File "/Users/rohan/.cache/uv/environments-v2/test-682afcde6c59793b/lib/python3.10/site-packages/enzyme_ad/jax/primitives.py", line 943, in _enzyme_fwd_lowering
identifier, tmpBuf = enzyme_call.create_enzyme_cpu_kernel(
ValueError: failed to compile C++
```
Also, the recent JAX version doesnt seem to be supported - any plans for this?
Contributor guide
No contributing guide indexed for this repository
Assessment
This issue has not been assessed yet.