[Bugfix] Handle GroupNorm autocast safely - #4779
Open
akshatvishu wants to merge 4 commits into
Open
Conversation
Signed-off-by: akshatvishu <akshatnayak197@gmail.com>
Signed-off-by: akshatvishu <akshatnayak197@gmail.com>
Signed-off-by: akshatvishu <akshatnayak197@gmail.com>
Signed-off-by: akshatvishu <akshatnayak197@gmail.com>
Contributor
🏷️ CI GuideRuns automatically on every PR:
Extended tests (opt-in via labels):
|
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
Make AITER GroupNorm follow PyTorch's FP32 autocast policy. Add dtype checks before the HIP kernel reads the input and affine parameter pointers.
Fixes #4780
Motivation
Hunyuan Image 3.0 calls GroupNorm under CUDA autocast with an FP16 input and BF16 weight and bias tensors. PyTorch registers GroupNorm as an FP32 autocast operation, but AITER calls its HIP kernel directly and does not pass through that dispatcher rule.
The AITER kernel selects its pointer type from the input dtype. Before this change, it treated the BF16 weight and bias storage as FP16 when the input was FP16. In the Hunyuan VAE, the AITER output was FP16 while the PyTorch output was FP32. The mean error was 1.0778 and the maximum error was 6.1785.
Changes
Performance
Tests ran on one MI300X with gfx942, ROCm 7.2, and PyTorch 2.11. The autocast measurement includes the FP32 tensor conversions.
(1, 128, 4, 1024, 1024)rtol=0.001,atol=0.01(1, 128, 4, 64, 64)(1, 512, 3, 64, 64)The change does not alter the HIP GroupNorm arithmetic or memory access pattern. Bandwidth and roofline analysis do not apply to this correctness fix.
Testing
Documentation
Dependencies
PyTorch compatibility question
AITER documentation currently lists PyTorch 2.0 and later as supported. The
device_typeargument fortorch.is_autocast_enabledwas added in PyTorch 2.4, while PyTorch 2.0 to 2.3 accept no arguments.Maintainers, should GroupNorm preserve PyTorch 2.0 to 2.3 compatibility by using
torch.is_autocast_enabled()without an argument, or is the current AITER baseline PyTorch 2.4 or later?Breaking changes
A direct mixed dtype call without autocast now stops with a clear error instead of launching a kernel that interprets the affine parameter storage using the input dtype.