ChainRulesTestUtils crashes with a custom regularization function on a Flux Dense layer
Nadie ha tomado este issue todavía.
Evaluación
- Dificultad
- 4/5
- Tiempo estimado
- 3-5 días
- Aptitud para principiantes
- 42/100
Línea de trabajo
Comienza ejecutando el reproductor de Julia proporcionado y las dos llamadas a test_rrule; después, inspecciona cómo test_rrule maneja los valores Tangent para objetos Dense y Chain. Se considera terminado cuando ambas reglas de regularización personalizadas se prueban sin los errores zero(::typeof(tanh)) ni de tipo de retorno inferido.
Escrito por el modelo de indexación a partir del texto del issue.
Descripción
I have been trying to write a custom reverse rule to a simple regularization function on a Flux Dense layer, and evaluate it with ChainRulesTestUtils. The function gradient from Zygote seems to work fine with the rules, but ChainRulesTestUtils crashes. The following code is executed just fine until the test_rrule calls. The first test_rrule tries to check whether the one-layer regularization function works, but instead it raises an error
Got exception outside of a @test
MethodError: no method matching zero(::typeof(tanh))
The second test_rrule crashes with
Got exception outside of a @test
return type Tuple{NoTangent, Tangent{Chain{Tuple{Dense{typeof(tanh), Matrix{Float64}, Vector{Float64}}, Dense{typeof(tanh), Matrix{Float64}, Vector{Float64}}}}, NamedTuple{(:layers,), Tuple{Tuple{NamedTuple{(:weight, :bias, :σ), Tuple{Matrix{Float64}, ZeroTangent, NoTangent}}, NamedTuple{(:weight, :bias, :σ), Tuple{Matrix{Float64}, ZeroTangent, NoTangent}}}}}}} does not match inferred return type Tuple{NoTangent, Tangent{Chain{Tuple{Dense{typeof(tanh), Matrix{Float64}, Vector{Float64}}, Dense{typeof(tanh), Matrix{Float64}, Vector{Float64}}}}}}
Any idea what could be the issue here? A bug somewhere?
using ChainRulesCore
using Flux
using Random
using ChainRulesTestUtils
Flux.trainable(nn::Dense) = (nn.weight, nn.bias,)
function weightregularization(nn::Dense)
return sum((nn.weight).^2.0)
end
function ChainRulesCore.rrule(::typeof(weightregularization), nn::Dense)
y = weightregularization(nn)
project_w = ProjectTo(nn.weight)
function weightregularization_pullback(ȳ)
pullb = Tangent{Dense}(weight=project_w(ȳ * 2.0*nn.weight), bias=ZeroTangent(), σ= NoTangent())
return NoTangent(), pullb
end
return y, weightregularization_pullback
end
function totalregularization(ch::Chain{T}) where T<:Tuple{Vararg{Dense}}
a = 0.0
for i in ch
a = a + sum(i.weight.^2.0)
end
return a
end
function ChainRulesCore.rrule(::typeof(totalregularization), ch::Chain{T}) where T<:Tuple{Vararg{Dense}}
y = totalregularization(ch)
function totalregularization_pullback(ȳ)
totalpullback = []
N = length(ch)
for i = 1:N
project_w = ProjectTo(ch[i].weight)
push!(totalpullback, (weight= project_w(ȳ * 2.0*ch[i].weight), bias = ZeroTangent(), σ= NoTangent()))
end
pullb = Tangent{Chain{T}}(layers=Tuple(totalpullback))
return NoTangent(), pullb
end
return y, totalregularization_pullback
end
nn = Dense(randn(1,2), randn(1), tanh)
gr1 = gradient(weightregularization,nn)
l1 = Dense(randn(2,2), randn(2), tanh)
l2 = Dense(randn(1,2), randn(1), tanh)
ch = Chain(l1,l2)
gr2 = gradient(totalregularization,ch)
test_rrule(weightregularization,nn)
test_rrule(totalregularization,ch)
- Lenguaje dominante
- Julia
- Estrellas
- 50
- Forks
- 18
- Merge medio
- 1 h 54 min
- PR fusionados (30 d)
- 1
Preparar el entorno
Este proyecto no incluye contenedor de desarrollo, Dockerfile ni guía de contribución, así que la configuración corre por tu cuenta: empieza por su README y consulta nuestra guía para la primera contribución para los pasos generales.
Primeros pasos
- Lee el issue completo y luego la guía de contribución del proyecto.
- Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
- Haz un fork del repositorio y trabaja en una rama.
- Abre un pull request que haga referencia al número del issue.
Más de JuliaDiff/ChainRulesTestUtils.jl
-
code snippet in readmeAbierto
Dificultad 2/5 1-3 horas Aptitud para principiantes 65/100
JuliaDiff/ChainRulesTestUtils.jl#148 · 1 reacción ·
-
use DocThemeIndigoAbiertodocumentation good first issue
Dificultad 2/5 1-3 horas Aptitud para principiantes 62/100
-
Dificultad 3/5 1-2 días Aptitud para principiantes 45/100
-
more `test_approx` ambiguitiesAbierto
Dificultad 2/5 1-3 horas Aptitud para principiantes 45/100
-
mutation
Dificultad 3/5 1-2 días Aptitud para principiantes 45/100
Todos los issues de JuliaDiff/ChainRulesTestUtils.jl
Issues similares
-
io
Dificultad 2/5 1-3 horas Aptitud para principiantes 78/100
Los mantenedores suelen responder en 1 día
-
Dificultad 1/5 Menos de una hora Aptitud para principiantes 72/100
-
docs
Dificultad 1/5 Menos de una hora Aptitud para principiantes 90/100
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 72/100
JuliaGPU/GPUArrays.jl#837 ·
Los mantenedores suelen responder en 1 día
-
Dificultad 1/5 Menos de una hora Aptitud para principiantes 88/100
Los mantenedores suelen responder en 1 día