Fix: Inability to get file size from HuggingFace downloader#45
Merged
djx-trans-n merged 2 commits intomainfrom Jul 4, 2025
Merged
Fix: Inability to get file size from HuggingFace downloader#45djx-trans-n merged 2 commits intomainfrom
djx-trans-n merged 2 commits intomainfrom
Conversation
sxy-trans-n
approved these changes
Jul 4, 2025
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.
Fix: Inability to get file size from HuggingFace downloader
1. What does this PR do?
This PR fixes the file size retrieval logic in
HuggingFaceDownloader. The key changes include:getWhisperKitFileSizemethod, a fallback mechanism is now triggered when theContent-Lengthfrom aHEADrequest is invalid (e.g., less than or equal to 0).getFileSizeWithRangeRequest, has been added. It sends aGETrequest with aRange: bytes=0-0header to retrieve the file'sContent-Rangeinformation, from which the accurate total file size is parsed.2. Why is this PR needed?
When running the
swama pull whisper-tinycommand, the program would crash due to a division-by-zero error. The root cause is:Content-Lengthheader forHEADrequests on files with content compression enabled (likegziporbr), causinghttpResponse.expectedContentLengthto return-1.0and passed as thetotalparameter to theProgressBar.ProgressBar, a division-by-zero error occurred when calculating the download percentage (percent = downloaded / total), leading to a crash.This PR resolves the issue by implementing a more reliable mechanism for fetching the file size.
3. Related Discussions
Fatal error: Double value cannot be converted to Int because it is either infinite or NaNthat occurred duringswama pull.4. How was this tested?
export SWAMA_REGISTRY=HUGGING_FACE.swama pull whisper-tiny.5. Impact Analysis
HuggingFaceDownloaderand has no impact onModelScopeDownloaderor other modules.getFileSizeWithRangeRequestmethod.