Skip to content

Commit

Permalink
add explicit errors for 2nd order
Browse files Browse the repository at this point in the history
  • Loading branch information
mcabbott committed Nov 23, 2024
1 parent 349dc99 commit 21d05c0
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions src/gradient.jl
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,12 @@ function gradient(f, args...; zero::Bool=true)
for a in args
_ensure_noenzyme(a)
end
if Zygote.isderiving()
error("""`Flux.gradient` does not support use within a Zygote gradient.

Check warning on line 39 in src/gradient.jl

View check run for this annotation

Codecov / codecov/patch

src/gradient.jl#L39

Added line #L39 was not covered by tests
If what you are doing worked on Flux < 0.14, then calling `Zygote.gradiet` directly should still work.
If you are writing new code, then Zygote over Zygote is heavily discouraged.
""")
end
Zygote.gradient(f, args...)
end

Expand Down Expand Up @@ -167,6 +173,12 @@ function withgradient(f, args...; zero::Bool=true)
for a in args
_ensure_noenzyme(a)
end
if Zygote.isderiving()
error("""`Flux.withgradient` does not support use within a Zygote gradient.

Check warning on line 177 in src/gradient.jl

View check run for this annotation

Codecov / codecov/patch

src/gradient.jl#L177

Added line #L177 was not covered by tests
If what you are doing worked on Flux < 0.14, then calling `Zygote.gradiet` directly should still work.
If you are writing new code, then Zygote over Zygote is heavily discouraged.
""")
end
Zygote.withgradient(f, args...)
end

Expand Down

0 comments on commit 21d05c0

Please sign in to comment.