Repository navigation
fix: handle concurrent remote shard download failures gracefully #43
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
Closed
Changes from 7 commits
Commits
Show all changes
19 commits
Select commit
Hold shift + click to select a range
1b1a090
implement remote gguf inspection on hugging face
pipe1os 71ef3a3
split print_model_info test to comply with codacy method size limit
pipe1os d0c5474
fix codacy issues: add read limit, honor gpu_util, modularize hf pars…
pipe1os bebe2c1
refactor: split concurrent shards fetching to lower cyclomatic comple…
pipe1os 6555e0e
fix codacy issues: compute GGUF group variant overhead dynamically
pipe1os 357ee16
docs: document remote gguf inspection options in README.md
pipe1os 5a8e6e2
fix: strip trailing slashes from model paths at entrypoint
pipe1os 7dc8576
fix: handle reverse tensor shape ordering for gguf shape guessing
pipe1os 0ef126b
fix: treat paths starting with local prefix as local files to prevent…
pipe1os b0b9744
fix: handle concurrent remote shard download failures gracefully
pipe1os 9ba40d0
fix: resolve safetensors shard index prefix splitting
pipe1os 738e291
merge: integrate branch 004-fix-safetensors-shard-prefix
pipe1os 1b1c58f
merge: integrate branch 005-graceful-shard-downloads
pipe1os 56bbf66
merge: integrate branch 006-fix-gguf-shape-guessing
pipe1os 0cfe2e5
merge: integrate branch 007-refine-remote-detection
pipe1os 2deb25a
merge: integrate branch 008-fix-comparison-trailing-slash
pipe1os 32bf12b
fix: address codacy review feedback on disk size, regex, path parsing…
pipe1os aa331eb
merge: sync with main and apply updates
pipe1os 1acb0cb
merge: sync with main
pipe1os File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -44,46 +44,53 @@ def _read_gguf_value(f: Any, val_type: int) -> Any: | |
| raise ValueError(f"Unknown GGUF value type: {val_type}") | ||
|
|
||
|
|
||
| def parse_gguf_header(path: str) -> Dict[str, Any]: | ||
| def parse_gguf_header(path_or_file: str | Any) -> Dict[str, Any]: | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ⚪ LOW RISK Nitpick: Consider using |
||
| """Parses a GGUF file header and extracts tensor information.""" | ||
| if isinstance(path_or_file, str): | ||
| with open(path_or_file, "rb") as f: | ||
| return _parse_gguf_header_from_stream(f) | ||
| else: | ||
| return _parse_gguf_header_from_stream(path_or_file) | ||
|
|
||
|
|
||
| def _parse_gguf_header_from_stream(f: Any) -> Dict[str, Any]: | ||
| tensors: Dict[str, Any] = {} | ||
| magic = f.read(4) | ||
| if magic != b"GGUF": | ||
| raise ValueError("Invalid GGUF file: Magic bytes missing.") | ||
|
|
||
| version = struct.unpack("<I", f.read(4))[0] | ||
| if version < 2: | ||
| raise ValueError(f"Unsupported GGUF version: {version}") | ||
|
|
||
| tensor_count = struct.unpack("<Q", f.read(8))[0] | ||
| kv_count = struct.unpack("<Q", f.read(8))[0] | ||
|
|
||
| with open(path, "rb") as f: | ||
| magic = f.read(4) | ||
| if magic != b"GGUF": | ||
| raise ValueError("Invalid GGUF file: Magic bytes missing.") | ||
|
|
||
| version = struct.unpack("<I", f.read(4))[0] | ||
| if version < 2: | ||
| raise ValueError(f"Unsupported GGUF version: {version}") | ||
|
|
||
| tensor_count = struct.unpack("<Q", f.read(8))[0] | ||
| kv_count = struct.unpack("<Q", f.read(8))[0] | ||
| metadata = {} | ||
| for _ in range(kv_count): | ||
| key_len = struct.unpack("<Q", f.read(8))[0] | ||
| key_name = f.read(key_len).decode("utf-8") | ||
| val_type = struct.unpack("<I", f.read(4))[0] | ||
| metadata[key_name] = _read_gguf_value(f, val_type) | ||
|
|
||
| metadata = {} | ||
| for _ in range(kv_count): | ||
| key_len = struct.unpack("<Q", f.read(8))[0] | ||
| key_name = f.read(key_len).decode("utf-8") | ||
| val_type = struct.unpack("<I", f.read(4))[0] | ||
| metadata[key_name] = _read_gguf_value(f, val_type) | ||
|
|
||
| tensors["__metadata__"] = metadata | ||
|
|
||
| for _ in range(tensor_count): | ||
| name_len = struct.unpack("<Q", f.read(8))[0] | ||
| name = f.read(name_len).decode("utf-8") | ||
|
|
||
| n_dims = struct.unpack("<I", f.read(4))[0] | ||
| shape = [] | ||
| for _ in range(n_dims): | ||
| shape.append(struct.unpack("<Q", f.read(8))[0]) | ||
|
|
||
| t_type = struct.unpack("<I", f.read(4))[0] | ||
| f.read(8) # skip offset bytes | ||
|
|
||
| # Strict GGUF tensor type mapping | ||
| dtype = GGML_TYPE_MAP.get(t_type, "Unknown") | ||
|
|
||
| tensors[name] = {"shape": shape, "dtype": dtype} | ||
| tensors["__metadata__"] = metadata | ||
|
|
||
| for _ in range(tensor_count): | ||
| name_len = struct.unpack("<Q", f.read(8))[0] | ||
| name = f.read(name_len).decode("utf-8") | ||
|
|
||
| n_dims = struct.unpack("<I", f.read(4))[0] | ||
| shape = [] | ||
| for _ in range(n_dims): | ||
| shape.append(struct.unpack("<Q", f.read(8))[0]) | ||
|
|
||
| t_type = struct.unpack("<I", f.read(4))[0] | ||
| f.read(8) # skip offset bytes | ||
|
|
||
| # Strict GGUF tensor type mapping | ||
| dtype = GGML_TYPE_MAP.get(t_type, "Unknown") | ||
|
|
||
| tensors[name] = {"shape": shape, "dtype": dtype} | ||
|
|
||
| return tensors | ||
|
|
||
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🟡 MEDIUM RISK
Local disk_size calculation for sharded SafeTensors (.index.json) currently reports the size of the index JSON file itself instead of the total weight size of all shards. This creates a discrepancy between local and remote model reporting.