-
Notifications
You must be signed in to change notification settings - Fork 270
[WIP] Add support for converting to OCI artifacts #2046
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
Open
rhatdan
wants to merge
1
commit into
containers:main
Choose a base branch
from
rhatdan:artifact
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
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
Some comments aren't visible on the classic Files Changed page.
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
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
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 |
|---|---|---|
|
|
@@ -145,6 +145,7 @@ def __init__(self, model: str, model_store_path: str): | |
| self._model_type: str | ||
| self._model_name, self._model_tag, self._model_organization = self.extract_model_identifiers() | ||
| self._model_type = type(self).__name__.lower() | ||
| self.artifact = False | ||
|
|
||
| self._model_store_path: str = model_store_path | ||
| self._model_store: Optional[ModelStore] = None | ||
|
|
@@ -200,6 +201,8 @@ def _get_entry_model_path(self, use_container: bool, should_generate: bool, dry_ | |
|
|
||
| if self.model_type == 'oci': | ||
| if use_container or should_generate: | ||
| if getattr(self, "artifact", False): | ||
| return os.path.join(MNT_DIR, self.artifact_name()) | ||
| return os.path.join(MNT_DIR, 'model.file') | ||
| else: | ||
| return f"oci://{self.model}" | ||
|
|
@@ -345,9 +348,10 @@ def exec_model_in_container(self, cmd_args, args): | |
| def setup_mounts(self, args): | ||
| if args.dryrun: | ||
| return | ||
|
|
||
| if self.model_type == 'oci': | ||
| if self.engine.use_podman: | ||
| mount_cmd = f"--mount=type=image,src={self.model},destination={MNT_DIR},subpath=/models,rw=false" | ||
| mount_cmd = self.mount_cmd() | ||
| elif self.engine.use_docker: | ||
| output_filename = self._get_entry_model_path(args.container, True, args.dryrun) | ||
| volume = populate_volume_from_image(self, os.path.basename(output_filename)) | ||
|
|
@@ -651,40 +655,48 @@ def inspect( | |
| as_json: bool = False, | ||
| dryrun: bool = False, | ||
| ) -> None: | ||
| print(self.get_inspect(show_all, show_all_metadata, get_field, dryrun, as_json)) | ||
|
|
||
| def get_inspect( | ||
| self, | ||
| show_all: bool = False, | ||
| show_all_metadata: bool = False, | ||
| get_field: str = "", | ||
| dryrun: bool = False, | ||
| as_json: bool = False, | ||
| ) -> Any: | ||
| model_name = self.filename | ||
| model_registry = self.type.lower() | ||
| model_path = self._get_inspect_model_path(dryrun) | ||
|
|
||
| if GGUFInfoParser.is_model_gguf(model_path): | ||
| if not show_all_metadata and get_field == "": | ||
|
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. issue (code-quality): We've found these issues:
|
||
| gguf_info: GGUFModelInfo = GGUFInfoParser.parse(model_name, model_registry, model_path) | ||
| print(gguf_info.serialize(json=as_json, all=show_all)) | ||
| return | ||
| return gguf_info.serialize(json=as_json, all=show_all) | ||
|
|
||
| metadata = GGUFInfoParser.parse_metadata(model_path) | ||
| if show_all_metadata: | ||
| print(metadata.serialize(json=as_json)) | ||
| return | ||
| return metadata.serialize(json=as_json) | ||
| elif get_field != "": # If a specific field is requested, print only that field | ||
| field_value = metadata.get(get_field) | ||
| if field_value is None: | ||
| raise KeyError(f"Field '{get_field}' not found in GGUF model metadata") | ||
| print(field_value) | ||
| return | ||
| return field_value | ||
|
|
||
| if SafetensorInfoParser.is_model_safetensor(model_name): | ||
| safetensor_info: SafetensorModelInfo = SafetensorInfoParser.parse(model_name, model_registry, model_path) | ||
| print(safetensor_info.serialize(json=as_json, all=show_all)) | ||
| return | ||
| return safetensor_info.serialize(json=as_json, all=show_all) | ||
|
|
||
| print(ModelInfoBase(model_name, model_registry, model_path).serialize(json=as_json)) | ||
| return ModelInfoBase(model_name, model_registry, model_path).serialize(json=as_json) | ||
|
|
||
| def print_pull_message(self, model_name): | ||
| def print_pull_message(self, model_name) -> None: | ||
| model_name = trim_model_name(model_name) | ||
| # Write messages to stderr | ||
| perror(f"Downloading {model_name} ...") | ||
| perror(f"Trying to pull {model_name} ...") | ||
|
|
||
| def is_artifact(self) -> bool: | ||
| return False | ||
|
|
||
|
|
||
| def compute_ports(exclude: list[str] | None = None) -> list[int]: | ||
| exclude = exclude and set(map(int, exclude)) or set() | ||
|
|
||
Oops, something went wrong.
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.
suggestion: The models list is extended with both manifests and artifacts, which may result in duplicate entries if the same model exists in both forms.
Deduplicate models by name or ID to prevent listing the same model multiple times.
Suggested implementation:
"name"with the appropriate key in the deduplication logic.modelsis not empty before this block, you may want to deduplicate the entire list (including existing entries).