Repository navigation
package_manager: native Hugging Face Xet downloads - #1222
Merged
Merged
Conversation
Unmodified lib/ sources of LZ4 v1.10.0 (BSD-2-Clause). The native package manager uses the LZ4 frame decoder for Hugging Face Xet xorb chunks; the library is only compiled with AUDIOCPP_BUILD_NATIVE_MODEL_MANAGER=ON.
Xet-backed files are reconstructed with the Xet CAS protocol instead of
streaming the /resolve redirect over a single connection:
- read X-Xet-Hash and the commit-pinned xet-auth link from the existing
un-followed /resolve metadata request
- get a read-scoped CAS token and query v2 reconstructions in 10 GB ranges
- fetch the signed xorb ranges in parallel (AUDIOCPP_HF_XET_CONCURRENCY,
default 16), parse raw or multipart/byteranges 206 bodies as they stream,
decode none/LZ4/ByteGrouping4-LZ4 chunks and write them at their term
offsets in the staging file with bounded memory
- validate every term's unpacked_length, the final size, and the Hub
SHA-256 (hashed on a background thread while the transfer runs;
AUDIOCPP_HF_XET_VERIFY=0 skips it)
- retry transient errors, refresh the CAS token on 401, and re-query the
reconstruction when a signed xorb URL is rejected
Non-Xet files, ModelScope, AUDIOCPP_HF_XET=0 and any Xet failure before
publication fall back to the existing HTTP download. Staging, atomic
publication, manifests and progress are unchanged. Hub, CAS and signed
storage URLs each receive only their own credentials.
The shared URL/client helpers move from manager.cpp to http_util.{h,cpp}
without behavior changes. package_manager_xet_test covers the decoders,
the multipart parser, and full transfers and fallbacks against a local
fixture.
Owner
|
@drphero Thanks for the improvement! I found two issues:
Please restore the ordinary
|
Capture a copied progress message instead of the structured binding `remote`, which C++17 does not allow in lambda captures (GCC accepts it as an extension; Clang rejects it). Count Xet progress per term as the furthest byte any attempt has written, kept across signed-URL refresh passes, so bytes redone after a refresh are not reported twice and progress cannot pass the file size. Add a fixture case that interrupts a partly written transfer with a refresh.
Contributor
Author
|
Thanks for testing this! Both are fixed in 89f5b17.
Unrelated to this PR: |
Owner
|
@drphero 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.
Native Hugging Face Xet downloads for the package manager
Most large model files on Hugging Face are now stored with Xet. The native package manager currently follows the
/resolveredirect and streams each file over one connection, which is whyhf download(backed byhf_xet) is noticeably faster. This PR adds a download-only Xet client in C++ toaudiocpp_package_manager, soaudiocpp_model_managerand the server/WebUI get the faster transfer path without any Python dependency.How it works
/resolvemetadata request now also keepsX-Xet-Hash, the commit-pinnedrel="xet-auth"link, andX-Linked-ETag(the file's SHA-256). No extra request is needed./api/models/{repo}/xet-read-token/{revision}.GET {casUrl}/v2/reconstructions/{hash}is requested in 10 GBRangebatches, as the spec recommends.AUDIOCPP_HF_XET_CONCURRENCY). Responses are parsed as they stream (raw206or strictmultipart/byteranges, with every part'sContent-Rangechecked against the signed range set). Chunks are decoded with no compression, LZ4 frame, or ByteGrouping4 + LZ4, and written straight to their term offsets in the existing staging file. Whole ranges are never buffered, so peak RSS stays around 10–15 MiB.unpacked_length, as the spec requires. The file size is checked, and the SHA-256 is verified againstX-Linked-ETagon a background thread that hashes the completed prefix while the transfer runs (AUDIOCPP_HF_XET_VERIFY=0turns this off).Staging, size validation, atomic publication, manifests (etags stay the same), install locks, cancellation, and progress all go through the existing install path unchanged. Xet only fills the staged file.
Fallback and safety
AUDIOCPP_HF_XET=0, and any Xet failure before publication (token or v2 unavailable, unsupported recipe layout, protocol error, retries exhausted) fall back to the existing HTTP download. The progress message names the route used.set_path_encode(false)).401on CAS refreshes the token. A403or expired signature on a xorb URL re-queries the reconstruction and redoes only the unfinished terms.Dependencies
lib/sources (BSD-2-Clause) underexternal/lz4. They are compiled only withAUDIOCPP_BUILD_NATIVE_MODEL_MANAGER=ON. Xet chunks use the LZ4 frame format.Changes
src/framework/package_manager/xet.{h,cpp}: the Xet clientsrc/framework/package_manager/http_util.{h,cpp}: URL/client helpers moved out ofmanager.cpp(pure move) so both transports share themmanager.cpp: carries the Xet metadata inRemoteFileInfo;download_file()tries Xet, then HTTPtests/unittests/test_package_manager_xet.cpp: offline tests (below)docs/model_manager.md: new "Hugging Face Xet Transfers" sectionCMakeLists.txt:lz4_vendortarget, the new sources, and the test (same guards as the existing package-manager tests)Validation
Unit/integration tests (
package_manager_xet_test, fully offline): a local httplib fixture plays Hub, CAS and xorb host, serving xorbs built in the test from known bytes.offset_into_first_range > 0, a 403 refreshing the recipe, a 503 retry, 200-instead-of-206 rejected,unpacked_lengthmismatch rejected, SHA-256 mismatch, v2 501PackageManager::install: the Xet route is used,AUDIOCPP_HF_XET=0, fallback on v2 404/501, token 403 and a protocol error, an integrity failure publishes nothing, cancellation publishes nothing, the manifest etag is unchanged, and no credential leaks (checked on every request)offset_into_first_range, or theunpacked_lengthcheck each makes the suite fail.Also:
package_manager_http_test,package_manager_modelscope_testandserver_model_installer_testpass. The Xet and HTTP tests are clean under ASan+UBSan. Helgrind reports no data races in the downloader. (TSan can't run in the container used for testing.)Real downloads: each output is byte-identical to the current HTTP route (
cmp/ per-file SHA-256) and matches the Hub SHA-256.Linux x86_64, 6 vCPU, datacenter network. Release build. Wall time per install. Runs alternate between routes so neither one always gets a warm CDN.
main(HTTP)hf download(huggingface_hub 2.2.0, hf_xet 1.7.0)qwen3_asr_0_6b_q8_0(1 file, 1.15 GB)qwen3_asr_1_7b_f16(1 file, 4.09 GB)index_tts2_safetensors(21 files, 8.08 GB)On this link that is about 2–2.6× faster than the current native route. For single large files it is close to
hf downloadat a small fraction of its memory. Multi-file packages still trailhf download, because the installer downloads a package's files one after another, whilehf downloadfetches several files concurrently. Parallelism here is within a file only. Single-connection throughput depends on latency, so the gain over the current route should be larger on higher-latency consumer links, where a single stream is the bottleneck. The numbers above come only from the machine described.Not tested