Skip to content

Commit b80329c

Browse files
authored
Fix model names with same sub-prefix (#1745)
1 parent acf6e04 commit b80329c

File tree

2 files changed

+27
-15
lines changed

2 files changed

+27
-15
lines changed

pkg/cortex/serve/cortex_internal/lib/api/predictor.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -551,7 +551,7 @@ def model_downloader(
551551
return None
552552

553553
# validate model
554-
model_contents = glob.glob(temp_dest + "*/**", recursive=True)
554+
model_contents = glob.glob(os.path.join(temp_dest, "**"), recursive=True)
555555
model_contents = util.remove_non_empty_directory_paths(model_contents)
556556
try:
557557
validate_model_paths(model_contents, predictor_type, temp_dest)

pkg/cortex/serve/cortex_internal/lib/model/cron.py

Lines changed: 26 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -348,7 +348,9 @@ def _refresh_model(
348348
update_model = False
349349
ondisk_model_version_path = os.path.join(ondisk_model_path, version)
350350
if os.path.exists(ondisk_model_version_path):
351-
local_paths = glob.glob(ondisk_model_version_path + "*/**", recursive=True)
351+
local_paths = glob.glob(
352+
os.path.join(ondisk_model_version_path, "**"), recursive=True
353+
)
352354
local_paths = util.remove_non_empty_directory_paths(local_paths)
353355
local_paths = [
354356
os.path.relpath(local_path, ondisk_model_version_path)
@@ -385,7 +387,7 @@ def _refresh_model(
385387
client.download_dir_contents(cloud_src, temp_dest)
386388

387389
# validate the downloaded model
388-
model_contents = glob.glob(temp_dest + "*/**", recursive=True)
390+
model_contents = glob.glob(os.path.join(temp_dest, "**"), recursive=True)
389391
model_contents = util.remove_non_empty_directory_paths(model_contents)
390392
try:
391393
validate_model_paths(model_contents, self._predictor_type, temp_dest)
@@ -419,7 +421,7 @@ def _refresh_model(
419421
# except when the model version found on disk is 1 and the number of detected versions on the upstream is 0,
420422
# thus indicating the 1-version on-disk model must be a model that came without a version
421423
if os.path.exists(ondisk_model_path):
422-
ondisk_model_versions = glob.glob(ondisk_model_path + "*/**")
424+
ondisk_model_versions = glob.glob(os.path.join(ondisk_model_path, "**"))
423425
ondisk_model_versions = [
424426
os.path.relpath(path, ondisk_model_path) for path in ondisk_model_versions
425427
]
@@ -434,7 +436,7 @@ def _refresh_model(
434436
f.write("not-available")
435437

436438
# remove the model directory if there are no models left
437-
if len(glob.glob(ondisk_model_path + "*/**")) == 0:
439+
if len(glob.glob(os.path.join(ondisk_model_path, "**"))) == 0:
438440
shutil.rmtree(ondisk_model_path)
439441

440442
# if it's a non-versioned model ModelVersion.NOT_PROVIDED
@@ -448,7 +450,9 @@ def _refresh_model(
448450
update_model = False
449451
ondisk_model_version_path = os.path.join(ondisk_model_path, "1")
450452
if os.path.exists(ondisk_model_version_path):
451-
local_paths = glob.glob(ondisk_model_version_path + "*/**", recursive=True)
453+
local_paths = glob.glob(
454+
os.path.join(ondisk_model_version_path, "**"), recursive=True
455+
)
452456
local_paths = util.remove_non_empty_directory_paths(local_paths)
453457
local_paths = [
454458
os.path.relpath(local_path, ondisk_model_version_path)
@@ -486,7 +490,7 @@ def _refresh_model(
486490
client.download_dir_contents(model_path, temp_dest)
487491

488492
# validate the downloaded model
489-
model_contents = glob.glob(temp_dest + "*/**", recursive=True)
493+
model_contents = glob.glob(os.path.join(temp_dest, "**"), recursive=True)
490494
model_contents = util.remove_non_empty_directory_paths(model_contents)
491495
try:
492496
validate_model_paths(model_contents, self._predictor_type, temp_dest)
@@ -973,7 +977,9 @@ def _refresh_model(
973977
update_model = False
974978
ondisk_model_version_path = os.path.join(ondisk_model_path, version)
975979
if os.path.exists(ondisk_model_version_path):
976-
local_paths = glob.glob(ondisk_model_version_path + "*/**", recursive=True)
980+
local_paths = glob.glob(
981+
os.path.join(ondisk_model_version_path, "**"), recursive=True
982+
)
977983
local_paths = util.remove_non_empty_directory_paths(local_paths)
978984
local_paths = [
979985
os.path.relpath(local_path, ondisk_model_version_path)
@@ -1004,7 +1010,7 @@ def _refresh_model(
10041010
client.download_dir_contents(cloud_src, temp_dest)
10051011

10061012
# validate the downloaded model
1007-
model_contents = glob.glob(temp_dest + "*/**", recursive=True)
1013+
model_contents = glob.glob(os.path.join(temp_dest, "**"), recursive=True)
10081014
model_contents = util.remove_non_empty_directory_paths(model_contents)
10091015
try:
10101016
validate_model_paths(model_contents, self._predictor_type, temp_dest)
@@ -1036,7 +1042,7 @@ def _refresh_model(
10361042
# except when the model version found on disk is 1 and the number of detected versions on the upstream is 0,
10371043
# thus indicating the 1-version on-disk model must be a model that came without a version
10381044
if os.path.exists(ondisk_model_path):
1039-
ondisk_model_versions = glob.glob(ondisk_model_path + "*/**")
1045+
ondisk_model_versions = glob.glob(os.path.join(ondisk_model_path, "**"))
10401046
ondisk_model_versions = [
10411047
os.path.relpath(path, ondisk_model_path) for path in ondisk_model_versions
10421048
]
@@ -1045,7 +1051,7 @@ def _refresh_model(
10451051
ondisk_model_version_path = os.path.join(ondisk_model_path, ondisk_version)
10461052
shutil.rmtree(ondisk_model_version_path)
10471053

1048-
if len(glob.glob(ondisk_model_path + "*/**")) == 0:
1054+
if len(glob.glob(os.path.join(ondisk_model_path, "**"))) == 0:
10491055
shutil.rmtree(ondisk_model_path)
10501056

10511057
# if it's a non-versioned model ModelVersion.NOT_PROVIDED
@@ -1057,7 +1063,9 @@ def _refresh_model(
10571063
update_model = False
10581064
ondisk_model_version_path = os.path.join(ondisk_model_path, "1")
10591065
if os.path.exists(ondisk_model_version_path):
1060-
local_paths = glob.glob(ondisk_model_version_path + "*/**", recursive=True)
1066+
local_paths = glob.glob(
1067+
os.path.join(ondisk_model_version_path, "**"), recursive=True
1068+
)
10611069
local_paths = util.remove_non_empty_directory_paths(local_paths)
10621070
local_paths = [
10631071
os.path.relpath(local_path, ondisk_model_version_path)
@@ -1090,7 +1098,7 @@ def _refresh_model(
10901098
client.download_dir_contents(model_path, temp_dest)
10911099

10921100
# validate the downloaded model
1093-
model_contents = glob.glob(temp_dest + "*/**", recursive=True)
1101+
model_contents = glob.glob(os.path.join(temp_dest, "**"), recursive=True)
10941102
model_contents = util.remove_non_empty_directory_paths(model_contents)
10951103
try:
10961104
validate_model_paths(model_contents, self._predictor_type, temp_dest)
@@ -1574,7 +1582,9 @@ def _make_local_models_available(self):
15741582
ondisk_model_version_path = os.path.join(
15751583
self._ondisk_models_dir, model_name, model_version
15761584
)
1577-
ondisk_paths = glob.glob(ondisk_model_version_path + "*/**", recursive=True)
1585+
ondisk_paths = glob.glob(
1586+
os.path.join(ondisk_model_version_path, "**"), recursive=True
1587+
)
15781588
ondisk_paths = util.remove_non_empty_directory_paths(ondisk_paths)
15791589
# removable is set to false to prevent the local models from being removed
15801590
self._tree.update_model(
@@ -1592,7 +1602,9 @@ def _make_local_models_available(self):
15921602
ondisk_model_version_path = os.path.join(
15931603
self._ondisk_models_dir, model_name, model_version
15941604
)
1595-
ondisk_paths = glob.glob(ondisk_model_version_path + "*/**", recursive=True)
1605+
ondisk_paths = glob.glob(
1606+
os.path.join(ondisk_model_version_path, "**"), recursive=True
1607+
)
15961608
ondisk_paths = util.remove_non_empty_directory_paths(ondisk_paths)
15971609
# removable is set to false to prevent the local models from being removed
15981610
self._tree.update_model(

0 commit comments

Comments
 (0)