Skip to content

FR: Expose more info to Python bindings #569

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

Open
yanok opened this issue Feb 5, 2025 · 1 comment
Open

FR: Expose more info to Python bindings #569

yanok opened this issue Feb 5, 2025 · 1 comment

Comments

@yanok
Copy link

yanok commented Feb 5, 2025

Feature request

Currently we can only get shape and dtype for all tensors via Python bindings. Could we also expose a global data offset as well as start/end offsets of specific tensors?

In particular, I'm interested in getting (start, end) offsets in the file for a specific tensor, so probably the global offset is not even needed, we can do addition on the Rust side.

Motivation

I want to experiment with reading the actual data using our custom interface that can stream data directly to GPU. So my plan is to read safetensors metadata using normal POSIX reads and then use custom API to stream the data. Custom API is in C but there are working Python bindings, so at this stage I'd prefer to keep the wiring in Python instead of trying to call into C from Rust. But for that I need to expose the offsets to Python.

Your contribution

Yes, I can submit a PR. It seems like a trivial change.

@Narsil
Copy link
Collaborator

Narsil commented May 9, 2025

I feel like this could come in handy: https://gist.github.com/Narsil/3edeec2669a5e94e4707aa0f901d2282

I'd rather not add surface in safetensors given it's quite trivial to do in pure python already and a relatively niche need.

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

No branches or pull requests

2 participants