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

Add neural network gradient tests [Juliacon 2024 Hackathon] #346

Closed
gdalle opened this issue Jul 13, 2024 · 1 comment · Fixed by #352
Closed

Add neural network gradient tests [Juliacon 2024 Hackathon] #346

gdalle opened this issue Jul 13, 2024 · 1 comment · Fixed by #352
Labels
downstream Related to downstream compatibility test Related to the testing subpackage

Comments

@gdalle
Copy link
Member

gdalle commented Jul 13, 2024

Goal

High-level: Support structures beyond arrays and numbers in DifferentiationInterface.

Low-level: Write tests for taking gradients of neural networks with Flux and Lux.

Steps

  1. Read the slides of my autodiff intro https://gdalle.github.io/JuliaCon2024-AutoDiff/#/title-slide
  2. Read some of the DifferentiationInterface documentation to understand the general ideas:
  3. Read DITest source code to understand how test scenarios are defined
  4. Fork the DifferentiationInterface repository and open a pull request
  5. Add a file to DifferentiationInterfaceTest/src/scenarios called flux.jl
  6. Define a GradientScenario involving a very simple neural network built with Flux.jl, for instance the one in this tutorial.
  7. Usually in deep learning we differentiate with respect to the parameters of a layer. In Flux, these parameters are stored within the layer itself. So the gradient we need is the gradient of layer(input) with respect to layer!!! In other words, for your GradientScenario, you will have f(layer) = layer(fixed_input) as the function (it only applies the layer to a fixed input).
  8. Add a file to DifferentiationInterface/test/Single/Zygote called flux.jl and test your scenario with DifferentiationInterfaceTest.test_differentiation. Take inspiration from the other test files.
  9. Since layer is not an array, the returned type will not be an array either: the gradient will be some form of Flux layer as well (I think), so you probably want to compute the ground truth with Zygote at first to see how it is structured.

If you need help

Participants

@gdalle gdalle added downstream Related to downstream compatibility test Related to the testing subpackage labels Jul 15, 2024
@gdalle gdalle linked a pull request Jul 15, 2024 that will close this issue
@nialamarcotte
Copy link
Contributor

nialamarcotte commented Jul 19, 2024 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
downstream Related to downstream compatibility test Related to the testing subpackage
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants