Skip to content

Commit d53d943

Browse files
committed
feat: error hints for Enzyme
1 parent 744dce4 commit d53d943

4 files changed

Lines changed: 58 additions & 4 deletions

File tree

DifferentiationInterface/CHANGELOG.md

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,20 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
77

88
## [Unreleased]
99

10-
### Changed
10+
## [0.6.54] - 2025-05-07
1111

12-
- Allocate Enzyme shadow memory during preparation ([#782])
12+
### Added
13+
14+
- Error hints for Enzyme ([#788])
1315

1416
## [0.6.53] - 2025-05-07
1517

18+
### Changed
19+
20+
- Allocate Enzyme shadow memory during preparation ([#782])
21+
1622
[unreleased]: https://github.com/JuliaDiff/DifferentiationInterface.jl/compare/DifferentiationInterface-v0.6.53...main
1723
[0.6.53]: https://github.com/JuliaDiff/DifferentiationInterface.jl/compare/DifferentiationInterface-v0.6.52...DifferentiationInterface-v0.6.53
1824

25+
[#788]: https://github.com/JuliaDiff/DifferentiationInterface.jl/pull/788
1926
[#782]: https://github.com/JuliaDiff/DifferentiationInterface.jl/pull/782

DifferentiationInterface/Project.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
name = "DifferentiationInterface"
22
uuid = "a0c0ee7d-e4b9-4e03-894e-1c5f64a51d63"
33
authors = ["Guillaume Dalle", "Adrian Hill"]
4-
version = "0.6.53"
4+
version = "0.6.54"
55

66
[deps]
77
ADTypes = "47edcb42-4c32-4615-8424-f2b9edc5f35b"
@@ -56,7 +56,7 @@ ADTypes = "1.13.0"
5656
ChainRulesCore = "1.23.0"
5757
DiffResults = "1.1.0"
5858
Diffractor = "=0.2.6"
59-
Enzyme = "0.13.17"
59+
Enzyme = "0.13.39"
6060
EnzymeCore = "0.8.8"
6161
ExplicitImports = "1.10.1"
6262
FastDifferentiation = "0.4.3"

DifferentiationInterface/ext/DifferentiationInterfaceEnzymeExt/DifferentiationInterfaceEnzymeExt.jl

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ using EnzymeCore:
3030
Split,
3131
WithPrimal
3232
using Enzyme:
33+
Enzyme,
3334
autodiff,
3435
autodiff_thunk,
3536
create_shadows,
@@ -53,4 +54,6 @@ include("forward_twoarg.jl")
5354
include("reverse_onearg.jl")
5455
include("reverse_twoarg.jl")
5556

57+
include("init.jl")
58+
5659
end # module
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
function __init__()
2+
# robust against internal changes
3+
condition = (
4+
isdefined(Enzyme, :Compiler) &&
5+
Enzyme.Compiler isa Module &&
6+
isdefined(Enzyme.Compiler, :EnzymeError) &&
7+
Enzyme.Compiler.EnzymeError isa DataType
8+
)
9+
condition || return nothing
10+
# see https://github.com/JuliaLang/julia/issues/58367 for why this isn't easier
11+
for n in names(Enzyme.Compiler; all=true)
12+
T = getfield(Enzyme.Compiler, n)
13+
if T isa DataType && T <: Enzyme.Compiler.EnzymeError
14+
# robust against internal changes
15+
Base.Experimental.register_error_hint(T) do io, exc
16+
if occursin("EnzymeMutabilityException", string(nameof(T)))
17+
printstyled(
18+
io,
19+
"\nIf you are using Enzyme through DifferentiationInterface, you may want to try modifying the ADTypes backend object as follows:";
20+
bold=true,
21+
)
22+
printstyled(
23+
io,
24+
"\n\n\tAutoEnzyme(; function_annotation=Enzyme.Duplicated)\n\n";
25+
color=:cyan,
26+
bold=true,
27+
)
28+
elseif occursin("EnzymeRuntimeActivityError", string(nameof(T)))
29+
printstyled(
30+
io,
31+
"\nIf you are using Enzyme through DifferentiationInterface, you may want to try modifying the ADTypes backend object as follows:";
32+
bold=true,
33+
)
34+
printstyled(
35+
io,
36+
"\n\n\tAutoEnzyme(; mode=Enzyme.set_runtime_activity(Enzyme.Forward))\n\tAutoEnzyme(; mode=Enzyme.set_runtime_activity(Enzyme.Reverse))\n\n";
37+
color=:cyan,
38+
bold=true,
39+
)
40+
end
41+
end
42+
end
43+
end
44+
end

0 commit comments

Comments
 (0)