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

Initializers through arguments #340

Closed
wants to merge 36 commits into from
Closed
Changes from 1 commit
Commits
Show all changes
36 commits
Select commit Hold shift + click to select a range
85ab4c5
passing Arena instances to tensor construction and Session run
asotona Mar 4, 2025
58db6d0
Merge remote-tracking branch 'babylon/code-reflection' into arenas-cont
asotona Mar 4, 2025
3d33898
using Arena.ofConfined() instance for each individual test in CNNTest
asotona Mar 4, 2025
9bd3711
more explicit arena use
asotona Mar 4, 2025
52f1804
releasing tensors
asotona Mar 4, 2025
6be0856
tensor construction moved to runtime
asotona Mar 4, 2025
b974d53
CNNTest cleanup
asotona Mar 4, 2025
b97afd8
Caching live sessions insted of proto models
asotona Mar 4, 2025
0c81d1f
Merge remote-tracking branch 'babylon/code-reflection' into loops-cont
asotona Mar 5, 2025
7dc9e16
OnnxOps.If implementation - work in progress
asotona Mar 5, 2025
634a9ba
OnnxOps.If implementation - work in progress
asotona Mar 5, 2025
023d64c
OnnxOps.If implementation - work in progress
asotona Mar 5, 2025
4a683b9
extracted LambdaToFunc from OnnxRuntime for use also in OnnxPartialEv…
asotona Mar 5, 2025
98a4509
OnnxOps.If implementation - work in progress
asotona Mar 5, 2025
8f476dd
OnnxOps.If implementation - work on captured inputs of subgraphs in p…
asotona Mar 5, 2025
a47bd5c
proposed changes applied
asotona Mar 6, 2025
18447d3
sealed ExplicitOnnxOps
asotona Mar 6, 2025
f2745df
Fixed captured tensors in If op model
asotona Mar 6, 2025
2a5c91d
improved SimpleTest
asotona Mar 6, 2025
3ba687f
removed debug print
asotona Mar 6, 2025
188de63
initializers as parameters prefix
asotona Mar 7, 2025
83b0354
initializers through arguments - work in progress
asotona Mar 7, 2025
d9f45a8
Removed Reshape from CNNTest to avoid model Conv exception when used …
asotona Mar 7, 2025
0345add
re-enable tests
asotona Mar 7, 2025
0ed099d
removed obsolete test
asotona Mar 7, 2025
5843369
MNISTDemo using initializers
asotona Mar 7, 2025
a796b23
removed obsolete imports and comment
asotona Mar 7, 2025
dbf678a
minor demo rearrangement
asotona Mar 7, 2025
acc2144
initializers from fields
asotona Mar 9, 2025
384ee27
raw implemenation of instance methods and instance initializers
asotona Mar 10, 2025
35dfef7
Minor demo cleanup
asotona Mar 10, 2025
08bd631
MNISTDemoUI rename
asotona Mar 10, 2025
d885df1
nit change
asotona Mar 10, 2025
5a0213f
OnnxProtoBuilder and OnnxProtoPrinter implemented support for packed …
asotona Mar 10, 2025
ee1fbaf
added DEBUG switch to OnnxRuntime with models print and export
asotona Mar 10, 2025
001dea5
nit change
asotona Mar 10, 2025
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
8 changes: 8 additions & 0 deletions cr-examples/onnx/src/main/java/oracle/code/onnx/Tensor.java
Original file line number Diff line number Diff line change
@@ -146,6 +146,14 @@ public static Tensor<Float> ofShape(Arena arena, long[] shape, float... values)
return new Tensor(arena, arena.allocateFrom(ValueLayout.JAVA_FLOAT, values), ElementType.FLOAT, shape);
}

public static <T> Tensor<T> ofShape(long[] shape, byte[] rawData, ElementType elementType) {
return ofShape(Arena.ofAuto(), shape, rawData, elementType);
}

public static <T> Tensor<T> ofShape(Arena arena, long[] shape, byte[] rawData, ElementType elementType) {
return new Tensor(arena, arena.allocateFrom(ValueLayout.JAVA_BYTE, rawData), elementType, shape);
}

// Mandatory reference to dataAddr to avoid its garbage colletion
private final MemorySegment dataAddr;
final MemorySegment tensorAddr;
Original file line number Diff line number Diff line change
@@ -23,13 +23,11 @@

package oracle.code.onnx.mnist;

import jdk.incubator.code.CodeReflection;

import java.io.*;
import java.io.IOException;
import java.lang.foreign.Arena;
import java.lang.foreign.MemorySegment;
import java.lang.foreign.ValueLayout;
import java.lang.invoke.MethodHandles;
import jdk.incubator.code.CodeReflection;
import oracle.code.onnx.OnnxRuntime;
import oracle.code.onnx.Tensor;

@@ -42,11 +40,9 @@ public class MNISTModel {
static final int IMAGE_SIZE = 28;
static final long[] IMAGE_SHAPE = new long[]{1, 1, IMAGE_SIZE, IMAGE_SIZE};

private static Tensor<Float> initialize(String resource, long... shape) {
private static Tensor<Float> initialize(String resource, long... shape) throws IOException {
try (var in = MNISTModel.class.getResourceAsStream(resource)) {
return Tensor.ofShape(shape, MemorySegment.ofArray(in.readAllBytes()).toArray(ValueLayout.JAVA_FLOAT_UNALIGNED));
} catch (IOException e) {
throw new UncheckedIOException(e);
return Tensor.ofShape(shape, in.readAllBytes(), Tensor.ElementType.FLOAT);
}
}

@@ -61,7 +57,7 @@ private static Tensor<Float> initialize(String resource, long... shape) {
final Tensor<Float> fc3Weights;
final Tensor<Float> fc3Biases;

MNISTModel() {
MNISTModel() throws IOException {
conv1Weights = initialize("conv1-weight-float-le", 6, 1, 5, 5);
conv1Biases = initialize("conv1-bias-float-le", 6);
conv2Weights = initialize("conv2-weight-float-le", 16, 6, 5, 5);