From d13e52abdf57b69ef7b713d3348d72aa181bc13c Mon Sep 17 00:00:00 2001 From: Michael Abbott <32575566+mcabbott@users.noreply.github.com> Date: Wed, 12 Oct 2022 18:24:06 -0400 Subject: [PATCH] fix doctests --- src/Optimisers.jl | 10 +++++----- src/adjust.jl | 6 +++--- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/src/Optimisers.jl b/src/Optimisers.jl index 73c56305..8e8cb19f 100644 --- a/src/Optimisers.jl +++ b/src/Optimisers.jl @@ -77,7 +77,7 @@ or [`update!`](@ref). julia> m = (x = rand(3), y = (true, false), z = tanh); julia> Optimisers.setup(Momentum(), m) # same field names as m -(x = Leaf(Momentum{Float32}(0.01, 0.9), [0.0, 0.0, 0.0]), y = (nothing, nothing), z = nothing) +(x = Leaf(Momentum{Float32}(0.01, 0.9), [0.0, 0.0, 0.0]), y = ((), ()), z = ()) ``` The recursion into structures uses Functors.jl, and any new `struct`s containing parameters @@ -90,7 +90,7 @@ julia> struct Layer; mat; fun; end julia> model = (lay = Layer([1 2; 3 4f0], sin), vec = [5, 6f0]); julia> Optimisers.setup(Momentum(), model) # new struct is by default ignored -(lay = nothing, vec = Leaf(Momentum{Float32}(0.01, 0.9), Float32[0.0, 0.0])) +(lay = (), vec = Leaf(Momentum{Float32}(0.01, 0.9), Float32[0.0, 0.0])) julia> destructure(model) (Float32[5.0, 6.0], Restructure(NamedTuple, ..., 2)) @@ -98,7 +98,7 @@ julia> destructure(model) julia> using Functors; @functor Layer # annotate this type as containing parameters julia> Optimisers.setup(Momentum(), model) -(lay = (mat = Leaf(Momentum{Float32}(0.01, 0.9), Float32[0.0 0.0; 0.0 0.0]), fun = nothing), vec = Leaf(Momentum{Float32}(0.01, 0.9), Float32[0.0, 0.0])) +(lay = (mat = Leaf(Momentum{Float32}(0.01, 0.9), Float32[0.0 0.0; 0.0 0.0]), fun = ()), vec = Leaf(Momentum{Float32}(0.01, 0.9), Float32[0.0, 0.0])) julia> destructure(model) (Float32[1.0, 3.0, 2.0, 4.0, 5.0, 6.0], Restructure(NamedTuple, ..., 6)) @@ -120,12 +120,12 @@ See also [`update!`](@ref), which will be faster for models of ordinary `Array`s julia> m = (x = Float32[1,2,3], y = tanh); julia> t = Optimisers.setup(Descent(0.1f0), m) -(x = Leaf(Descent{Float32}(0.1), nothing), y = nothing) +(x = Leaf(Descent{Float32}(0.1), nothing), y = ()) julia> g = (x = [1,1,1], y = nothing); # fake gradient julia> Optimisers.update(t, m, g) -((x = Leaf(Descent{Float32}(0.1), nothing), y = nothing), (x = Float32[0.9, 1.9, 2.9], y = tanh)) +((x = Leaf(Descent{Float32}(0.1), nothing), y = ()), (x = Float32[0.9, 1.9, 2.9], y = tanh)) ``` """ update diff --git a/src/adjust.jl b/src/adjust.jl index d6f3647d..78b3d452 100644 --- a/src/adjust.jl +++ b/src/adjust.jl @@ -13,15 +13,15 @@ To change just the learning rate, provide a number `η::Real`. julia> m = (vec = rand(Float32, 2), fun = sin); julia> st = Optimisers.setup(Nesterov(), m) # stored momentum is initialised to zero -(vec = Leaf(Nesterov{Float32}(0.001, 0.9), Float32[0.0, 0.0]), fun = nothing) +(vec = Leaf(Nesterov{Float32}(0.001, 0.9), Float32[0.0, 0.0]), fun = ()) julia> st, m = Optimisers.update(st, m, (vec = [16, 88], fun = nothing)); # with fake gradient julia> st -(vec = Leaf(Nesterov{Float32}(0.001, 0.9), Float32[-0.016, -0.088]), fun = nothing) +(vec = Leaf(Nesterov{Float32}(0.001, 0.9), Float32[-0.016, -0.088]), fun = ()) julia> st = Optimisers.adjust(st, 0.123) # change learning rate, stored momentum untouched -(vec = Leaf(Nesterov{Float32}(0.123, 0.9), Float32[-0.016, -0.088]), fun = nothing) +(vec = Leaf(Nesterov{Float32}(0.123, 0.9), Float32[-0.016, -0.088]), fun = ()) ``` To change other parameters, `adjust` also accepts keyword arguments matching the field