Skip to content

feat: detect tensor container by content when there is no extension - #1315

Merged
0xShug0 merged 1 commit into
0xShug0:mainfrom
kikaitachi:sniff_format
Nov 16, 2026
Merged

0xShug0 merged 1 commit into
0xShug0:mainfrom
kikaitachi:sniff_format

Conversation

@kikaitachi

Copy link
Copy Markdown
Contributor

Detect tensor container by content when the file extension is unrecognised

Problem

open_tensor_source selects a loader from path.extension() only. When a model is stored in a
Hugging Face cache (~/.cache/huggingface/hub/...), the usable path
snapshots/<rev>/<dir>/model-q8_0.gguf is a symlink to a content-addressed blob such as
blobs/5fb838f0… with no extension. The model path gets canonicalised (weakly_canonical
resolves symlinks), so the loader receives the blob path and fails:

load failed (unsupported tensor source format: /cache/huggingface/hub/blobs/5f/5fb838f03bc1e5…)

This reproduces with audiocpp_model_load on Parakeet-TDT-0.6B-v3-GGUF/parakeet-tdt-0.6b-v3-q8_0.gguf
downloaded with hf download, and affects any model fetched that way (also e.g. symlinked or
renamed model files). llama.cpp is not affected because it checks the GGUF magic rather than the
extension.

Change

  • src/framework/assets/tensor_source.cpp: new sniff_tensor_container() that inspects the first
    9 bytes — GGUF magic, or a little-endian u64 header size in (0, 100 MB] followed by { for
    safetensors. open_tensor_source still matches the extension first; sniffing runs only when
    the extension is not in kTensorContainers. Otherwise unchanged, including the error message.
  • tests/unittests/test_gguf_tensor_source.cpp: test_extensionless_tensor_source_is_sniffed
    covers an extensionless GGUF, an extensionless safetensors file, and an unrecognised file
    (still rejected).

Behavior impact

  • Additive. Previously these paths always threw unsupported tensor source format; no input
    that loaded before is handled differently (extension lookup is unchanged and takes priority).
  • No effect on outputs, performance or memory for files with a recognised extension. The only
    extra cost is a 9-byte read on a path that would previously have failed.
  • Torch (.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):

cmake -S . -B build -DCMAKE_BUILD_TYPE=Release -DENGINE_BUILD_TESTS=ON \
  -DAUDIOCPP_MODEL_SET=custom -DAUDIOCPP_MODELS="parakeet_tdt;supertonic"
cmake --build build --target gguf_tensor_source_test --parallel
./build/bin/gguf_tensor_source_test      # -> gguf_tensor_source_test passed

End-to-end:

Known limitations

Only GGUF and safetensors are sniffed. Other helpers that test for a literal .gguf extension
(e.g. prepare_model_directory) are untouched, since they are not on this failing path.

@0xShug0
0xShug0 merged commit 4c2293a into 0xShug0:main Nov 16, 2026
17 of 18 checks passed
@0xShug0

0xShug0 commented Nov 16, 2026

Copy link
Copy Markdown
Owner

@kikaitachi Thanks! PR merged.

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