Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

mark some tests as broken #1545

Merged
merged 7 commits into from
Dec 30, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 2 additions & 4 deletions src/forward/lib.jl
Original file line number Diff line number Diff line change
@@ -60,10 +60,8 @@ function _pushforward(dargs, ::typeof(Core._apply), f, args...)
Core._apply(_pushforward, ((df, dargs...), f), args...)
end

if VERSION >= v"1.4.0-DEV.304"
_pushforward(dargs, ::typeof(Core._apply_iterate), ::typeof(iterate), f, args...) =
_pushforward((first(args), tail(tail(dargs))...), Core._apply, f, args...)
end
_pushforward(dargs, ::typeof(Core._apply_iterate), ::typeof(iterate), f, args...) =
_pushforward((first(args), tail(tail(dargs))...), Core._apply, f, args...)

using ..Zygote: literal_getproperty, literal_getfield, literal_getindex

16 changes: 7 additions & 9 deletions src/lib/lib.jl
Original file line number Diff line number Diff line change
@@ -198,15 +198,13 @@
end
end

if VERSION >= v"1.4.0-DEV.304"
@adjoint! function Core._apply_iterate(::typeof(iterate), f, args...)
y, back = Core._apply(_pullback, (__context__, f), args...)
st = map(_empty, args)
y, function (Δ)
Δ = back(Δ)
Δ === nothing ? nothing :
(nothing, first(Δ), unapply(st, Base.tail(Δ))...)
end
@adjoint! function Core._apply_iterate(::typeof(iterate), f, args...)

Check warning on line 201 in src/lib/lib.jl

Codecov / codecov/patch

src/lib/lib.jl#L201

Added line #L201 was not covered by tests
y, back = Core._apply(_pullback, (__context__, f), args...)
st = map(_empty, args)
y, function (Δ)
Δ = back(Δ)
Δ === nothing ? nothing :
(nothing, first(Δ), unapply(st, Base.tail(Δ))...)
end
end

10 changes: 3 additions & 7 deletions test/chainrules.jl
Original file line number Diff line number Diff line change
@@ -163,14 +163,10 @@ using Zygote: ZygoteRuleConfig

@test (1,) == h(1)

if VERSION >= v"1.6-"
@test begin
a3, pb3 = Zygote.pullback(h, 1)
((1,),) == pb3(1)
end
else

@test begin
a3, pb3 = Zygote.pullback(h, 1)
@test ((1,),) == pb3(1)
((1,),) == pb3(1)
end
end

18 changes: 12 additions & 6 deletions test/compiler.jl
Original file line number Diff line number Diff line change
@@ -33,7 +33,7 @@ y, back = pullback(badly, 2)
bt = try back(1) catch e stacktrace(catch_backtrace()) end

@test trace_contains(bt, nothing, "compiler.jl", bad_def_line)
if VERSION <= v"1.6-" || VERSION >= v"1.10-"
if VERSION >= v"1.10-"
@test trace_contains(bt, :badly, "compiler.jl", bad_call_line)
else
@test_broken trace_contains(bt, :badly, "compiler.jl", bad_call_line)
@@ -319,14 +319,17 @@ end
@test res == 12.
@test_throws ErrorException pull(1.)
err = try pull(1.) catch ex; ex end
@test occursin("Can't differentiate function execution in catch block",
string(err))
if VERSION >= v"1.11"
@test_broken occursin("Can't differentiate function execution in catch block", string(err))
else
@test occursin("Can't differentiate function execution in catch block", string(err))
end
end

if VERSION >= v"1.8"
@testset "try/catch/else" begin
@test Zygote.gradient(try_catch_else, false, 1.0) == (nothing, 8.0)
@test_throws "Can't differentiate function execution in catch block" Zygote.gradient(try_catch_else, true, 1.0)
@test_throws ErrorException Zygote.gradient(try_catch_else, true, 1.0)
end
end

@@ -348,6 +351,9 @@ end
@test_throws ErrorException pull(1.)

err = try pull(1.) catch ex; ex end
@test occursin("Can't differentiate function execution in catch block",
string(err))
if VERSION >= v"1.11"
@test_broken occursin("Can't differentiate function execution in catch block", string(err))
else
@test occursin("Can't differentiate function execution in catch block", string(err))
end
end
484 changes: 247 additions & 237 deletions test/features.jl

Large diffs are not rendered by default.

46 changes: 29 additions & 17 deletions test/gradcheck.jl
Original file line number Diff line number Diff line change
@@ -405,10 +405,8 @@ end

@testset "vararg map" begin
# early stop
if VERSION >= v"1.5"
# In Julia 1.4 and earlier, map(*,rand(5),[1,2,3]) is a DimensionMismatch
@test gradient(x -> sum(map(*,x,[1,2,3])), rand(5)) == ([1,2,3,0,0],)
end
@test gradient(x -> sum(map(*,x,[1,2,3])), rand(5)) == ([1,2,3,0,0],)
@test gradient(x -> sum(map(*,x,(1,2,3))), rand(5)) == ([1,2,3,0,0],)
@test gradient(x -> sum(map(*,x,[1,2,3])), Tuple(rand(5))) == ((1.0, 2.0, 3.0, nothing, nothing),)

@@ -1063,7 +1061,13 @@ _randmatseries(rng, ::typeof(atanh), T, n, domain::Type{Complex}) = nothing
@testset "similar eigenvalues" begin
λ[1] = λ[3] + sqrt(eps(eltype(λ))) / 10
A2 = U * Diagonal(λ) * U'
@test _gradtest_hermsym(f, ST, A2)
@static if VERSION >= v"1.11"
broken = f == sqrt && MT <: Symmetric{Float64} && domain == Real
# @show f MT domain
@test _gradtest_hermsym(f, ST, A2) broken=broken
else
@test _gradtest_hermsym(f, ST, A2)
end
end

