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

Tangent Interface Docs #434

Open
wants to merge 16 commits into
base: main
Choose a base branch
from
Open

Tangent Interface Docs #434

wants to merge 16 commits into from

Conversation

willtebbutt
Copy link
Member

@Jollywatt per our discussion elsewhere, here is a stab at aggregating all of the information that I have about the tangent interface into a single location. When you get a minute, could you let me know if this is the kind of thing that you need to do what you wanted to do, or if there's additional info that you'll need?

Copy link

codecov bot commented Jan 3, 2025

Codecov Report

Attention: Patch coverage is 50.00000% with 13 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
src/test_utils.jl 54.16% 11 Missing ⚠️
src/tangents.jl 0.00% 2 Missing ⚠️
Files with missing lines Coverage Δ
src/fwds_rvs_data.jl 20.64% <ø> (-76.03%) ⬇️
src/tangents.jl 10.24% <0.00%> (-74.99%) ⬇️
src/test_utils.jl 30.03% <54.16%> (-63.07%) ⬇️

... and 35 files with indirect coverage changes

Copy link
Contributor

github-actions bot commented Jan 3, 2025

Performance Ratio:
Ratio of time to compute gradient and time to compute function.
Warning: results are very approximate! See here for more context.

┌────────────────────────────┬──────────┬─────────┬─────────────┬─────────┐
│                      Label │ Mooncake │  Zygote │ ReverseDiff │  Enzyme │
│                     String │   String │  String │      String │  String │
├────────────────────────────┼──────────┼─────────┼─────────────┼─────────┤
│                   sum_1000 │     84.8 │     1.0 │        5.61 │    8.21 │
│                  _sum_1000 │      6.6 │  1380.0 │        34.4 │    1.09 │
│               sum_sin_1000 │     2.29 │    1.68 │        10.8 │    1.96 │
│              _sum_sin_1000 │     2.71 │   255.0 │        13.6 │    2.44 │
│                   kron_sum │     62.0 │    3.55 │       232.0 │    8.44 │
│              kron_view_sum │     21.3 │    3.32 │        80.8 │    34.0 │
│      naive_map_sin_cos_exp │      2.6 │ missing │        7.63 │    2.35 │
│            map_sin_cos_exp │     2.72 │    1.44 │        6.01 │    2.94 │
│      broadcast_sin_cos_exp │     2.59 │    2.23 │        1.46 │    2.24 │
│                 simple_mlp │     4.78 │    3.25 │        6.45 │     3.3 │
│                     gp_lml │     13.2 │    6.55 │     missing │     6.2 │
│ turing_broadcast_benchmark │     3.22 │ missing │        25.2 │ missing │
│         large_single_block │     4.42 │  4380.0 │        30.6 │    2.18 │
└────────────────────────────┴──────────┴─────────┴─────────────┴─────────┘

@yebai yebai requested a review from sunxd3 January 7, 2025 11:33
Copy link
Collaborator

@sunxd3 sunxd3 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I haven't tried to implement a tangent type and use these functions, so couldn't verify claims like If all the tests in these functions pass, then you have satisfied the interface. All the comments are only cosmetic.

But this is clearly a really good clarification!

# Tangents

As discussed in [Representing Gradients](@ref), Mooncake requires that each "primal" type be associated to a unique "tangent" type, given by the function [tangent_type](@ref).
Moreover, we must be able to "split" a given tangent into its _fdata_ ("forwards-data") and _rdata_ ("reverse-data"), whose types are given by [fdata_type](@ref) and `rdata_type` respectively.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe miss ref for rdata_type?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, yes. For some reason, it didn't like me doing that. I'm not 100% sure why.

src/test_utils.jl Show resolved Hide resolved
src/test_utils.jl Outdated Show resolved Hide resolved
src/test_utils.jl Outdated Show resolved Hide resolved
@Jollywatt
Copy link

@willtebbutt I've had a look at these docs and tried to implement the interface for a custom type. I was almost able to, but in particular I had to add methods for

  • _get_fdata_field
  • tangent (binary method)

in addition to those in the interface. I also ran into problems with a generated function, which I didn't find a way around.

I've put a MWE in this notebook: https://jollywatt.github.io/notes/mooncake-self-tangents

@willtebbutt
Copy link
Member Author

Thanks -- I'll take a look at your notebook!

@yebai
Copy link
Contributor

yebai commented Jan 9, 2025

@Jollywatt @willtebbutt I suggest that you take a look at #428 (comment) as part of "integration testing" this PR's completeness and accuracy. Defining a macro that can help users extend tangent types for their Julia types will be nice.

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

Successfully merging this pull request may close these issues.

4 participants