-
Notifications
You must be signed in to change notification settings - Fork 69
Test: Replaced raw Mooncake with Flux implementation and checked Mooncake compatibility for more layers #642
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
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -123,15 +123,13 @@ function test_gradients( | |||||
| end | ||||||
|
|
||||||
| if test_mooncake | ||||||
| # Mooncake gradient with respect to input, compared against Zygote. | ||||||
| # Mooncake gradient with respect to input via Flux integration, compared against Zygote. | ||||||
| loss_mc_x = (xs...) -> loss(f, graph, xs...) | ||||||
| # TODO error without `invokelatest` when using TestItemRunner | ||||||
| _cache_x = Base.invokelatest(Mooncake.prepare_gradient_cache, loss_mc_x, xs...) | ||||||
| y_mc, g_mc = Base.invokelatest(Mooncake.value_and_gradient!!, _cache_x, loss_mc_x, xs...) | ||||||
| result = Flux.withgradient(loss_mc_x, Flux.AutoMooncake(), xs...) | ||||||
| y_mc = result.val # Extract value from NamedTuple | ||||||
| g_mc = result.grad # Extract gradients tuple | ||||||
| @assert isapprox(y, y_mc; rtol, atol) | ||||||
| for i in eachindex(xs) | ||||||
| @assert isapprox(g[i], g_mc[i+1]; rtol, atol) | ||||||
| end | ||||||
| check_equal_leaves(g, g_mc; rtol, atol) | ||||||
| end | ||||||
|
|
||||||
| if test_gpu | ||||||
|
|
@@ -158,14 +156,12 @@ function test_gradients( | |||||
| end | ||||||
|
|
||||||
| if test_mooncake | ||||||
| # Mooncake gradient with respect to f, compared against Zygote. | ||||||
| ps_mc, re_mc = Flux.destructure(f) | ||||||
| loss_mc_f = ps -> loss(re_mc(ps), graph, xs...) | ||||||
| _cache_f = Base.invokelatest(Mooncake.prepare_gradient_cache, loss_mc_f, ps_mc) | ||||||
| y_mc, g_mc = Base.invokelatest(Mooncake.value_and_gradient!!, _cache_f, loss_mc_f, ps_mc) | ||||||
| # Mooncake gradient with respect to f via Flux integration, compared against Zygote. | ||||||
| result = Flux.withgradient(f -> loss(f, graph, xs...), Flux.AutoMooncake(), f) | ||||||
| y_mc = result.val # Extract value from NamedTuple | ||||||
| g_mc_result = result.grad # Extract gradients tuple | ||||||
|
CarloLucibello marked this conversation as resolved.
Outdated
|
||||||
| @assert isapprox(y, y_mc; rtol, atol) | ||||||
| g_mc_f = (re_mc(g_mc[2]),) | ||||||
| check_equal_leaves(g, g_mc_f; rtol, atol) | ||||||
| check_equal_leaves(g, g_mc_result; rtol, atol) | ||||||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
@CarloLucibello The
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ops, sorry, yes please fix |
||||||
| end | ||||||
|
|
||||||
| if test_gpu | ||||||
|
|
||||||
Uh oh!
There was an error while loading. Please reload this page.