From 21d05c0f56fa3070ee242fd27702530028a90586 Mon Sep 17 00:00:00 2001 From: Michael Abbott <32575566+mcabbott@users.noreply.github.com> Date: Sat, 23 Nov 2024 17:39:25 -0500 Subject: [PATCH] add explicit errors for 2nd order --- src/gradient.jl | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/src/gradient.jl b/src/gradient.jl index d970251510..57b08416a0 100644 --- a/src/gradient.jl +++ b/src/gradient.jl @@ -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. + 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 @@ -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. + 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