1
1
#!/usr/bin/env python
2
2
# -*- coding: utf-8 -*--
3
- # Copyright (c) 2024 Oracle and/or its affiliates.
3
+ # Copyright (c) 2024, 2025 Oracle and/or its affiliates.
4
4
# Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl/
5
5
6
6
import os
@@ -653,12 +653,12 @@ def test_get_model_fine_tuned(
653
653
}
654
654
655
655
@pytest .mark .parametrize (
656
- ("artifact_location_set" , "download_from_hf" ),
656
+ ("artifact_location_set" , "download_from_hf" , "cleanup_model_cache" ),
657
657
[
658
- (True , True ),
659
- (True , False ),
660
- (False , True ),
661
- (False , False ),
658
+ (True , True , True ),
659
+ (True , False , True ),
660
+ (False , True , False ),
661
+ (False , False , True ),
662
662
],
663
663
)
664
664
@patch ("ads.model.service.oci_datascience_model.OCIDataScienceModel.create" )
@@ -683,6 +683,7 @@ def test_import_verified_model(
683
683
mock_ocidsc_create ,
684
684
artifact_location_set ,
685
685
download_from_hf ,
686
+ cleanup_model_cache ,
686
687
mock_get_hf_model_info ,
687
688
mock_init_client ,
688
689
):
@@ -742,11 +743,13 @@ def test_import_verified_model(
742
743
app = AquaModelApp ()
743
744
if download_from_hf :
744
745
with tempfile .TemporaryDirectory () as tmpdir :
746
+ mock_snapshot_download .return_value = f"{ str (tmpdir )} /{ model_name } "
745
747
model : AquaModel = app .register (
746
748
model = model_name ,
747
749
os_path = os_path ,
748
750
local_dir = str (tmpdir ),
749
751
download_from_hf = True ,
752
+ cleanup_model_cache = cleanup_model_cache ,
750
753
allow_patterns = ["*.json" ],
751
754
ignore_patterns = ["test.json" ],
752
755
)
@@ -761,6 +764,20 @@ def test_import_verified_model(
761
764
f"oci os object bulk-upload --src-dir { str (tmpdir )} /{ model_name } --prefix prefix/path/{ model_name } / -bn aqua-bkt -ns aqua-ns --auth api_key --profile DEFAULT --no-overwrite --exclude { HF_METADATA_FOLDER } *"
762
765
)
763
766
)
767
+ if cleanup_model_cache :
768
+ cache_dir = os .path .join (
769
+ os .path .expanduser ("~" ),
770
+ ".cache" ,
771
+ "huggingface" ,
772
+ "hub" ,
773
+ "models--oracle--aqua-1t-mega-model" ,
774
+ )
775
+ assert (
776
+ os .path .exists (f"{ str (tmpdir )} /{ os .path .dirname (model_name )} " )
777
+ is False
778
+ )
779
+ assert os .path .exists (cache_dir ) is False
780
+
764
781
else :
765
782
model : AquaModel = app .register (
766
783
model = "ocid1.datasciencemodel.xxx.xxxx." ,
@@ -1183,22 +1200,22 @@ def test_import_model_with_input_tags(
1183
1200
"model" : "oracle/oracle-1it" ,
1184
1201
"inference_container" : "odsc-vllm-serving" ,
1185
1202
},
1186
- "ads aqua model register --model oracle/oracle-1it --os_path oci://aqua-bkt@aqua-ns/path --download_from_hf True --inference_container odsc-vllm-serving" ,
1203
+ "ads aqua model register --model oracle/oracle-1it --os_path oci://aqua-bkt@aqua-ns/path --download_from_hf True --cleanup_model_cache True -- inference_container odsc-vllm-serving" ,
1187
1204
),
1188
1205
(
1189
1206
{
1190
1207
"os_path" : "oci://aqua-bkt@aqua-ns/path" ,
1191
1208
"model" : "ocid1.datasciencemodel.oc1.iad.<OCID>" ,
1192
1209
},
1193
- "ads aqua model register --model ocid1.datasciencemodel.oc1.iad.<OCID> --os_path oci://aqua-bkt@aqua-ns/path --download_from_hf True" ,
1210
+ "ads aqua model register --model ocid1.datasciencemodel.oc1.iad.<OCID> --os_path oci://aqua-bkt@aqua-ns/path --download_from_hf True --cleanup_model_cache True " ,
1194
1211
),
1195
1212
(
1196
1213
{
1197
1214
"os_path" : "oci://aqua-bkt@aqua-ns/path" ,
1198
1215
"model" : "oracle/oracle-1it" ,
1199
1216
"download_from_hf" : False ,
1200
1217
},
1201
- "ads aqua model register --model oracle/oracle-1it --os_path oci://aqua-bkt@aqua-ns/path --download_from_hf False" ,
1218
+ "ads aqua model register --model oracle/oracle-1it --os_path oci://aqua-bkt@aqua-ns/path --download_from_hf False --cleanup_model_cache True " ,
1202
1219
),
1203
1220
(
1204
1221
{
@@ -1207,7 +1224,7 @@ def test_import_model_with_input_tags(
1207
1224
"download_from_hf" : True ,
1208
1225
"model_file" : "test_model_file" ,
1209
1226
},
1210
- "ads aqua model register --model oracle/oracle-1it --os_path oci://aqua-bkt@aqua-ns/path --download_from_hf True --model_file test_model_file" ,
1227
+ "ads aqua model register --model oracle/oracle-1it --os_path oci://aqua-bkt@aqua-ns/path --download_from_hf True --cleanup_model_cache True -- model_file test_model_file" ,
1211
1228
),
1212
1229
(
1213
1230
{
@@ -1216,7 +1233,7 @@ def test_import_model_with_input_tags(
1216
1233
"inference_container" : "odsc-tei-serving" ,
1217
1234
"inference_container_uri" : "<region>.ocir.io/<your_tenancy>/<your_image>" ,
1218
1235
},
1219
- "ads aqua model register --model oracle/oracle-1it --os_path oci://aqua-bkt@aqua-ns/path --download_from_hf True --inference_container odsc-tei-serving --inference_container_uri <region>.ocir.io/<your_tenancy>/<your_image>" ,
1236
+ "ads aqua model register --model oracle/oracle-1it --os_path oci://aqua-bkt@aqua-ns/path --download_from_hf True --cleanup_model_cache True -- inference_container odsc-tei-serving --inference_container_uri <region>.ocir.io/<your_tenancy>/<your_image>" ,
1220
1237
),
1221
1238
(
1222
1239
{
@@ -1227,7 +1244,7 @@ def test_import_model_with_input_tags(
1227
1244
"defined_tags" : {"dtag1" : "dvalue1" , "dtag2" : "dvalue2" },
1228
1245
},
1229
1246
"ads aqua model register --model oracle/oracle-1it --os_path oci://aqua-bkt@aqua-ns/path "
1230
- "--download_from_hf True --inference_container odsc-vllm-serving --freeform_tags "
1247
+ "--download_from_hf True --cleanup_model_cache True -- inference_container odsc-vllm-serving --freeform_tags "
1231
1248
'{"ftag1": "fvalue1", "ftag2": "fvalue2"} --defined_tags {"dtag1": "dvalue1", "dtag2": "dvalue2"}' ,
1232
1249
),
1233
1250
],
0 commit comments