Skip to content

rule for LuxLib.Impl.batchnorm_cudnn and fix CI Mooncake tests. - #1738

Open
AstitvaAggarwal wants to merge 3 commits into
LuxDL:mainfrom
AstitvaAggarwal:Astitva/mooncake-gpu-rules
Open

rule for LuxLib.Impl.batchnorm_cudnn and fix CI Mooncake tests.#1738
AstitvaAggarwal wants to merge 3 commits into
LuxDL:mainfrom
AstitvaAggarwal:Astitva/mooncake-gpu-rules

Conversation

@AstitvaAggarwal

@AstitvaAggarwal AstitvaAggarwal commented Jul 9, 2026

Copy link
Copy Markdown
Contributor

Adds a Mooncake rrule!! for LuxLib.Impl.batchnorm_cudnn, enabling Mooncake AD through Lux's GPU BatchNorm. The rule is caching the forward pass's batch stats so the pullback doesn't recompute them non-deterministically (similar pattern as FluxML/NNlib#727). New tests check both interface registration and correctness (vs Zygote).

Note : Ive also fixed the LuxTestUtils bug that was causing Mooncake to fail completely on CI, due to which its testing was disabled temporarily (#1703 etc.)

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Code Review

This pull request integrates Mooncake.jl into the LuxLib library, enabling reverse-mode automatic differentiation support for cuDNN-based batch normalization. The changes include adding Mooncake as a dependency, implementing a custom rrule for batchnorm_cudnn, and introducing a helper function _unwrap_mooncake_tangent in LuxTestUtils to handle tangent unwrapping. The review feedback correctly identifies a potential runtime error in the new test suite, suggesting the use of the newly implemented unwrapping utility to ensure compatibility with Mooncake's tangent objects.

Important

The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.

)
∂args_mooncake = ∂all_mooncake[2:end] # drop the gradient w.r.t. `f` itself
for (∂zyg, ∂mc) in zip(∂args_zygote, ∂args_mooncake)
@test Array(∂mc) ≈ Array(∂zyg) atol = atol rtol = rtol

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

medium

The check_mooncake_correctness function directly calls Array(∂mc) on the result of Mooncake.value_and_gradient!!. If Mooncake returns a Tangent object instead of a raw array (which can happen depending on the configuration), Array(∂mc) will throw a MethodError. It is safer to use LuxTestUtils._unwrap_mooncake_tangent to ensure the tangent is unwrapped before converting to an Array.

@test Array(LuxTestUtils._unwrap_mooncake_tangent(∂mc))  Array(∂zyg) atol = atol rtol = rtol

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

done

@AstitvaAggarwal
AstitvaAggarwal force-pushed the Astitva/mooncake-gpu-rules branch from 667b04d to 6e301ec Compare July 23, 2026 16:26
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.

1 participant