Repository navigation
feat: detect tensor container by content when there is no extension - #1315
Merged
Merged
Conversation
Owner
|
@kikaitachi Thanks! PR merged. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Detect tensor container by content when the file extension is unrecognised
Problem
open_tensor_sourceselects a loader frompath.extension()only. When a model is stored in aHugging Face cache (
~/.cache/huggingface/hub/...), the usable pathsnapshots/<rev>/<dir>/model-q8_0.ggufis a symlink to a content-addressed blob such asblobs/5fb838f0…with no extension. The model path gets canonicalised (weakly_canonicalresolves symlinks), so the loader receives the blob path and fails:
This reproduces with
audiocpp_model_loadonParakeet-TDT-0.6B-v3-GGUF/parakeet-tdt-0.6b-v3-q8_0.ggufdownloaded with
hf download, and affects any model fetched that way (also e.g. symlinked orrenamed model files). llama.cpp is not affected because it checks the GGUF magic rather than the
extension.
Change
src/framework/assets/tensor_source.cpp: newsniff_tensor_container()that inspects the first9 bytes —
GGUFmagic, or a little-endian u64 header size in (0, 100 MB] followed by{forsafetensors.
open_tensor_sourcestill matches the extension first; sniffing runs only whenthe extension is not in
kTensorContainers. Otherwise unchanged, including the error message.tests/unittests/test_gguf_tensor_source.cpp:test_extensionless_tensor_source_is_sniffedcovers an extensionless GGUF, an extensionless safetensors file, and an unrecognised file
(still rejected).
Behavior impact
unsupported tensor source format; no inputthat loaded before is handled differently (extension lookup is unchanged and takes priority).
extra cost is a 9-byte read on a path that would previously have failed.
.bin/.pt) is deliberately not sniffed: ZIP/pickle magic is not a reliable signal.Validation
Build and unit test (Jetson Thor, aarch64, Ubuntu, GCC 13.3, CPU backend):
End-to-end:
Known limitations
Only GGUF and safetensors are sniffed. Other helpers that test for a literal
.ggufextension(e.g.
prepare_model_directory) are untouched, since they are not on this failing path.