feat(graph): bf16/fp16 Parameter.AddGradient (unblock bf16 autograd training)#153
Merged
Conversation
The host gradient-accumulation type switch in AddGradient/ClearGradient had float32/float64/ints but no reduced-precision float case, so any bf16 (or fp16) autograd training failed at the first backward with 'AddGradient unsupported for this numeric type'. Add float16.BFloat16 and float16.Float16 cases: accumulate through f32 and round on store (matching how every bf16 op publishes its result). bf16 shares f32's exponent range, so no overflow vs f32. Unblocks bf16 CrossAsset training (its layer backwards accumulate grads here). General framework fix -- any bf16/fp16 consumer benefits; CPU f32/f64/int paths byte-identical.
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 free
to 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
Parameter.AddGradient/ClearGradienthost gradient-accumulation type switches covered float32/float64/ints but no reduced-precision float case, so bf16 (or fp16) autograd training failed at the first backward withAddGradient unsupported for this numeric type; use engine ops instead. This is the gating blocker for bf16 CrossAsset training (its layer backwards — LayerNorm/Linear/Bias — accumulate grads through this path).Fix
Add
float16.BFloat16andfloat16.Float16cases: accumulate through f32 and round on store (matching how every bf16 op publishes its result). bf16 shares f32's exponent range, so no overflow vs f32.Tests
TestParameter_AddGradient_BFloat16/_Float16(round-trip via the shared helper)TestParameter_AddGradient_BFloat16_Value— asserts two accumulations sum exactly (0.5+0.25→0.75, 1.0+0.5→1.5, both bf16-exact).General framework fix — any bf16/fp16 consumer benefits, nothing Wolf-specific. Follow-up to v1.13.0 (native bf16 GPU kernels).