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

[Safetensors parser] Support optional file path #563

Merged
merged 8 commits into from
Mar 20, 2024

Conversation

mishig25
Copy link
Collaborator

@mishig25 mishig25 commented Mar 20, 2024

Before

Safetensors parser was in assumption that safetensors files are strictly named model.safetensors, which is not the case always.

This PR

Support optional file names so that other names like llama3.safetensors would still work

Copy link
Member

@coyotte508 coyotte508 left a comment

Choose a reason for hiding this comment

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

What happens if the safetensors index file is inside a folder?

Should we use the folder as the "base" path for the other files?

packages/hub/src/lib/parse-safetensors-metadata.ts Outdated Show resolved Hide resolved
packages/hub/src/lib/parse-safetensors-metadata.ts Outdated Show resolved Hide resolved
@mishig25 mishig25 marked this pull request as ready for review March 20, 2024 10:39
@mishig25 mishig25 requested review from apolinario and removed request for apolinario March 20, 2024 11:14
@mishig25
Copy link
Collaborator Author

cc: @apolinario for the upcoming moon support

Copy link
Member

@julien-c julien-c left a comment

Choose a reason for hiding this comment

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

lgtm with a few suggestions!

Co-authored-by: Julien Chaumond <[email protected]>
@coyotte508
Copy link
Member

coyotte508 commented Mar 20, 2024

Looks good, just this question:

What happens if the safetensors index file is inside a folder?

Should we then use the folder as the "base" path for the other files?

(if relevant)

@julien-c
Copy link
Member

yes valid question from @coyotte508 actually (read too fast initially)

IIRC @Narsil the shard index file contains relative filenames (there's no notion of directory), right? we should always assume the single files are in the same folder imo, correct?

(we can fix this in a later PR though i guess – and add a test from a real model)

@mishig25
Copy link
Collaborator Author

(we can fix this in a later PR though i guess – and add a test from a real model)

merging this PR

@mishig25 mishig25 merged commit 3bd9297 into main Mar 20, 2024
1 of 2 checks passed
@mishig25 mishig25 deleted the safetensors_parser_file_path branch March 20, 2024 12:12
@osanseviero
Copy link
Contributor

Note that for diffusion, the situation is a bit tricky as we have non-diffusers safetensors at the top directory, while diffusers safetensors in folders

See https://huggingface.co/stabilityai/sdxl-turbo/tree/main

@julien-c
Copy link
Member

@osanseviero yes. So this PR should work, no?

@osanseviero
Copy link
Contributor

Yes, this PR is good, but we might need to make some distinction for diffusers in the UI between these two types of safetensors models.

@mishig25
Copy link
Collaborator Author

Yes, this PR is good, but we might need to make some distinction for diffusers in the UI between these two types of safetensors models.

I think that task is for the moon

@osanseviero
Copy link
Contributor

Yes, this indeed is for moon

@julien-c
Copy link
Member

yes valid question from @coyotte508 actually (read too fast initially)

IIRC @Narsil the shard index file contains relative filenames (there's no notion of directory), right? we should always assume the single files are in the same folder imo, correct?

Let's open an issue so we don't forget this, ok?

@julien-c
Copy link
Member

@osanseviero for diffusers on the main model page i think we will still only parse a file model.safetensors so we won't display a model size for diffusers (too complex to calculate from different files / not worth it for now IMO)

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.

4 participants