Content-Length: 429526 | pFad | http://github.com/googleapis/python-aiplatform/commit/8fb836bcf361230e47d3af9e7ca5882a17da136a

96 fix: update Model.list_model_evaluations and get_model_evaluation to … · googleapis/python-aiplatform@8fb836b · GitHub
Skip to content

Commit 8fb836b

Browse files
authored
fix: update Model.list_model_evaluations and get_model_evaluation to use the provided version (#1616)
* fix: add model versioning support to Model.get_model_evaluation and list_model_evaluations * linting fix * update list_model_evaluations to use instantiated model version * update get evaluation method
1 parent 484e416 commit 8fb836b

File tree

2 files changed

+48
-6
lines changed

2 files changed

+48
-6
lines changed

google/cloud/aiplatform/models.py

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4571,10 +4571,14 @@ def list_model_evaluations(
45714571
self,
45724572
) -> List["model_evaluation.ModelEvaluation"]:
45734573
"""List all Model Evaluation resources associated with this model.
4574+
If this Model resource was instantiated with a version, the Model
4575+
Evaluation resources for that version will be returned. If no version
4576+
was provided when the Model resource was instantiated, Model Evaluation
4577+
resources will be returned for the default version.
45744578
45754579
Example Usage:
45764580
my_model = Model(
4577-
model_name="projects/123/locations/us-central1/models/456"
4581+
model_name="projects/123/locations/us-central1/models/456@1"
45784582
)
45794583
45804584
my_evaluations = my_model.list_model_evaluations()
@@ -4584,10 +4588,8 @@ def list_model_evaluations(
45844588
List of ModelEvaluation resources for the model.
45854589
"""
45864590

4587-
self.wait()
4588-
45894591
return model_evaluation.ModelEvaluation._list(
4590-
parent=self.resource_name,
4592+
parent=self.versioned_resource_name,
45914593
credentials=self.credentials,
45924594
)
45934595

@@ -4597,7 +4599,10 @@ def get_model_evaluation(
45974599
) -> Optional[model_evaluation.ModelEvaluation]:
45984600
"""Returns a ModelEvaluation resource and instantiates its representation.
45994601
If no evaluation_id is passed, it will return the first evaluation associated
4600-
with this model.
4602+
with this model. If the aiplatform.Model resource was instantiated with a
4603+
version, this will return a Model Evaluation from that version. If no version
4604+
was specified when instantiating the Model resource, this will return an
4605+
Evaluation from the default version.
46014606
46024607
Example usage:
46034608
my_model = Model(

tests/unit/aiplatform/test_models.py

Lines changed: 38 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2357,7 +2357,7 @@ def test_update(self, update_model_mock, get_model_mock):
23572357
model=current_model_proto, update_mask=update_mask
23582358
)
23592359

2360-
def test_get_model_evaluation_with_id(
2360+
def test_get_model_evaluation_with_evaluation_id(
23612361
self,
23622362
mock_model_eval_get,
23632363
get_model_mock,
@@ -2371,6 +2371,26 @@ def test_get_model_evaluation_with_id(
23712371
name=_TEST_MODEL_EVAL_RESOURCE_NAME, retry=base._DEFAULT_RETRY
23722372
)
23732373

2374+
def test_get_model_evaluation_with_evaluation_and_instantiated_version(
2375+
self,
2376+
mock_model_eval_get,
2377+
get_model_mock,
2378+
list_model_evaluations_mock,
2379+
):
2380+
test_model = models.Model(
2381+
model_name=f"{_TEST_MODEL_RESOURCE_NAME}@{_TEST_VERSION_ID}"
2382+
)
2383+
2384+
test_model.get_model_evaluation(evaluation_id=_TEST_ID)
2385+
2386+
mock_model_eval_get.assert_called_once_with(
2387+
name=_TEST_MODEL_EVAL_RESOURCE_NAME, retry=base._DEFAULT_RETRY
2388+
)
2389+
2390+
list_model_evaluations_mock.assert_called_once_with(
2391+
request={"parent": test_model.versioned_resource_name}
2392+
)
2393+
23742394
def test_get_model_evaluation_without_id(
23752395
self,
23762396
mock_model_eval_get,
@@ -2402,6 +2422,23 @@ def test_list_model_evaluations(
24022422

24032423
assert len(eval_list) == len(_TEST_MODEL_EVAL_LIST)
24042424

2425+
def test_list_model_evaluations_with_version(
2426+
self,
2427+
get_model_mock,
2428+
mock_model_eval_get,
2429+
list_model_evaluations_mock,
2430+
):
2431+
2432+
test_model = models.Model(
2433+
model_name=f"{_TEST_MODEL_RESOURCE_NAME}@{_TEST_VERSION_ID}"
2434+
)
2435+
2436+
test_model.list_model_evaluations()
2437+
2438+
list_model_evaluations_mock.assert_called_once_with(
2439+
request={"parent": test_model.versioned_resource_name}
2440+
)
2441+
24052442
def test_init_with_version_in_resource_name(self, get_model_with_version):
24062443
model = models.Model(
24072444
model_name=models.ModelRegistry._get_versioned_name(

0 commit comments

Comments
 (0)








ApplySandwichStrip

pFad - (p)hone/(F)rame/(a)nonymizer/(d)eclutterfier!      Saves Data!


--- a PPN by Garber Painting Akron. With Image Size Reduction included!

Fetched URL: http://github.com/googleapis/python-aiplatform/commit/8fb836bcf361230e47d3af9e7ca5882a17da136a

Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy