Skip to content
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
Binary file added testdata/dnn/onnx/data/input_biased_matmul.npy
Binary file not shown.
Binary file added testdata/dnn/onnx/data/output_biased_matmul.npy
Binary file not shown.
26 changes: 26 additions & 0 deletions testdata/dnn/onnx/generate_onnx_models_with_onnxscript.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,13 @@
from onnxscript import opset11
from onnxscript import opset13

###############
### CAUTION!!!
### Be sure to put constant numpy arrays out of @ost.script() decorated fucntion.
### Otherwise random values change each time eager mode is enter.
### See discussions in https://github.com/microsoft/onnxscript/issues/1313
###############

np.random.seed(0)

def make_model_and_data(model, *args, **kwargs):
Expand Down Expand Up @@ -339,3 +346,22 @@ def layer_norm_no_fusion(x: ost.FLOAT[n, c, h, w]) -> ost.FLOAT[n, c, h, w]:

return add
make_model_and_data(layer_norm_no_fusion, np.random.rand(n, c, h, w).astype(np.float32))


''' Subgraph: [Input] -> MatMul<B> -> Add<A> -> [Output]
'''

b = 2
m = 32
n = 64
k = 16
weight_data = np.random.rand(k, n).astype(np.float32)
bias_data = np.random.rand(n).astype(np.float32)

@ost.script()
def biased_matmul(x: ost.FLOAT[b, m, k]) -> ost.FLOAT[b, m, n]:
weight = op.Constant(value=onnx.helper.make_tensor("", onnx.TensorProto.FLOAT, [k, n], weight_data))
matmul = op.MatMul(x, weight)
bias = op.Constant(value=onnx.helper.make_tensor("", onnx.TensorProto.FLOAT, [n], bias_data))
return op.Add(bias, matmul)
make_model_and_data(biased_matmul, np.random.rand(b, m, k).astype(np.float32), use_ort=True, ort_input_keys=["x"])
Binary file added testdata/dnn/onnx/models/biased_matmul.onnx
Binary file not shown.