-
Notifications
You must be signed in to change notification settings - Fork 46
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
ODSC-64654 register model artifact reference #1008
base: main
Are you sure you want to change the base?
Changes from all commits
7042af5
9223d68
c87b1fa
11c5553
21ba115
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
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." | ||
) | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1553,4 +1553,45 @@ In the next example, the model that was stored in the model catalog as part of t | |
Restore Archived Model | ||
********************** | ||
|
||
The ``.restore_model()`` method of Model catalog restores the model for a specified number of hours. Restored models can be downloaded for 1-240 hours, defaulting to 24 hours. | ||
The ``.restore_model()`` method of Model catalog restores the model for a specified number of hours. Restored models can be downloaded for 1-240 hours, defaulting to 24 hours. | ||
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. What would be the full user experience? Could you provide end-to-end example? 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. Hi @mrDzurb this is an existing piece of code, my code starts below this, don't know why the diff is showing this as changed. |
||
|
||
Register Model Artifact Reference | ||
********************** | ||
|
||
The ``.register_model_artifact_reference()`` method of Model catalog registers the references of your OCI Object Storage buckets where the artifact files are present against the model. | ||
|
||
By using this API, you can avoid the need to upload or export large model artifacts, and can simply give the references of the OCI Object Storage locations where your artifacts are present. The OCI Data Science will directly read artifact files from those locations when you create a deployment of the model. | ||
|
||
The input to this method is a List of bucket_uri(s). The URI syntax for the bucket_uri is: | ||
|
||
oci://<bucket_name>@<namespace>/<path>/ | ||
|
||
Example - | ||
|
||
.. code-block:: python3 | ||
|
||
model.register_model_artifact_reference( | ||
bucket_uri_list = ["oci://<bucket_name>@<namespace>/<path>/"] | ||
) | ||
|
||
Important Points: | ||
|
||
1. The buckets provided should be of same region and have versioning enabled on them. | ||
|
||
2. The <path> is optional. If your files that you want to use for this model are within a path in the bucket, then path can be specified in the bucket_uri, else it can be skipped like below: | ||
|
||
oci://<bucket_name>@<namespace>/ | ||
|
||
3. The location specified by bucket_uri should have at-least one object within it. | ||
|
||
4. Make sure that the buckets provided has following IAM policy configured to allow the Data Science service to read artifact files from those Object Storage buckets in your tenancy. An administrator must configure these policies in `IAM <https://docs.oracle.com/iaas/Content/Identity/home1.htm>`_ in the Console. | ||
|
||
.. parsed-literal:: | ||
|
||
allow any-user to read object-family in compartment <compartment> where ALL {target.bucket.name= '<bucket_name>', request.principal.type = /\*datasciencemodel\*/} | ||
|
||
If you want, you can have a more granular policy by having an additional filter on project_id like below, which will then give access to the bucket only to models present in the data science project specified in the filter. | ||
|
||
.. parsed-literal:: | ||
|
||
allow any-user to read object-family in compartment <compartment> where ALL {target.bucket.name= '<bucket_name>', request.principal.type = /\*datasciencemodel\*/, request.principal.project_id = '<project_ocid>'} |
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.