-
-
Notifications
You must be signed in to change notification settings - Fork 612
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
deprecate Flux.params #2413
Comments
I think we were waiting for a couple more features to land so we could have parity with some of the remaining use cases people might use implicit params for. FluxML/Optimisers.jl#57 is the main one I can think of. |
I think that's the only one left |
Would there be an alternative way to perform Along these lines, I also wanted to ask if |
That already exists, roughly: julia> model = Chain(Dense(2 => 1, tanh), Dense(1 => 1));
julia> st = Flux.state(model)
(layers = ((weight = Float32[0.5213037 0.35699493], bias = Float32[0.0], σ = ()), (weight = Float32[0.96851003;;], bias = Float32[0.0], σ = ())),)
julia> Flux.loadmodel!(model, st); # this is a nested copyto!
julia> using ComponentArrays
julia> ca = ComponentArray(; Flux.state(model)...)
ComponentVector{Tuple{@NamedTuple{weight::Matrix{Float32}, bias::Vector{Float32}, σ::Tuple{}}, @NamedTuple{weight::Matrix{Float32}, bias::Vector{Float32}, σ::Tuple{}}}}(layers = ((weight = Float32[0.5213037 0.35699493], bias = Float32[0.0], σ = ()), (weight = Float32[0.96851003;;], bias = Float32[0.0], σ = ())))
julia> ca.layers[1].weight .= NaN
1×2 Matrix{Float32}:
NaN NaN
julia> Flux.loadmodel!(model, ca)
Chain(
Dense(2 => 1, tanh), # 3 parameters (some NaN)
Dense(1 => 1), # 2 parameters
) # Total: 4 arrays, 5 parameters, 276 bytes. The caveats are (1) what Flux.state returns includes non-trainable parameters, (2) I've no idea what'll happen to shared parameters, ComponentArrays ignores them, and (3) this is designed for loading from disk not for use within gradients, so Zygote may hate it, but that's fixable. (Edit, (4) my use of ComponentArray does not seem to produce something backed by one big vector, e.g.
Possibly OT here. But perhaps worth opening an issue... perhaps with an example of what you wish would work? |
Hi Michael, thanks a lot for the detailed reply (and sorry for the delay in my reply), I wasn't aware of Now, if I understand correctly, I have to write my own And with regards to And with regards to So for now I can write a |
Hi @kishore-nori, could you open a new issue and provide a specific example that we can reason on? Your case seems to be well served by |
Sure will come up with a MWE and open an issue, thank you. By the way, I have realized that that idea of |
Is there any reason why we keep it around?
For the need of having a vector or iterable over trainable leaves we can build something (
trainables(model)
?) on top of Functors.fleaves so that we have a function decoupled fromZygote
.The text was updated successfully, but these errors were encountered: