Skip to content

Commit

Permalink
[pytorch] expose IValue for custom input data type (#1195)
Browse files Browse the repository at this point in the history
Change-Id: Ifdbf35297073d9f105e6819bd632c77df4782940
  • Loading branch information
frankfliu authored Aug 30, 2021
1 parent 887bc6f commit 480f686
Show file tree
Hide file tree
Showing 11 changed files with 926 additions and 311 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ libs
*.dylib
*.dll
*.class
*.log

# Eclipse
.settings
Expand Down
2 changes: 1 addition & 1 deletion pytorch/pytorch-engine/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,11 @@ processResources {
]
def classesDir = "${project.buildDir}/jnilib"
files.each { entry ->
project.logger.lifecycle("Downloading ${url}/${entry.key}")
def file = new File("${classesDir}/${entry.value}")
if (file.exists()) {
project.logger.lifecycle("prebuilt or cached file found for ${entry.value}")
} else {
project.logger.lifecycle("Downloading ${url}/${entry.key}")
file.getParentFile().mkdirs()
new URL("${url}/${entry.key}").withInputStream { i -> file.withOutputStream { it << i } }
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import ai.djl.ndarray.types.Shape;
import ai.djl.nn.AbstractSymbolBlock;
import ai.djl.nn.SymbolBlock;
import ai.djl.pytorch.jni.IValue;
import ai.djl.pytorch.jni.IValueUtils;
import ai.djl.pytorch.jni.JniUtils;
import ai.djl.training.ParameterStore;
Expand Down Expand Up @@ -88,6 +89,16 @@ public void close() {
}
}

/**
* Runs the forward of this PyTorch module.
*
* @param inputs the input {@link IValue}
* @return the result {@link IValue}
*/
public IValue forward(IValue... inputs) {
return IValueUtils.forward(this, inputs);
}

/** {@inheritDoc} */
@Override
protected NDList forwardInternal(
Expand Down
Loading

0 comments on commit 480f686

Please sign in to comment.