Git Product home page Git Product logo

Comments (6)

CarloLucibello avatar CarloLucibello commented on June 14, 2024 2

I'm not sure what we should add to the documentation.
Not an expert on that, but in multi-objective optimization in principle you want to obtain a whole pareto frontier.
I wouldn't mention the term "multi-objective" anywhere in the documentation.
We could stress in more places that withgradient can return additional outputs if we think it deserves more prominence.

from flux.jl.

jacob-m-wilson-42 avatar jacob-m-wilson-42 commented on June 14, 2024

There currently isn't any mention of how to look at multiple outputs using withgradient in the current Flux docs. We don't have to stress multi-objective optimization, but I think there definitely needs to be documentation in there for how to track multiple losses using withgradient. Currently, you have to take a look at Zygote, which I couldn't find until @mcabbot pointed it out for me.

from flux.jl.

ToucheSir avatar ToucheSir commented on June 14, 2024

I guess where I'm confused is why this feature request is about multi-objective losses? Mostly because this:

loss, grads = withgradient(model) do m
  a = loss_a(m, x)
  b = loss_b(m, x)
  c = a + b
  return c
end

Is still training with a "multi-objective loss" from my perspective. What the recent withgradient change unlocked is the ability to return auxiliary state which will not have gradients backpropped through them. It just so happens that the example in the issue uses this mechanism to sneak out the individual losses for subsequent code, but it would be equally valid to use it for e.g. embeddings or non-differentiable metrics. Therefore, is this request more about documenting how to use auxiliary state with withgradient and Flux models with examples, or is it about showing how to optimize a model with multiple joint losses (and how similar that would be to what you'd do with other libraries, just return loss1 + loss2 + ...)?

from flux.jl.

mcabbott avatar mcabbott commented on June 14, 2024

#2331 suggests to add this bullet: https://github.com/FluxML/Flux.jl/pull/2331/files#diff-791e8b024a9ce7e7f89b45b7582d628d3d8d55f0bb5e17c39f8a50bd6aa21aeaR228-R230

from flux.jl.

jacob-m-wilson-42 avatar jacob-m-wilson-42 commented on June 14, 2024

@ToucheSir, the functionality you included in your previous post is well-documented. That code will calculate the gradients and the total loss of the combined individual loss terms. I am interested in using withgradient to return the loss value of each individual loss term (in your code, I would like to track the individual loss a and b every epoch). It doesn't affect how the network trains, but it gives you some insight into how the network is performing on each individual loss term. I'm studying Physics Informed Neural Networks (PINNs) and it is important to see how the network is handling the initial, boundary and physics loss terms individually. Without the below functionality

trio, grads = withgradient(model) do m
  a = loss_a(m, x)
  b = loss_b(m, x)
  (; c=a+b, a, b)
end

you would have to call withgradient on loss component a and b individually and manually add the gradients back together before passing to the optimizer. I would like to see this syntax added to the Flux documentation as it is only currently documented in the Zygote package.

@mcabbott, yes even something small like that would really help! Just something to make it more explicit that this functionality exists.

from flux.jl.

ToucheSir avatar ToucheSir commented on June 14, 2024

Ok, so in that case I agree with Carlo that the documentation should not mention multi-objective losses specifically, but rather focus on getting auxiliary information out and perhaps provide individual loss terms as an example.

from flux.jl.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.