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

Expose OnnxRuntime's getMetadata() in DJL API #3596

Merged
merged 3 commits into from
Jan 28, 2025
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
11 changes: 11 additions & 0 deletions api/src/main/java/ai/djl/nn/Block.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@
import java.io.DataInputStream;
import java.io.DataOutputStream;
import java.io.IOException;
import java.util.Collections;
import java.util.Map;
import java.util.function.Predicate;

/**
Expand Down Expand Up @@ -353,4 +355,13 @@ static void validateLayout(LayoutType[] expectedLayout, LayoutType[] actualLayou
}
}
}

/**
* Returns a map of all the custom metadata of the block.
*
* @return the map of {@link PairList}
*/
default Map<String, String> getCustomMetadata() {
return Collections.emptyMap();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
import ai.djl.util.PairList;
import ai.onnxruntime.OnnxJavaType;
import ai.onnxruntime.OnnxMap;
import ai.onnxruntime.OnnxModelMetadata;
import ai.onnxruntime.OnnxSequence;
import ai.onnxruntime.OnnxTensor;
import ai.onnxruntime.OnnxValue;
Expand Down Expand Up @@ -128,6 +129,17 @@ public PairList<String, Shape> describeInput() {
return result;
}

/** {@inheritDoc} */
@Override
public Map<String, String> getCustomMetadata() {
try {
OnnxModelMetadata modelMetadata = session.getMetadata();
return modelMetadata.getCustomMetadata();
} catch (OrtException e) {
throw new EngineException(e);
}
}

private NDList evaluateOutput(OrtSession.Result results) {
NDList output = new NDList();
for (Map.Entry<String, OnnxValue> r : results) {
Expand Down
Loading