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

forward port of patch in 0.28.0 that terminates a python worker when … #2631

Merged
merged 1 commit into from
Dec 11, 2024
Merged
Show file tree
Hide file tree
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
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@

import ai.djl.Device;
import ai.djl.Model;
import ai.djl.engine.EngineException;
import ai.djl.inference.Predictor;
import ai.djl.modality.Input;
import ai.djl.modality.Output;
Expand Down Expand Up @@ -63,6 +64,10 @@ public PyPredictor(
@Override
@SuppressWarnings("unchecked")
public List<O> batchPredict(List<I> inputs) throws TranslateException {
if (process.isModelUnrecoverable()) {
throw new EngineException(
"Backend Python process is unrecoverable. Initiating worker termination");
}
if (!process.isReady()) {
// TODO: wait for restart
throw new TranslateException("Backend Python process is stopped.");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ class PyProcess {
private CountDownLatch latch;
private volatile boolean started; // NOPMD
private volatile boolean modelLoaded; // NOPMD
private volatile boolean modelUnrecoverable; // NOPMD
private AtomicInteger restartCount;
private CompletableFuture<Void> restartFuture;
private boolean trtLlmMode;
Expand Down Expand Up @@ -147,6 +148,8 @@ Output predict(Input inputs, int timeout, boolean initialLoad) {
if (!initialLoad) {
logger.info("Restart python process ...");
restartFuture = CompletableFuture.runAsync(this::startPythonProcess);
} else {
modelUnrecoverable = true;
}
if (e instanceof EngineException) {
throw (EngineException) e;
Expand Down Expand Up @@ -263,6 +266,10 @@ boolean isReady() {
return started && modelLoaded;
}

boolean isModelUnrecoverable() {
return modelUnrecoverable;
}

private static String[] getHosts(int clusterSize) {
String leaderAddr = Utils.getenv("DJL_LEADER_ADDR");
String workerAddrFormat = Utils.getenv("DJL_WORKER_ADDR_FORMAT");
Expand Down
Loading