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

Avoid load default engine if not being used #1136

Merged
merged 1 commit into from
Aug 2, 2021
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
9 changes: 9 additions & 0 deletions api/src/main/java/ai/djl/engine/Engine.java
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,15 @@ private static synchronized String initEngine() {
*/
public abstract int getRank();

/**
* Returns the default Engine name.
*
* @return the default Engine name
*/
public static String getDefaultEngineName() {
return DEFAULT_ENGINE;
}

/**
* Returns the default Engine.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
*/
package ai.djl.modality.cv.util;

import ai.djl.engine.Engine;
import ai.djl.modality.cv.Image;
import ai.djl.ndarray.NDArray;
import ai.djl.ndarray.types.Shape;
Expand Down Expand Up @@ -109,7 +108,7 @@ public static NDArray normalize(NDArray input, float mean, float std) {
*/
public static NDArray normalize(NDArray input, float[] mean, float[] std) {
boolean chw = isCHW(input.getShape());
boolean tf = "TensorFlow".equals(Engine.getInstance().getEngineName());
boolean tf = "TensorFlow".equals(input.getManager().getEngine().getEngineName());
if ((chw && tf) || (!chw && !tf)) {
throw new IllegalArgumentException(
"normalize requires CHW format. TensorFlow requires HWC");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ public <I, O> ZooModel<I, O> loadModel(Criteria<I, O> criteria)
// Otherwise check the modelzoo supported engine and grab a random engine in the list.
// Otherwise if none of them is specified or model zoo is null, go to default engine.
if (engine == null && modelZoo != null) {
String defaultEngine = Engine.getInstance().getEngineName();
String defaultEngine = Engine.getDefaultEngineName();
for (String supportedEngine : modelZoo.getSupportedEngines()) {
if (supportedEngine.equals(defaultEngine)) {
engine = supportedEngine;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -158,8 +158,9 @@ public void onTrainingBegin(Trainer trainer) {
logger.info("Training on: {}.", devicesMsg);

long init = System.nanoTime();
String engineName = Engine.getInstance().getEngineName();
String version = Engine.getInstance().getVersion();
Engine engine = trainer.getManager().getEngine();
String engineName = engine.getEngineName();
String version = engine.getVersion();
long loaded = System.nanoTime();
logger.info(
String.format(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ public class Arguments {
if (cmd.hasOption("engine")) {
engine = cmd.getOptionValue("engine");
} else {
engine = Engine.getInstance().getEngineName();
engine = Engine.getDefaultEngineName();
}

if (cmd.hasOption("duration")) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,6 @@ public String getGroupId() {
/** {@inheritDoc} */
@Override
public Set<String> getSupportedEngines() {
return Collections.singleton(Engine.getInstance().getEngineName());
return Collections.singleton(Engine.getDefaultEngineName());
}
}