if f (log, sqrt) # only defined for invertible matrices
@@ -1168,10 +1172,20 @@ end
return sum(sin.(vcat(vec.(_splitreim(B))...)))
end === map(_->nothing, _splitreim(A))
else
@test gradtest(_splitreim(collect(A))...) do (args...)
A = ST(_joinreim(_dropimaggrad.(args)...))
B = A^p
return vcat(vec.(_splitreim(B))...)
@static if VERSION >= v"1.11"
# @show MT p
broken = MT <: Symmetric{Float64} && p == -3
@test gradtest(_splitreim(collect(A))...) do (args...)
A = ST(_joinreim(_dropimaggrad.(args)...))
B = A^p
return vcat(vec.(_splitreim(B))...)
end broken=broken
else
@test gradtest(_splitreim(collect(A))...) do (args...)
A = ST(_joinreim(_dropimaggrad.(args)...))
B = A^p
return vcat(vec.(_splitreim(B))...)
end
end
end

@@ -1862,15 +1876,13 @@ end
@test gradient(x -> sum(randexp(Random.GLOBAL_RNG, Float32, 1,1)), 1) == (nothing,)
@test gradient(x -> sum(randexp(Random.GLOBAL_RNG, Float32, (1,1))), 1) == (nothing,)

@static if VERSION > v"1.3"
@test gradient(x -> sum(rand(Random.default_rng(), 4)), 1) == (nothing,)
@test gradient(x -> sum(rand(Random.default_rng(), Float32, 1,1)), 1) == (nothing,)
@test gradient(x -> sum(rand(Random.default_rng(), Float32, (1,1))), 1) == (nothing,)
@test gradient(x -> sum(randn(Random.default_rng(), Float32, 1,1)), 1) == (nothing,)
@test gradient(x -> sum(randn(Random.default_rng(), Float32, (1,1))), 1) == (nothing,)
@test gradient(x -> sum(randexp(Random.default_rng(), Float32, 1,1)), 1) == (nothing,)
@test gradient(x -> sum(randexp(Random.default_rng(), Float32, (1,1))), 1) == (nothing,)
end
@test gradient(x -> sum(rand(Random.default_rng(), 4)), 1) == (nothing,)
@test gradient(x -> sum(rand(Random.default_rng(), Float32, 1,1)), 1) == (nothing,)
@test gradient(x -> sum(rand(Random.default_rng(), Float32, (1,1))), 1) == (nothing,)
@test gradient(x -> sum(randn(Random.default_rng(), Float32, 1,1)), 1) == (nothing,)
@test gradient(x -> sum(randn(Random.default_rng(), Float32, (1,1))), 1) == (nothing,)
@test gradient(x -> sum(randexp(Random.default_rng(), Float32, 1,1)), 1) == (nothing,)
@test gradient(x -> sum(randexp(Random.default_rng(), Float32, (1,1))), 1) == (nothing,)
end

@testset "broadcasted($op, Array, Bool)" for op in (+,-,*)
7 changes: 4 additions & 3 deletions test/tools.jl
Original file line number Diff line number Diff line change
@@ -45,14 +45,15 @@ end

struct Tester
cpu_offload::Float64
end

function Tester(p)
function Tester(p)
# @show Zygote.isderiving(p)
cpu_offload = Zygote.isderiving(p) ? 0.0 : 0.2
Tester(cpu_offload)
new(cpu_offload)
end
end


function f56(p)
sum(Tester(p).cpu_offload .* p)
end
26 changes: 12 additions & 14 deletions test/utils.jl
Original file line number Diff line number Diff line change
@@ -12,22 +12,20 @@ using Zygote: hessian_dual, hessian_reverse
@test_throws Exception hess(identity, randn(2))
end

VERSION > v"1.6-" && @testset "diagonal hessian" begin
@testset "diagonal hessian" begin
@test diaghessian(x -> x[1]*x[2]^2, [1, pi]) == ([0, 2],)

if VERSION > v"1.6-"
# Gradient of ^ may contain log(complex(...)), which interacts badly with Dual below Julia 1.6:
# julia> log(ForwardDiff.Dual(1,0) + 0im) # ERROR: StackOverflowError:
# https://github.com/JuliaDiff/ChainRules.jl/issues/525
# Fixed in 1.6 by: https://github.com/JuliaLang/julia/pull/36030
xs, y = randn(2,3), rand()
f34(xs, y) = xs[1] * (sum(xs .^ (1:3)') + y^4) # non-diagonal Hessian, two arguments

dx, dy = diaghessian(f34, xs, y)
@test size(dx) == size(xs)
@test vec(dx) diag(hessian(x -> f34(x,y), xs))
@test dy hessian(y -> f34(xs,y), y)
end
# Gradient of ^ may contain log(complex(...)), which interacts badly with Dual below Julia 1.6:
# julia> log(ForwardDiff.Dual(1,0) + 0im) # ERROR: StackOverflowError:
# https://github.com/JuliaDiff/ChainRules.jl/issues/525
# Fixed in 1.6 by: https://github.com/JuliaLang/julia/pull/36030
xs, y = randn(2,3), rand()
f34(xs, y) = xs[1] * (sum(xs .^ (1:3)') + y^4) # non-diagonal Hessian, two arguments

dx, dy = diaghessian(f34, xs, y)
@test size(dx) == size(xs)
@test vec(dx) diag(hessian(x -> f34(x,y), xs))
@test dy hessian(y -> f34(xs,y), y)

zs = randn(7,13) # test chunk mode
@test length(zs) > ForwardDiff.DEFAULT_CHUNK_THRESHOLD