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

PyO3: Better shape handling #1143

Merged
merged 5 commits into from
Oct 29, 2023

Conversation

LLukas22
Copy link
Contributor

This PR adds the ability to provide shapes as *args meaning that rand((10,10)) can now also be written as rand(10,10). I also added a new PyRelativeShape struct which handles negative dims, e.g. t.reshape(-1,1). I decided to add this new struct to explicitly make some functions accept "relative" shapes (e.g. reshape) and force other functions to only accept normal PyShapes (e.g. rand).

I also needed to upgrade pyo3 from 0.19.0 to 0.20.0 as there was a bug with *args and named parameters which got fixed in 0.20.0 e.g. rand(*shape, device=None) wouldn't let me specify a device even if the python code was valid.

candle-pyo3/py_src/candle/__init__.pyi Outdated Show resolved Hide resolved
candle-pyo3/src/shape.rs Outdated Show resolved Hide resolved
@LLukas22
Copy link
Contributor Author

Alright, i renamed it to PyShapeWithHole and added the validation logic.

@LaurentMazare LaurentMazare merged commit 174b208 into huggingface:main Oct 29, 2023
22 of 24 checks passed
@LaurentMazare
Copy link
Collaborator

Merged, thanks!

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