-
Notifications
You must be signed in to change notification settings - Fork 1.4k
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
fix groupnorm int32 index overflow #1845
base: master
Are you sure you want to change the base?
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
sorry for having let this one slip off, could you add a test case which this PR allows?
@crcrpar thanks for your advise. I've added a test case and tested with H100. with the main branch, error occurs:
with the fixed branch, the atol should be adjusted to 7e-2 to account for potential increased reduction accuracy error
|
torch.testing.assert_close(y_tst, y_ref, atol=7e-2, rtol=0) | ||
torch.testing.assert_close(dx_tst, dx_ref, atol=7e-2, rtol=0) | ||
torch.testing.assert_close(dw_tst, dw_ref, atol=7e-2, rtol=0) | ||
torch.testing.assert_close(db_tst, db_ref, atol=7e-2, rtol=0) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
is this for the large tensor?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yes, float reduction accuracy error would grow up with larger tensor
@@ -177,6 +177,7 @@ def test_16_groups(self): | |||
[8, 1920, 32, 32], | |||
[8, 1920, 16, 16], | |||
[8, 2560, 8, 8], | |||
[1, 128, 16128, 1200], |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this seems to require about 50 GB, how about checking the memory size like
diff --git a/apex/contrib/test/group_norm/test_group_norm.py b/apex/contrib/test/group_norm/test_group_norm.py
index 5675749..687c2e1 100644
--- a/apex/contrib/test/group_norm/test_group_norm.py
+++ b/apex/contrib/test/group_norm/test_group_norm.py
@@ -177,8 +177,9 @@ class GroupNormTest(unittest.TestCase):
[8, 1920, 32, 32],
[8, 1920, 16, 16],
[8, 2560, 8, 8],
- [1, 128, 16128, 1200],
]
+ if torch.cuda.get_device_properties().total_memory > 50_000_000_000:
+ sizes.append([1, 128, 16128, 1200])
for sz in sizes:
n, c, h, w = sz
self.verify_group_norm(GroupNorm,
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've checked seriously, this tensor gots 128 * 16128 * 1200=2,477,260,800 elements, about 5GB. This kernel will take about 10GB, so this check seems not so necessary ?
@crcrpar |
This PR fix groupnorm int32 index calculate overflow when hwc is large, as hwc is of int data type. The problem could be reproduced by code below.
@crcrpar please review, thanks !