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

[WIP] Move cpu tensors over to numpy #1077

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

Ch0ronomato
Copy link
Contributor

@Ch0ronomato Ch0ronomato commented Nov 10, 2024

Description

When doing an integration pass with pymc, there were type issues on the pymc side when given a torch tensor. To mitigate this, I migrated the linker to always return a numpy ndarray instead, and in the else case leave the tensor alone instead of forcing a device transfer.

Related Issue

Checklist

Type of change

  • New feature / enhancement
  • Bug fix
  • Documentation
  • Maintenance
  • Other (please specify):

📚 Documentation preview 📚: https://pytensor--1077.org.readthedocs.build/en/1077/

@Ch0ronomato Ch0ronomato changed the title Move cpu tensors over to numpy [WIP] Move cpu tensors over to numpy Nov 11, 2024
Comment on lines +16 to +21
from torch import is_tensor

if is_tensor(out) and out.device.type == "cpu":
return out.detach().numpy()
else:
return out
Copy link
Member

Choose a reason for hiding this comment

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

We should add an option to the PyTorch linker: coerce_to_numpy that defaults to True, and will apply to either CPU or GPU tensors? When False we don't force any conversion.

This mixed behavior is just unpredictable no?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I like it.

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