Skip to content

Improve ability to convert safetensors files.#1276

Merged
prusnak merged 2 commits intoggml-org:masterfrom
ubik2:master
May 8, 2023
Merged

Improve ability to convert safetensors files.#1276
prusnak merged 2 commits intoggml-org:masterfrom
ubik2:master

Conversation

@ubik2
Copy link
Copy Markdown
Contributor

@ubik2 ubik2 commented May 2, 2023

When loading a safetensors file, ignore the metadata header.
If no pt or pth files are available, attempt to load safetensors files.
Edit: This has been changed to try to load safetensors files first, and only load the pt/pth/bin file if those aren't available.

… or pth files are available, attempt to load safetensors files
Comment thread convert.py Outdated
files = [file for glob in globs for file in path.glob(glob)]
if not files:
# Check if it's a set of safetensors files
globs = ["model-00001-of-*.safetensors"]
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Why not just add "model-00001-of-*.safetensors" to the globs above?

Copy link
Copy Markdown
Contributor Author

@ubik2 ubik2 May 4, 2023

Choose a reason for hiding this comment

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

That would generally work as well. I was thinking to treat it the same as the ggml files, where it's lower priority than the pth files, in case both exist. If I simply add the safetensors pattern to the globs, and both are present, the convert script will abort, since it's unsure which one to use.
In any case, I'm happy to change it if you prefer.

Copy link
Copy Markdown
Contributor

@prusnak prusnak May 4, 2023

Choose a reason for hiding this comment

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

Hm, shouldn't the safetensors be preferred if anything?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

That sounds good to me.
I initially wanted to minimize the behavior change, but I've updated the PR to try with the safetensors first.

@prusnak prusnak merged commit 95078cc into ggml-org:master May 8, 2023
Seunghhon pushed a commit to Seunghhon/llama.cpp that referenced this pull request Apr 26, 2026
* when loading a safetensors file, ignore the metadata header
* check for safetensors files first, and only use PyTorch versions when safetensors aren't available
phuongncn pushed a commit to phuongncn/llama.cpp-gx10-dgx-sparks-deepseekv4 that referenced this pull request Apr 28, 2026
* when loading a safetensors file, ignore the metadata header
* check for safetensors files first, and only use PyTorch versions when safetensors aren't available
phuongncn pushed a commit to phuongncn/llama.cpp-gx10-dgx-sparks-deepseekv4 that referenced this pull request Apr 28, 2026
ljubomirj pushed a commit to ljubomirj/llama.cpp that referenced this pull request May 6, 2026
* when loading a safetensors file, ignore the metadata header
* check for safetensors files first, and only use PyTorch versions when safetensors aren't available
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