Skip to content

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.

@Ch0ronomato
Copy link
Contributor Author

@ricardoV94 did this basically. Gonna close 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