-
Notifications
You must be signed in to change notification settings - Fork 6.7k
Numpy std var large tensor fix #19324
Changes from all commits
4446c84
f2c939e
268aac2
d4443f3
aa1f2cd
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -1256,7 +1256,7 @@ def test_diagflat(): | |
| assert inp.grad.shape == inp.shape | ||
| assert inp.grad[-1, -1] == 1 | ||
|
|
||
|
|
||
| @use_np | ||
| def test_diagonal(): | ||
| inp = np.zeros((2, INT_OVERFLOW+2)) | ||
|
|
@@ -1967,6 +1967,38 @@ def test_array_split(): | |
| assert out[1][-1][-1] == 2 | ||
|
|
||
|
|
||
| @use_np | ||
| def test_std(): | ||
| N = 2*20 | ||
| inp = np.zeros((2, INT_OVERFLOW)) | ||
| inp[-1, -1] = N | ||
| inp.attach_grad() | ||
| with mx.autograd.record(): | ||
| out = np.std(inp, axis=1) | ||
| out.backward() | ||
| assert out.shape == (2, ) | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. can we directly comapre the outputs with actual numpy's operators ? call
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I tried that first but it would take too long to run on large tensors so I instead derived a analytical formula. The correctness has been verified with small tensor size first then I switched to large tenosr
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
| ref = ((float(N)/INT_OVERFLOW)**2 * (INT_OVERFLOW-1))**0.5 | ||
| assert_almost_equal(out[1], ref, rtol=1e-5, atol=1e-5) | ||
| assert inp.grad.shape == inp.shape | ||
| assert inp.grad[-1, -1] == 0 | ||
|
|
||
|
|
||
| @use_np | ||
| def test_var(): | ||
| N = 2*20 | ||
| inp = np.zeros((2, INT_OVERFLOW)) | ||
| inp[-1, -1] = N | ||
| inp.attach_grad() | ||
| with mx.autograd.record(): | ||
| out = np.var(inp, axis=1) | ||
| out.backward() | ||
| assert out.shape == (2, ) | ||
| ref = (float(N)/INT_OVERFLOW)**2 * (INT_OVERFLOW-1) | ||
| assert_almost_equal(out[1], ref, rtol=1e-5, atol=1e-5) | ||
|
|
||
| assert inp.grad.shape == inp.shape | ||
| assert inp.grad[-1, -1] == 0 | ||
|
|
||
| @use_np | ||
| def test_rollaxis(): | ||
| inp = np.zeros((1, 1, 2, INT_OVERFLOW, 1)) | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.
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.
can you change index variables inside the kernel to
index_tfromsize_tThere 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.
changed