-
Notifications
You must be signed in to change notification settings - Fork 48
ODSC-64654 register model artifact reference #1008
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
tkg2261
wants to merge
5
commits into
main
Choose a base branch
from
ODSC-64654-register-model-artifact-reference
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
Show all changes
5 commits
Select commit
Hold shift + click to select a range
7042af5
ODSC-64654 register model artifact reference
9223d68
exiting register_artifact function with exception on failure
c87b1fa
Merge branch 'main' into ODSC-64654-register-model-artifact-reference
VipulMascarenhas 11c5553
Merge branch 'main' into ODSC-64654-register-model-artifact-reference
mrDzurb 21ba115
Merge branch 'main' into ODSC-64654-register-model-artifact-reference
mayoor 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -17,7 +17,11 @@ | |
ExportModelArtifactDetails, | ||
ImportModelArtifactDetails, | ||
UpdateModelDetails, | ||
) | ||
WorkRequest, | ||
RegisterModelArtifactReferenceDetails, | ||
OSSModelArtifactReferenceDetails, | ||
ModelArtifactReferenceDetails | ||
|
||
from oci.exceptions import ServiceError | ||
from requests.structures import CaseInsensitiveDict | ||
|
||
|
@@ -474,6 +478,55 @@ def export_model_artifact(self, bucket_uri: str, region: str = None): | |
progress_bar_description="Exporting model artifacts." | ||
) | ||
|
||
@check_for_model_id( | ||
msg="Model needs to be saved to the Model Catalog before the artifact can be registered against it." | ||
) | ||
def register_model_artifact_reference(self, bucket_uri_list: List[str]) -> None: | ||
""" | ||
Registers model artifact references against a model. | ||
Can be used for any model for which model-artifact doesn't exist yet. Requires to provide List of Object | ||
Storage buckets_uri(s) which contain the artifacts. | ||
|
||
Parameters | ||
---------- | ||
bucket_uri_list: List[str] | ||
The list of OCI Object Storage URIs where model artifacts are present. | ||
Example: [`oci://<bucket_name>@<namespace>/prefix/`, `oci://<bucket_name>@<namespace>/prefix/`]. | ||
|
||
Returns | ||
------- | ||
None | ||
""" | ||
model_artifact_reference_details_list = [] | ||
for bucket_uri in bucket_uri_list: | ||
bucket_details = ObjectStorageDetails.from_path(bucket_uri) | ||
model_artifact_reference_details = OSSModelArtifactReferenceDetails() | ||
model_artifact_reference_details.namespace = bucket_details.namespace | ||
model_artifact_reference_details.bucket_name = bucket_details.bucket | ||
if bucket_details.filepath is not None and bucket_details.filepath != "": | ||
model_artifact_reference_details.prefix = bucket_details.filepath.strip('/') | ||
model_artifact_reference_details_list.append(model_artifact_reference_details) | ||
|
||
register_model_artifact_reference_details = RegisterModelArtifactReferenceDetails() | ||
register_model_artifact_reference_details.model_artifact_references = model_artifact_reference_details_list | ||
|
||
work_request_id = self.client.register_model_artifact_reference( | ||
model_id=self.id, | ||
register_model_artifact_reference_details=register_model_artifact_reference_details | ||
).headers["opc-work-request-id"] | ||
|
||
# Show progress of model artifact references being registered | ||
try : | ||
DataScienceWorkRequest(work_request_id).wait_work_request( | ||
progress_bar_description="Registering model artifact references." | ||
) | ||
logger.info("Artifact references registered successfully.") | ||
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. change this to debug |
||
except Exception as ex: | ||
logger.error(f"WorkRequest: `{work_request_id}` failed. Fetching Work Request Error Logs.") | ||
get_work_request_errors_response = self.client.list_work_request_errors(work_request_id) | ||
logger.error(get_work_request_errors_response.data) | ||
raise Exception(get_work_request_errors_response.data) | ||
|
||
@check_for_model_id( | ||
msg="Model needs to be saved to the Model Catalog before it can be updated." | ||
) | ||
|
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
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.
Just curious, since we already have the
.with_artifact()
logic, why introduce a new method? Wouldn't it be better to enhance the existing one? It's a well-known method, and users are already familiar with it. Also willdownload_artifact()
method still work?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.
@mrDzurb
.with_artifact()
method already does model-by-ref but using uploadArtifact api. We want to keep that flow too for now, till we completely enable and transition to registerArtifact API. I didn't want to introduce any breaking change, that's why have NOT modified existing method. Moreover,register_model_artifact_reference
as a separate method is also consistent withexport_model_artifact
method, which in a way does similar job.Yes, the
download_artifact
method will still work, it will download the json configuration file uploaded by the registerArtifact api.