48
48
"publishers/hf-meta-llama/models/llama-3.3-70b-instruct@001"
49
49
)
50
50
_TEST_HUGGING_FACE_ACCESS_TOKEN = "test-access-token"
51
-
51
+ _TEST_GCS_URI = "gs://some-bucket/some-model"
52
52
_TEST_ENDPOINT_NAME = "projects/test-project/locations/us-central1/endpoints/1234567890"
53
53
_TEST_MODEL_NAME = "projects/test-project/locations/us-central1/models/9876543210"
54
54
_TEST_MODEL_CONTAINER_SPEC = types .ModelContainerSpec (
@@ -85,6 +85,22 @@ def google_auth_mock():
85
85
yield google_auth_mock
86
86
87
87
88
+ @pytest .fixture
89
+ def export_publisher_model_mock ():
90
+ """Mocks the export_publisher_model method."""
91
+ with mock .patch .object (
92
+ model_garden_service .ModelGardenServiceClient ,
93
+ "export_publisher_model" ,
94
+ ) as export_publisher_model :
95
+ mock_export_lro = mock .Mock (ga_operation .Operation )
96
+ mock_export_lro .result .return_value = types .ExportPublisherModelResponse (
97
+ publisher_model = _TEST_MODEL_FULL_RESOURCE_NAME ,
98
+ destination_uri = _TEST_GCS_URI ,
99
+ )
100
+ export_publisher_model .return_value = mock_export_lro
101
+ yield export_publisher_model
102
+
103
+
88
104
@pytest .fixture
89
105
def deploy_mock ():
90
106
"""Mocks the deploy method."""
@@ -338,6 +354,7 @@ def list_publisher_models_mock():
338
354
"deploy_mock" ,
339
355
"get_publisher_model_mock" ,
340
356
"list_publisher_models_mock" ,
357
+ "export_publisher_model_mock" ,
341
358
)
342
359
class TestModelGarden :
343
360
"""Test cases for ModelGarden class."""
@@ -350,6 +367,54 @@ def setup_method(self):
350
367
def teardown_method (self ):
351
368
aiplatform .initializer .global_pool .shutdown (wait = True )
352
369
370
+ def test_export_full_resource_name_success (self , export_publisher_model_mock ):
371
+ aiplatform .init (
372
+ project = _TEST_PROJECT ,
373
+ location = _TEST_LOCATION ,
374
+ )
375
+ model = model_garden .OpenModel (model_name = _TEST_MODEL_FULL_RESOURCE_NAME )
376
+ model .export (_TEST_GCS_URI )
377
+ export_publisher_model_mock .assert_called_once_with (
378
+ types .ExportPublisherModelRequest (
379
+ parent = f"projects/{ _TEST_PROJECT } /locations/{ _TEST_LOCATION } " ,
380
+ name = _TEST_MODEL_FULL_RESOURCE_NAME ,
381
+ destination = types .GcsDestination (output_uri_prefix = _TEST_GCS_URI ),
382
+ ),
383
+ metadata = [("x-goog-user-project" , "test-project" )],
384
+ )
385
+
386
+ def test_export_simplified_resource_name_success (self , export_publisher_model_mock ):
387
+ aiplatform .init (
388
+ project = _TEST_PROJECT ,
389
+ location = _TEST_LOCATION ,
390
+ )
391
+ model = model_garden .OpenModel (model_name = _TEST_MODEL_SIMPLIFIED_RESOURCE_NAME )
392
+ model .export (_TEST_GCS_URI )
393
+ export_publisher_model_mock .assert_called_once_with (
394
+ types .ExportPublisherModelRequest (
395
+ parent = f"projects/{ _TEST_PROJECT } /locations/{ _TEST_LOCATION } " ,
396
+ name = _TEST_MODEL_FULL_RESOURCE_NAME ,
397
+ destination = types .GcsDestination (output_uri_prefix = _TEST_GCS_URI ),
398
+ ),
399
+ metadata = [("x-goog-user-project" , "test-project" )],
400
+ )
401
+
402
+ def test_export_hugging_face_id_success (self , export_publisher_model_mock ):
403
+ aiplatform .init (
404
+ project = _TEST_PROJECT ,
405
+ location = _TEST_LOCATION ,
406
+ )
407
+ model = model_garden .OpenModel (model_name = _TEST_MODEL_HUGGING_FACE_ID )
408
+ model .export (_TEST_GCS_URI )
409
+ export_publisher_model_mock .assert_called_once_with (
410
+ types .ExportPublisherModelRequest (
411
+ parent = f"projects/{ _TEST_PROJECT } /locations/{ _TEST_LOCATION } " ,
412
+ name = _TEST_HUGGING_FACE_MODEL_FULL_RESOURCE_NAME ,
413
+ destination = types .GcsDestination (output_uri_prefix = _TEST_GCS_URI ),
414
+ ),
415
+ metadata = [("x-goog-user-project" , "test-project" )],
416
+ )
417
+
353
418
def test_deploy_full_resource_name_success (self , deploy_mock ):
354
419
aiplatform .init (
355
420
project = _TEST_PROJECT ,
0 commit comments