Repository navigation
Upgrade MXNet backend to MXNet.np interface - #225
Conversation
Codecov Report
@@ Coverage Diff @@
## main #225 +/- ##
==========================================
+ Coverage 86.35% 87.05% +0.69%
==========================================
Files 82 82
Lines 3855 3846 -9
==========================================
+ Hits 3329 3348 +19
+ Misses 526 498 -28
Continue to review full report at Codecov.
|
|
@JeanKossaifi this should be ready to review when you have a chance. |
|
Thanks @aarmey, it's great to have this! |
|
Done @JeanKossaifi. MXNet seems to be extra picky about types, so I needed to adjust a few places where ints were being passed in. Everything is working aside from the robust PCA test, which I can't seem to fix. Has something changed about it recently? |
| skip_if_jax = pytest.mark.skipif(tl.get_backend() == "jax", | ||
| reason="Operation not supported in JAX") | ||
| skip_if_backend = pytest.mark.skipif(tl.get_backend() in ("tensorflow", "jax", "mxnet"), | ||
| reason=f"Operation not supported in {tl.get_backend()}") |
There was a problem hiding this comment.
Why are we skipping for MXNet? I am planning to fix this for JAX and tensorflow too, should be mostly a matter of doing the index assignment with index_update.
There was a problem hiding this comment.
Fixed (mostly). See below.
|
The issue with the Robust PCA must be due to the changes in the MXNet backend: the test still passes for the other backends and the last changes where made almost a year ago (same for the test, only the |
|
Ok, thanks. I'll try and track down the change... |
|
If the issue just comes from a dtype issue, then setting the default to None for the dtype as in NumPy might solve the issue. We can then let NumPy/MXNet choose the best dtype based on the input. |
|
|
||
| # Delete the selected row | ||
| mask.pop(max_row_idx) | ||
| mask.pop(tl.to_numpy(max_row_idx)) |
There was a problem hiding this comment.
MXNet does not automatically make scalars standard Python types, and so this is required to work with pop.
There was a problem hiding this comment.
Yes, I was explicitely typecasting in argmax to make up for that strange behaviour.
| @skip_if_tensorflow | ||
|
|
||
| @skip_if_backend | ||
| @pytest.mark.skipif(tl.get_backend() in ("mxnet"), reason=f"MXNet bug in advanced indexing (Issue 18919).") |
There was a problem hiding this comment.
I've gotten the other TT methods to work, but this one has an indexing problem where core is first created. I believe it's the same issue as this Issue on the MXNet repository.
| if mask is None: | ||
| mask = 1 | ||
| else: | ||
| mask = T.tensor(mask, dtype=float) |
There was a problem hiding this comment.
MXNet is not properly promoting a boolean/integer-type array when multiplied by a scalar float. The threshold was being converted to 0 below.
There was a problem hiding this comment.
That was a tricky one, kuddos for finding/fixing it!
That's a very odd behavior from MXNet -- we could report in the main repo.
There was a problem hiding this comment.
Definitely was tricky—I got lucky by seeing rec_X was always 0 with a mask.
|
Everything should be resolved @JeanKossaifi |
| def argmin(data=None, axis=None): | ||
| res = nd.argmin(data, axis) | ||
| if res.shape == (1,): | ||
| return res.astype('int32').asscalar() |
There was a problem hiding this comment.
I had added these asscalar and typecasting where appropriate to compensate for the issue with 0-order tensors. Do you think it's better to remove them all?
|
Looks good to me overall -- do you think it's better to not do any typecasting or |
|
Hmm... I'm happy to go with your preference, but think the casting makes more sense this way. I think MXNet is often doing this automatically (e.g., Python's In TT, the It seems more surprising that operations would fundamentally change the type of a variable depending upon the shape you end up with. My mental model of Tensorly is that it provides high-level abstractions of operations that mostly remain within the backend. |
|
I agree - best to let the backend decide as long as it doesn't break things for us. Thanks for the PR, merging! |
This also removes the need for some of the MXNet-specific workarounds.