Skip to content

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

Closed
@gdalle

Description

@gdalle

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    downstreamRelated to downstream compatibilitytestRelated to the testing subpackage

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions