Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add fix to workaround SageMaker changes #401

Merged
merged 2 commits into from
Dec 14, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 12 additions & 8 deletions engines/python/src/main/java/ai/djl/python/engine/PyModel.java
Original file line number Diff line number Diff line change
Expand Up @@ -291,6 +291,15 @@ private void createAllPyProcesses(int mpiWorkers) {
}

private void downloadS3(String url) {
// TODO: Workaround on SageMaker readonly disk
String downloadDir = Utils.getenv("SERVING_DOWNLOAD_DIR", "/tmp");
if ("default".equals(downloadDir)) {
downloadDir = modelDir.toAbsolutePath().toString();
}
if (pyEnv.getInitParameters().containsKey("model_id")) {
throw new IllegalArgumentException("model_id and s3url could not both set!");
}
pyEnv.addParameter("model_id", downloadDir);
try {
String[] commands;
if (Files.exists(Paths.get("/opt/djl/bin/s5cmd"))) {
Expand All @@ -301,23 +310,18 @@ private void downloadS3(String url) {
"1",
"sync",
url + "*",
modelDir.toAbsolutePath().toString()
downloadDir
};
} else {
logger.info("s5cmd is not installed, using aws cli");
commands =
new String[] {
"aws", "s3", "sync", url, modelDir.toAbsolutePath().toString()
};
commands = new String[] {"aws", "s3", "sync", url, downloadDir};
}
Process exec = Runtime.getRuntime().exec(commands);
try (InputStream is = exec.getInputStream()) {
logger.debug(Utils.toString(is));
}
exec.waitFor();
logger.info(
String.format(
"Download completed! Files saved to %s", modelDir.toAbsolutePath()));
logger.info("Download completed! Files saved to {}", downloadDir);
} catch (IOException | InterruptedException e) {
throw new EngineException("Model failed to download from s3", e);
}
Expand Down