Skip to content
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

fixes #550: move torch tensors to cpu before to numpy array #853

Merged
merged 1 commit into from
Sep 16, 2023

Conversation

dkgaraujo
Copy link
Contributor

As mentioned in keras-team/keras#18437, one remaining change from #750 is to first move the torch tensor to the CPU before passing it to a numpy array.

This is relevant for the Metal GPU case. While calling .cpu() is harmless on a torch tensor already in the CPU, in my observation directly moving the tensor from Metal to numpy returns an error, hence the need to move it first.

@google-cla
Copy link

google-cla bot commented Sep 8, 2023

Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA).

View this failed invocation of the CLA check for more information.

For the most up to date status, view the checks section at the bottom of the pull request.

@dkgaraujo
Copy link
Contributor Author

Another thing I would mention is that the instructions for macOS users could be updated to reflect that access to GPU requires setting another environment variable as follows:

import os
os.environ[“KERAS_BACKEND”] = “torch”
os.environ[“PYTORCH_ENABLE_MPS_FALLBACK”] = “1”
import keras_core as keras

@codecov
Copy link

codecov bot commented Sep 8, 2023

Codecov Report

Patch coverage: 100.00% and no project coverage change.

Comparison is base (f350416) 76.00% compared to head (ae75181) 76.00%.
Report is 2 commits behind head on main.

Additional details and impacted files
@@           Coverage Diff           @@
##             main     keras-team/keras-core#853   +/-   ##
=======================================
  Coverage   76.00%   76.00%           
=======================================
  Files         328      328           
  Lines       31103    31103           
  Branches     6052     6052           
=======================================
  Hits        23639    23639           
  Misses       5866     5866           
  Partials     1598     1598           
Flag Coverage Δ
keras_core 75.91% <100.00%> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.

Files Changed Coverage Δ
..._core/trainers/data_adapters/torch_data_adapter.py 86.95% <100.00%> (ø)

☔ View full report in Codecov by Sentry.

📢 Have feedback on the report? Share it here.

@dkgaraujo
Copy link
Contributor Author

I signed the CLA - I'm not sure if I should take another step to officially pass that check.

Copy link
Member

@fchollet fchollet left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, thanks! You can ignore the CLA issue.

@fchollet fchollet merged commit 6ad426a into keras-team:main Sep 16, 2023
7 of 8 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants