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

Upgrading Pyo3 0.22 (with gil-refs) #504

Merged
merged 3 commits into from
Jul 25, 2024
Merged

Upgrading Pyo3 0.22 (with gil-refs) #504

merged 3 commits into from
Jul 25, 2024

Conversation

Narsil
Copy link
Collaborator

@Narsil Narsil commented Jul 25, 2024

What does this PR do?

Upgrades to PyO3 0.22.
gil-refs still required because I couldn't find a way to get access to the &[u8] from the data pybuffer.
Without gil-refs, the data is created in pydata which is dropped at the end of the loop, therefore the reference doesn't live long enough.

I also tried changing everything around to use FromPyObject but it's not implemented for &[u8] as it would require FromPyObjectBound which is a sealed trait.

Additionally, the SafetensorError custom exception doesn't work with gil-refs because it doesn't implement the HasPyGilRef.

the trait `pyo3::PyNativeType` is not implemented for `SafetensorError`, which is required by `SafetensorError: HasPyGilRef`

Moving to just renaming PyException sort of seems to work without too much breaking change, although the exception is now the regular exception being effectively a catch all which is a breaking change.

Fixes # (issue) or description of the problem this PR solves.

let tensor = if count == 0 {
// Torch==1.10 does not allow frombuffer on empty buffers so we create
// the tensor manually.
// let zeros = module.getattr(intern!(py, "zeros"))?;
let args = (shape.clone(),);
let shape: PyObject = shape.clone().into_py(py);
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

PyObject doesn'tseem to implement clone anymore therefore we're just cloning the raw Rust object.

@Narsil Narsil changed the title [WIP] Upgrading Pyo3 0.22 (with gil-refs) Upgrading Pyo3 0.22 (with gil-refs) Jul 25, 2024
@Narsil Narsil merged commit 7d29f61 into main Jul 25, 2024
3 checks passed
@Narsil Narsil deleted the upgrade_pyo3_2 branch July 25, 2024 12:42
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