Skip to content
This repository was archived by the owner on Aug 7, 2025. It is now read-only.

Commit 3917407

Browse files
authored
workaround solution for SageMaker (#2405)
1 parent 253f8a3 commit 3917407

File tree

1 file changed

+15
-2
lines changed

1 file changed

+15
-2
lines changed

frontend/archive/src/main/java/org/pytorch/serve/archive/model/ModelArchive.java

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -80,15 +80,28 @@ public static ModelArchive downloadModel(
8080
}
8181
}
8282

83-
if (new File(url).isDirectory()) {
83+
File directory = new File(url);
84+
if (directory.isDirectory()) {
8485
// handle the case that the input url is a directory.
8586
// the input of url is "/xxx/model_store/modelXXX" or
8687
// "xxxx/yyyyy/modelXXX".
87-
return load(url, new File(url), false);
88+
File[] fileList = directory.listFiles();
89+
if (fileList.length == 1 && fileList[0].isDirectory()) {
90+
// handle the case that a model tgz file
91+
// has root dir after decompression on SageMaker
92+
return load(url, fileList[0], false);
93+
}
94+
return load(url, directory, false);
8895
} else if (modelLocation.exists()) {
8996
// handle the case that "/xxx/model_store/modelXXX" is directory.
9097
// the input of url is modelXXX when torchserve is started
9198
// with snapshot or with parameter --models modelXXX
99+
File[] fileList = modelLocation.listFiles();
100+
if (fileList.length == 1 && fileList[0].isDirectory()) {
101+
// handle the case that a model tgz file
102+
// has root dir after decompression on SageMaker
103+
return load(url, fileList[0], false);
104+
}
92105
return load(url, modelLocation, false);
93106
}
94107

0 commit comments

Comments
 (0)