-
Notifications
You must be signed in to change notification settings - Fork 106
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
Implemented Eye Op in PyTorch #877
Conversation
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #877 +/- ##
==========================================
- Coverage 81.05% 81.05% -0.01%
==========================================
Files 170 170
Lines 46980 46992 +12
Branches 11509 11510 +1
==========================================
+ Hits 38079 38088 +9
- Misses 6695 6697 +2
- Partials 2206 2207 +1
|
@ricardoV94, is there something odd with the coverage reports? |
It's flaky don't worry |
tests/link/pytorch/test_basic.py
Outdated
trange = range(1, 6) | ||
for _N in trange: | ||
for _M in trange: | ||
for _k in list(range(_M + 2)) + [-x for x in range(1, _N + 2)]: | ||
compare_pytorch_and_py( | ||
FunctionGraph([N, M, k], [out]), | ||
[np.array(_N), np.array(_M), np.array(_k)], | ||
) |
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.
In this case let's compile a single pytensor function and call repeatedly with the different inputs, instead of creating a function for every combination of test values. Something like:
fn = pytensor.function([N, M, k], out, mode=torch_mode) # Whatever mode is used internally in `compare_pytorch_and_py`
for _N in trange....:
...
np.testing.assert_allclose(fn(_N, _M, _k), np.eye(_N, _M, _k))
tests/link/pytorch/test_basic.py
Outdated
M = scalar("M", dtype="int64") | ||
k = scalar("k", dtype="int64") | ||
|
||
out = eye(N, M, k, dtype="float32") |
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.
Do we need to specify dtype here? It should be handled automatically by the config.floatX
setting
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.
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.
If dtype is something the user can control directly we should probably test with default and a user-specified non-default?
Left some comments, some are style choices (feel free to push back on those) but some need to be addressed ( |
c36ac85
to
5024b04
Compare
Can you give me a declaration example for the default, non-explicit part.
Am Sa., 6. Juli 2024 um 19:05 Uhr schrieb Ricardo Vieira <
***@***.***>:
… ***@***.**** commented on this pull request.
------------------------------
In tests/link/pytorch/test_basic.py
<#877 (comment)>:
> @@ -235,3 +235,20 @@ def test_arange():
FunctionGraph([start, stop, step], [out]),
[np.array(1), np.array(10), np.array(2)],
)
+
+
+def test_eye():
+ N = scalar("N", dtype="int64")
+ M = scalar("M", dtype="int64")
+ k = scalar("k", dtype="int64")
+
+ out = eye(N, M, k, dtype="float32")
+
+ trange = range(1, 6)
+
+ fn = function([N, M, k], out, mode=pytorch_mode)
+
+ for _N in trange:
Can stay then, there's still the question of testing default vs manual
dtype discussed above
—
Reply to this email directly, view it on GitHub
<#877 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/ALEEX7GXWIXDLW4V2THR7U3ZLAPVVAVCNFSM6AAAAABKIGQSLGVHI2DSMVQWIX3LMV43YUDVNRWFEZLROVSXG5CSMV3GSZLXHMZDCNRRGU2TINBWGU>
.
You are receiving this because you were mentioned.Message ID:
***@***.***>
|
I guess just test |
- Added support for diagonal offset (param `k`)
5024b04
to
08d23ab
Compare
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.
Not sure why codecov is whining, but this looks good to go on my end.
I think codecov cannot see line hits the way pytorch uses the functions |
Cool stuff @twaclaw! |
@twaclaw I've been trying to contact you through LI, or maybe send me an email. |
Description
PyTorch
-
torch.eye
doesn't support a diagonal offset paramk
directly. The implementation of this offset required composing twotorch
functions.Related Issue
Checklist
Type of change