fix: eliminate HuggingFace rate-limit failures in model downloads#2
Open
shreeraman96 wants to merge 1 commit into
Open
fix: eliminate HuggingFace rate-limit failures in model downloads#2shreeraman96 wants to merge 1 commit into
shreeraman96 wants to merge 1 commit into
Conversation
Replace the per-directory tree walk with a single recursive listing (with Link pagination), honor ratelimit/Retry-After headers on 429/503 with capped backoff, stop wiping the model cache on rate-limit and network errors so partial downloads stay resumable, fall back to the HuggingFace CLI token file for authenticated quotas, and add a URLProtocol-based regression suite.
12 tasks
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.
Why is this change needed?
Fixes altic-dev/FluidVoice#683. Anonymous HuggingFace clients get 500 API requests per 5-minute fixed window per IP (the
apibucket; verified viaratelimit-policyheaders). Downloading Parakeet v3 listed one directory per API call (41 calls measured), and any failure wiped the cache and re-ran the burst —AsrManagermodel loads plus the consumer's retry made a single download gesture cost ~250 listing calls, saturating the window and making every subsequent attempt fail with "Rate limited while listing files" for all engines.Changes
downloadRepo/downloadSubdirectorywith a single?recursive=truelisting, with RFC 5988Link: rel="next"pagination (100-page cap + cycle detection).selectFilesToDownload(tree:patterns:subPath:)that reproduces the old walk's pruning + inclusion semantics exactly.fetchHuggingFaceFile: delay from theratelimitheader'st=(seconds to window reset), elseRetry-After, else exponential backoff, clamped to [0.5s, 300s];CancellationErrorandURLError.cancelledpropagate immediately.loadModels' wipe-and-retry: rate-limit, HTML-error-page, network, and cancellation errors rethrow without deleting the cache (partial downloads stay resumable); corruption/compile failures keep the wipe + single retry.~/.cache/huggingface/token(HuggingFace CLI login) when the token env vars are absent, and send aUser-Agent.DownloadUtilsRateLimitTests(15 tests) with a URLProtocol stub via an internalsessionOverrideseam.Repro evidence (offline stub HF server via
REGISTRY_URL, real Parakeet v3 tree)Before this change:
downloadRepoAfter this change:
t=1)Verification
swift test --filter DownloadUtilsRateLimitTests: 15/15 pass (single-call listing, pagination union, header-aware retry, retry exhaustion message, no-cache-wipe on 429 and onURLError.timedOut, filter-equivalence for subPath/non-subPath/pruned-ancestor cases).swift buildandswift format lintclean.Consumer impact
Public API unchanged (internal test seam only), so FluidVoice and other consumers build as-is; FluidVoice picks the fix up via its
B/cohere-coreml-asrbranch pin. A companion FluidVoice PR gates the app-level cache-clear recovery the same way.