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

Restrict GPU access from worker to deviceIds #3221

Closed
wants to merge 2 commits into from
Closed
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 @@ -130,16 +130,13 @@ private void startWorkerPython(int port, String deviceIds)
modelPath.getAbsolutePath(),
model.getModelArchive().getManifest().getModel().getHandler())));

if (model.getParallelLevel() > 0) {
if (model.getParallelType() != ParallelType.CUSTOM) {
attachRunner(argl, envp, port, deviceIds);
} else {
if (deviceIds != null) {
envp.add("CUDA_VISIBLE_DEVICES=" + deviceIds);
}
argl.add(EnvironmentUtils.getPythonRunTime(model));
}
} else if (model.getParallelLevel() == 0) {
if (deviceIds != null) {
envp.add("CUDA_VISIBLE_DEVICES=" + deviceIds);
}

if (model.getParallelLevel() > 0 && model.getParallelType() != ParallelType.CUSTOM) {
attachRunner(argl, envp, port, deviceIds);
} else {
argl.add(EnvironmentUtils.getPythonRunTime(model));
}

Expand Down Expand Up @@ -291,9 +288,6 @@ private void startWorkerCPP(int port, String runtimeType, String deviceIds)
private void attachRunner(
ArrayList<String> argl, List<String> envp, int port, String deviceIds) {
envp.add("LOGLEVEL=INFO");
if (deviceIds != null) {
envp.add("CUDA_VISIBLE_DEVICES=" + deviceIds);
}
ModelConfig.TorchRun torchRun = model.getModelArchive().getModelConfig().getTorchRun();
envp.add(String.format("OMP_NUM_THREADS=%d", torchRun.getOmpNumberThreads()));
argl.add("torchrun");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -544,16 +544,20 @@ public void retry() {

protected String getDeviceIds() {
List<Integer> deviceIds;
if (gpuId == -1 || model.getParallelLevel() == 0) {
if (gpuId == -1) {
return null;
} else if (model.isHasCfgDeviceIds()) {
return model.getDeviceIds().subList(gpuId, gpuId + model.getParallelLevel()).stream()
.map(String::valueOf)
.collect(Collectors.joining(","));
} else {
deviceIds = new ArrayList<>(model.getParallelLevel());
for (int i = gpuId; i < gpuId + model.getParallelLevel(); i++) {
deviceIds.add(i);
if (model.getParallelLevel() > 0) {
for (int i = gpuId; i < gpuId + model.getParallelLevel(); i++) {
deviceIds.add(i);
}
} else {
deviceIds.add(gpuId);
}
return deviceIds.stream().map(String::valueOf).collect(Collectors.joining(","));
}
Expand Down
Loading