EnzymeInternalError differentiating DynamicExpressions ParametricExpression eval_tree_array
This came up while testing `SymbolicRegression.jl` `ParametricExpression` support with Enzyme. I was able to reduce it to a direct `DynamicExpressions.jl` + `Enzyme.jl` reproducer below.
Full verbose log and the standalone script are in this gist:
https://gist.github.com/MilesCranmerBot/ab94e22b108efbcd83eb0f6e63c453d2
## Reproducer
```julia
using DynamicExpressions
using Enzyme
using Random: MersenneTwister
Enzyme.Compiler.VERBOSE_ERRORS[] = true
rng = MersenneTwister(0)
X = rand(rng, 2, 32)
class = rand(rng, 1:2, 32)
operators = OperatorEnum(; unary_operators=[cos], binary_operators=[+, *, -])
ex = @parse_expression(
x * x - cos(2.5 * y + -0.5) + p1,
operators=operators,
expression_type=ParametricExpression,
variable_names=["x", "y"],
extra_metadata=(parameter_names=["p1"], parameters=[0.1 0.2]),
)
function f(ex, X, class, operators, output)
pred, ok = eval_tree_array(ex, X, class, operators)
output[] = ok ? sum(abs2, pred) : Inf
return nothing
end
dex = Enzyme.make_zero(ex)
dX = zero(X)
output = [0.0]
doutput = [1.0]
Enzyme.autodiff(
Reverse,
f,
Duplicated(ex, dex),
Duplicated(X, dX),
Const(class),
Const(operators),
Duplicated(output, doutput),
)
```
## Error
This fails with:
```text
ERROR: LoadError: EnzymeInternalError: Enzyme compilation failed due to an internal error.
Please open an issue with the code to reproduce and full error log on github.com/EnzymeAD/Enzyme.jl
To toggle more information for debugging (needed for bug reports), set Enzyme.Compiler.VERBOSE_ERRORS[] = true (default false)
...
Illegal address space propagation
+ rep: %2 = alloca ptr addrspace(10), i64 1, align 8, !enzymejl_allocart !74, !enzyme_type !75, !enzymejl_allocart_name !77
+ prev: %3 = addrspacecast ptr %2 to ptr addrspace(10), !enzyme_backstack !0
+ inst: %root_phi.in = phi ptr addrspace(10) [ %9, %L90 ], [ %7, %L88 ], [ %3, %L82 ], !dbg !182
Stacktrace:
[1] macro expansion
@ ~/.julia/packages/DynamicExpressions/ERjoe/src/Evaluate.jl:550
[2] dispatch_deg1_l2_ll0_lr0_eval
@ ~/.julia/packages/DynamicExpressions/ERjoe/src/Evaluate.jl:534
[3] macro expansion
@ ~/.julia/packages/DynamicExpressions/ERjoe/src/Evaluate.jl:512
[4] dispatch_deg1_eval
@ ~/.julia/packages/DynamicExpressions/ERjoe/src/Evaluate.jl:481
```
## Environment
```text
Julia Version 1.12.5
OS: Linux (x86_64-linux-gnu)
CPU: 12 x AMD EPYC-Genoa Processor
LLVM: libLLVM-18.1.7 (ORCJIT, znver4)
Threads: 12 default, 1 interactive, 12 GC
Enzyme 0.13.150
DynamicExpressions 2.5.2
```
I originally hit the same internal error via `SymbolicRegression.jl` `v2.0.0-alpha.11` / commit `482530b64cfd9b96cb1b6162de0ad5b763e8e6b0`, with the stack passing through `SymbolicRegression/src/ParametricExpression.jl:93` into `DynamicExpressions.Evaluate.jl:550`.
5 条评论