-
Notifications
You must be signed in to change notification settings - Fork 29
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
ENH: support CuPy to_device "cpu" #40
ENH: support CuPy to_device "cpu" #40
Conversation
* allow `to_device(x, "cpu")` for CuPy--this makes it easier to write portable unit tests where the expected value is on the host (a NumPy array) * otherwise, you can end up writing different shims in downstream libraries to move the array-like back to the host (`.get()` for CuPy...); if CuPy conforms to the standard, we shouldn't need this shim long-term
Looks fine to me, although this might also be something to request upstream from cupy. |
The standard doesn't say anything about how devices are specified https://data-apis.org/array-api/latest/design_topics/device_support.html#syntax-for-device-assignment. The "cpu" device for NumPy was just a convention that was chosen, probably based off pytorch. Maybe the standard should specify that "cpu" == host? It could be worth opening an issue about. I'm not sure what has already been discussed here. |
CuPy won't be tested until I test it manually. I'll be sure to do that before making another release. |
For the record I did test on CuPy (and Torch) locally with a 1080 Ti and passed for me. |
I'm actually a little unsure about this thinking about it. If you transfer a CuPy array to NumPy, you change what namespace it uses. That's different from PyTorch where CPU and GPU tensors both use the |
Good point, I shared that in the cross-linked array API standard issue. That said, at least for my use case, I didn't care so much about staying in the same array namespace as being able to have the memory usable directly in |
Well you would need to make sure to recall array_namespace after calling to_device. My feeling is that this goes against some of the design decisions of the standard (see https://data-apis.org/array-api/latest/purpose_and_scope.html and https://data-apis.org/array-api/latest/design_topics/data_interchange.html). But device stuff isn't really my wheelhouse so hopefully other folks will weigh in on the issue or at the consortium meeting. |
allow
to_device(x, "cpu")
for CuPy--this makes it easier to write portable unit tests where theexpected value is on the host (a NumPy array)
otherwise, you can end up writing different shims in downstream libraries to move the array-like back to the host (
.get()
for CuPy...); if CuPy conforms to the standard, we shouldn't need this shim long-term