-
Notifications
You must be signed in to change notification settings - Fork 89
Improve Safetensors packaging #607
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
base: main
Are you sure you want to change the base?
Conversation
…m model files in a directory
Summary of ChangesHello @ilopezluna, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed! This pull request significantly enhances the model packaging and unpacking capabilities by introducing a new directory-based builder. This allows for a more faithful representation of complex model structures, such as those found in HuggingFace, by preserving nested file paths through OCI layer annotations. The changes also include a robust mechanism for excluding unwanted files during packaging and a smarter unpacking process that automatically adapts to different model formats. Furthermore, critical security improvements have been made to prevent directory traversal vulnerabilities during file extraction. Highlights
🧠 New Feature in Public Preview: You can now enable Memory to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console. Using Gemini Code AssistThe full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips. Invoking Gemini You can request assistance from Gemini at any point by creating a comment using either
Customization To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a Limitations & Feedback Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here. You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension. Footnotes
|
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.
Code Review
This pull request introduces a significant improvement to model packaging by allowing the creation of model artifacts directly from a directory structure, preserving nested file paths. This is achieved through a new builder.FromDirectory function and a corresponding V0.2 model config format. The unpacking logic has been updated to handle this new format while maintaining backward compatibility with V0.1 models. The changes are well-structured and include thorough testing. My review focuses on improving the robustness and maintainability of the new unpacking logic, particularly regarding the handling of different layer types and reducing code duplication.
adcc1d3 to
491326d
Compare
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.
Hey - I've found 1 issue, and left some high level feedback:
- The new layer-based unpacking paths (
UnpackFromLayers,unpackGenericFileLayers,unpackSafetensorsWithAnnotations) duplicate very similardescriptorProvider/pathProviderpatterns and annotation handling logic; consider extracting shared helper interfaces/functions to reduce drift and make future changes less error-prone. - In
FromDirectoryall filesystem entries whose base name starts with.are unconditionally skipped, which prevents packaging intentionally hidden content (e.g.,.well-known); you may want an option to override this behavior or to limit the auto-skip to a narrower set (like.git). - Several loops over layers silently
continueon errors from methods likeMediaType(),Digest(), orLayers()(e.g., inunpackSafetensorsWithAnnotations,UnpackFromLayers,unpackGenericFileLayers), which can mask mispackaged layers; consider logging or wrapping these errors to make diagnosing bad artifacts easier while still tolerating non-critical failures if needed.
Prompt for AI Agents
Please address the comments from this code review:
## Overall Comments
- The new layer-based unpacking paths (`UnpackFromLayers`, `unpackGenericFileLayers`, `unpackSafetensorsWithAnnotations`) duplicate very similar `descriptorProvider` / `pathProvider` patterns and annotation handling logic; consider extracting shared helper interfaces/functions to reduce drift and make future changes less error-prone.
- In `FromDirectory` all filesystem entries whose base name starts with `.` are unconditionally skipped, which prevents packaging intentionally hidden content (e.g., `.well-known`); you may want an option to override this behavior or to limit the auto-skip to a narrower set (like `.git`).
- Several loops over layers silently `continue` on errors from methods like `MediaType()`, `Digest()`, or `Layers()` (e.g., in `unpackSafetensorsWithAnnotations`, `UnpackFromLayers`, `unpackGenericFileLayers`), which can mask mispackaged layers; consider logging or wrapping these errors to make diagnosing bad artifacts easier while still tolerating non-critical failures if needed.
## Individual Comments
### Comment 1
<location> `pkg/distribution/MODEL_TYPES.md:172-174` </location>
<code_context>
+| Format | Constant | Description |
+|--------|----------|-------------|
+| GGUF | `FormatGGUF` | llama.cpp quantized models |
+| Safetensors | `FormatSafetensors` | HuggingFace weights |
+| Diffusers | `FormatDiffusers` | Image generation models |
+
</code_context>
<issue_to_address>
**suggestion (typo):** Consider changing "HuggingFace" to the more common "Hugging Face" spelling.
Using the standard "Hugging Face" spelling will align with the official brand and common usage.
```suggestion
| Format | Constant | Description |
|--------|----------|-------------|
| GGUF | `FormatGGUF` | llama.cpp quantized models |
| Safetensors | `FormatSafetensors` | Hugging Face weights |
| Diffusers | `FormatDiffusers` | Image generation models |
```
</issue_to_address>Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.
Co-authored-by: sourcery-ai[bot] <58596630+sourcery-ai[bot]@users.noreply.github.com>
This pull request introduces a new directory-based model packaging builder and updates the unpacking logic to support a more flexible layer-per-file model format (V0.2). The changes significantly improve support for complex model directory structures.
Directory-based model packaging and exclusion logic:
FromDirectoryand related options inpkg/distribution/builder/from_directory.go, enabling recursive packaging of model directories with full structure preservation and customizable exclusion patterns (by name, glob, or path).shouldExcludehelper function for flexible exclusion matching, supporting directory names, file names, globs, and specific paths.Testing and validation:
pkg/distribution/builder/from_directory_test.goto verify directory packaging and exclusion logic, covering various exclusion scenarios and edge cases.Unpacking logic improvements:
pkg/distribution/internal/bundle/unpack.goto auto-detect and unpack models using the new V0.2 layer-per-file format, falling back to legacy logic for older formats. AddedisV02Modeldetection and refactored runtime config unpacking for interface compatibility. [1] [2]Documentation:
pkg/distribution/MODEL_TYPES.mdto document model types, interfaces, helper functions, concrete types, supported formats, media types, and design rationale for multiple interfaces.