Skip to content

Commit a3d7cb1

Browse files
authored
[serving] set ai.djl.pytorch.num_interop_threads (#1059)
Change-Id: I9b654322e2b7505dbaa8569b6480a4f5ab19c981
1 parent 45ac6ed commit a3d7cb1

File tree

2 files changed

+4
-3
lines changed

2 files changed

+4
-3
lines changed

api/src/main/java/ai/djl/training/listener/MemoryTrainingListener.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ public static void collectMemoryInfo(Metrics metrics) {
103103

104104
metrics.addMetric("Heap", heapUsed, "bytes");
105105
metrics.addMetric("NonHeap", nonHeapUsed, "bytes");
106-
int gpuCount = Device.getGpuCount();
106+
int gpuCount = CudaUtils.getGpuCount();
107107

108108
// CudaUtils.getGpuMemory() will allocates memory on GPUs if CUDA runtime is not
109109
// initialized.
@@ -138,7 +138,7 @@ public static void dumpMemoryInfo(Metrics metrics, String logDir) {
138138
list.addAll(metrics.getMetric("NonHeap"));
139139
list.addAll(metrics.getMetric("cpu"));
140140
list.addAll(metrics.getMetric("rss"));
141-
int gpuCount = Device.getGpuCount();
141+
int gpuCount = CudaUtils.getGpuCount();
142142
for (int i = 0; i < gpuCount; ++i) {
143143
list.addAll(metrics.getMetric("GPU-" + i));
144144
}

serving/serving/build.gradle

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ run {
4646
systemProperties System.getProperties()
4747
systemProperties.remove("user.dir")
4848
systemProperty("file.encoding", "UTF-8")
49+
systemProperty("ai.djl.pytorch.num_interop_threads", "1")
4950
applicationDefaultJvmArgs = ["-agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=4000"]
5051
}
5152

@@ -56,7 +57,7 @@ startScripts {
5657
text = text.replace('DEFAULT_JVM_OPTS=""', 'if [[ "${MODEL_SERVER_HOME}" = "" ]] ; then\n' +
5758
' export MODEL_SERVER_HOME=${APP_HOME}\n' +
5859
'fi\n' +
59-
'DEFAULT_JVM_OPTS="-Dlog4j.configurationFile=${APP_HOME}/conf/log4j2.xml"\n')
60+
'DEFAULT_JVM_OPTS="-Dai.djl.pytorch.num_interop_threads=1 -Dlog4j.configurationFile=${APP_HOME}/conf/log4j2.xml"\n')
6061
text = text.replaceAll('CLASSPATH=\\$APP_HOME/lib/.*', 'CLASSPATH=\\$APP_HOME/lib/*')
6162
unixScript.text = text
6263
}

0 commit comments

Comments
 (0)