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

How to do implicit differentiation for neural network parameters? #23

Closed
JinraeKim opened this issue Nov 19, 2022 · 4 comments
Closed

Comments

@JinraeKim
Copy link

JinraeKim commented Nov 19, 2022

Hi!

I'm trying to do implicit differentiation of the parameters for a given neural network.

For example, nn is a neural network constructed by Flux.jl. I can get the parameters by Flux.params(nn).

In this tutorial, I need to provide the parameters as the arguments of the forward solver function (here, it's lasso(data::ComponentArray)).

But I don't know how to do this for my case; namely, optimization_prob(parameters) = ...?

If I can overwrite network parameters with p = Flux.params(nn), then I would be able to do so like

function optimization_prob(parameters)  # will be provided by `Flux.params(nn)` outside this function
    load_parameters!(nn, parameters)
    # etc...
end

Is there any workaround for this?

@mohamed82008
Copy link
Collaborator

Once you create the implicit function, you can nest it with other functions. I don't understand what you are trying to do if it's not a simple nesting of 2 functions. Just make sure your second function you are nesting with the implicit function is Zygote compatible on its own first.

@gdalle gdalle added the invalid label Mar 10, 2023
@mohamed82008
Copy link
Collaborator

@JinraeKim can you please post a complete example here?

@JinraeKim
Copy link
Author

@mohamed82008
I was trying to do something like this before but I didn't complete it yet as I got busy and it's related to my side project :>

I may begin my side project this year, so if I figure it out or struggle with this, will post a comment!

@JinraeKim
Copy link
Author

My workaround for this is to define the last layer of a neural network of interest (related to solving an optimization problem) by this package and put the intermediate values of the neural network to be the optimization parameters of the last layer, see #67

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants