This repository has been archived by the owner on Nov 17, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 6.8k
[v1.x][LT] Add forward & backward linalg.gemm test for large size #18825
Merged
sandeep-krishnamurthy
merged 2 commits into
apache:v1.x
from
ChaiBapchya:add_lt_gemm_test
Jul 30, 2020
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1211,23 +1211,49 @@ def check_syrk_batch(): | |
assert_almost_equal(A.grad[1,0,0], nd.array([0.4]), rtol=1e-3, atol=1e-5) | ||
|
||
def check_gemm2(): | ||
def run_gemm2(inp1,inp2): | ||
def run_gemm2(inp1, inp2): | ||
inp1.attach_grad() | ||
inp2.attach_grad() | ||
with mx.autograd.record(): | ||
out = mx.nd.linalg.gemm2(inp1,inp2) | ||
out = mx.nd.linalg.gemm2(inp1, inp2) | ||
return inp1.grad, inp2.grad, out | ||
|
||
inp1=mx.nd.ones(shape=(SMALL_Y, LARGE_X)) | ||
inp1[0][0]=0.1 | ||
inp2=mx.nd.ones(shape=(LARGE_X, SMALL_Y)) | ||
inp1_grad, inp2_grad, out= run_gemm2(inp1,inp2) | ||
inp1 = mx.nd.ones(shape=(SMALL_Y, LARGE_X)) | ||
perturbation = 0.2 | ||
inp1[0][0] = perturbation | ||
inp2 = mx.nd.ones(shape=(LARGE_X, SMALL_Y)) | ||
inp1_grad, inp2_grad, out = run_gemm2(inp1, inp2) | ||
assert out.asnumpy()[0][0] == LARGE_X | ||
assert out.shape == (SMALL_Y, SMALL_Y) | ||
out.backward() | ||
assert inp1_grad.shape == (SMALL_Y, LARGE_X) | ||
assert inp2_grad.shape == (LARGE_X, SMALL_Y) | ||
assert_almost_equal(inp2_grad.asnumpy()[0][0],49.1) | ||
assert_almost_equal(inp1_grad.asnumpy()[0][0], SMALL_Y) | ||
assert_almost_equal(inp2_grad.asnumpy()[0][0], SMALL_Y - (1 - perturbation)) | ||
|
||
def check_gemm(): | ||
def run_gemm(inp1,inp2, inp3): | ||
inp1.attach_grad() | ||
inp2.attach_grad() | ||
inp3.attach_grad() | ||
with mx.autograd.record(): | ||
out = mx.nd.linalg.gemm(inp1, inp2, inp3, transpose_b=True) | ||
return inp1.grad, inp2.grad, inp3.grad, out | ||
|
||
inp1 = mx.nd.ones(shape=(MEDIUM_X, SMALL_Y, MEDIUM_X)) | ||
perturbation = 0.2 | ||
inp1[0][0][0] = perturbation | ||
inp2 = mx.nd.ones(shape=(MEDIUM_X, SMALL_Y, MEDIUM_X)) | ||
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. spaces around 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. It's incorrect according to PEP8 style guide Python |
||
inp3 = mx.nd.ones(shape=(MEDIUM_X, SMALL_Y, SMALL_Y)) | ||
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. same 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. It's incorrect according to PEP8 style guide Python |
||
inp1_grad, inp2_grad, inp3_grad, out= run_gemm(inp1, inp2, inp3) | ||
ChaiBapchya marked this conversation as resolved.
Show resolved
Hide resolved
|
||
assert_almost_equal(out.asnumpy()[0][0][0], MEDIUM_X + perturbation) | ||
assert out.shape == inp3.shape | ||
out.backward() | ||
assert inp1_grad.shape == (MEDIUM_X, SMALL_Y, MEDIUM_X) | ||
assert inp2_grad.shape == (MEDIUM_X, SMALL_Y, MEDIUM_X) | ||
assert inp3_grad.shape == (MEDIUM_X, SMALL_Y, SMALL_Y) | ||
assert_almost_equal(inp1_grad.asnumpy()[0][0][0], SMALL_Y) | ||
assert_almost_equal(inp2_grad.asnumpy()[0][0][0], SMALL_Y - (1 - perturbation)) | ||
|
||
def check_det(): | ||
def run_det(inp): | ||
|
@@ -1340,6 +1366,7 @@ def run_trsm(inp): | |
assert(grad[0, 0, 0] == 0) | ||
assert(grad[1, 0, 0] == 0) | ||
|
||
check_gemm() | ||
check_potrf() | ||
check_potri() | ||
check_syrk_batch() | ||
|
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.
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.
spaces around
=
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.
It's incorrect according to PEP8 style guide Python
https://www.python.org/dev/peps/pep-0008/