Uh oh!
There was an error while loading. Please reload this page.
Conversation
KakaruHayate added a commit
to KakaruHayate/DiffSinger
that referenced
this pull request
Aug 25, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for freeto join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Introduce
MixedPrecisionLayerNorm(a drop-innn.LayerNormsubclass) and use it for the LayerNorms in the LYNXNet / LYNXNet2 diffusion backbones and the ConvNeXt aux decoder, so activations stay in fp16/bf16 under AMP autocast.Motivation
Under PyTorch AMP autocast (this project trains with
pl_trainer_precision: '16-mixed'by default),layer_normis in autocast's fp32 cast-policy list: everynn.LayerNormoutputs fp32 even with fp16 activations.The fp32 outputs then flow through ops that autocast does not cast (
Transpose, GELU/GLU, residual adds, dropout) until the next conv/linear, so all activations saved for backward in that span are stored in fp32 — doubling a large fraction of activation memory for no precision benefit.How it works
MixedPrecisionLayerNorm.forwarddisables autocast locally, castsweight/biasto the activation dtype, and callsF.layer_normdirectly. Mean/variance are still accumulated in fp32 inside the CUDA kernel; the only extra rounding is a one-time fp16 quantization of the normalized output and of the affine parameters.weight/biasmust be cast rather than passed through as fp32, because the CUDAlayer_normkernel rejects mixed input/weight dtypes (expected scalar type Half but found Float); upcasting the activation to fp32 instead would discard the memory saving entirely.Non-AMP fp32 execution is unchanged (bit-identical to
nn.LayerNorm), checkpoints stay fully compatible, and ONNX/JIT-exported graphs are identical to before.