repo stringclasses 454
values | file_path stringlengths 5 201 | extension stringclasses 1
value | content stringlengths 8 509k | num_lines int64 3 16.9k | size_bytes int64 8 511k |
|---|---|---|---|---|---|
onnxruntime | onnxruntime/test/testdata/coreml_argmax_cast_test.py | .py | import onnx
from onnx import TensorProto, helper
# CoreML EP currently handles a special case for supporting ArgMax followed by a Cast to int32.
# Please see <repo_root>/onnxruntime/core/providers/coreml/builders/impl/argmax_op_builder.cc and
# <repo_root>/onnxruntime/core/providers/coreml/builders/impl/cast_op_builde... | 36 | 1,328 |
onnxruntime | onnxruntime/test/testdata/test_shape_data_propagation_gather_mul_topk.py | .py | # Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the MIT License.
# Regression fixture for the Shape -> Gather(1-D index) -> Mul -> TopK chain.
#
# This exercises the elementwise data-propagation consumers (Mul) with rank-1
# single-element operands. Both Gather indices are 1-D constants, s... | 63 | 3,053 |
onnxruntime | onnxruntime/test/testdata/add_mul_add.py | .py | from onnx import TensorProto, checker, helper, save
# (A + B) * B + A
graph_proto = helper.make_graph(
nodes=[
helper.make_node(
"Add",
inputs=["A", "B"],
outputs=["add_output"],
name="add_0",
),
helper.make_node(
"Mul",
... | 38 | 963 |
onnxruntime | onnxruntime/test/testdata/matmul_with_dynamic_input_shape.py | .py | from pathlib import Path
import onnx
from onnx import TensorProto, helper
# This model contains a MatMul where:
# - A has shape [M, K] and `M` is a dynamic dimension.
# - B is an initializer with shape [K, N].
# - This is important for the CoreML EP which only handles the case where B is an initializer.
# M is dyn... | 35 | 1,018 |
onnxruntime | onnxruntime/test/testdata/invalid_dim_param_value_repetition.py | .py | """
Run this script to recreate the original onnx model.
Example usage:
python invalid_dim_param_value_repetition.py
"""
import numpy as np
import onnx
def order_repeated_field(repeated_proto, key_name, order):
order = list(order)
repeated_proto.sort(key=lambda x: order.index(getattr(x, key_name)))
def mak... | 71 | 3,040 |
onnxruntime | onnxruntime/test/testdata/model_with_external_initializers.py | .py | # Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the MIT License.
import os
import numpy as np
import onnx
from onnx import TensorProto, helper
from onnx.external_data_helper import set_external_data
from onnx.numpy_helper import from_array
def create_external_data_tensor(value, tensor_n... | 78 | 2,466 |
onnxruntime | onnxruntime/test/testdata/test_kernel_info_get_const_input.py | .py | import onnx
from onnx import TensorProto, helper
def GenerateModel(model_name): # noqa: N802
initializers = [
helper.make_tensor(
"weight",
TensorProto.FLOAT,
[1, 4],
[1.0, 2.0, 3.0, 4.0],
),
]
nodes = [
helper.make_node(
... | 43 | 953 |
onnxruntime | onnxruntime/test/testdata/dummy_t5_model_generator.py | .py | """Script to generate a dummy ONNX model emulating T5 model with BeamSearch op."""
import argparse
import numpy as np
import onnx
import onnxruntime as ort
from onnxruntime.transformers.convert_generation import move_initializers
def create_model(
vocab_size: int,
embed_dim: int,
num_heads: int,
he... | 378 | 16,008 |
onnxruntime | onnxruntime/test/testdata/ep_partitioning_tests.py | .py | import onnx
from onnx import TensorProto, helper
# Create graph with Add and Sub nodes that can be used to test partitioning when one of the operators
# can run using the test EP and the other cannot.
# As the operators take 2 inputs and produce one output we can easily create edges to test different scenarios
def cr... | 109 | 4,507 |
onnxruntime | onnxruntime/test/testdata/capi_symbolic_dims.py | .py | import onnx
from onnx import TensorProto, helper, shape_inference
# create output with rank but unnamed symbolic dim
output = helper.make_tensor_value_info("C", TensorProto.FLOAT, [1])
output.type.tensor_type.shape.Clear()
dim = output.type.tensor_type.shape.dim.add()
print(dim)
graph_def = helper.make_graph(
nod... | 37 | 1,151 |
onnxruntime | onnxruntime/test/testdata/test_shape_data_propagation_with_shape_related_nodes.py | .py | import onnx
from onnx import TensorProto, helper
# 1. Define graph input with symbolic shape ['batch', 3, 'width', 'height']
input_tensor = helper.make_tensor_value_info("input", TensorProto.FLOAT, ["batch", 3, "width", "height"])
# 2. Define intermediate and output tensors
shape_out = helper.make_tensor_value_info("... | 54 | 1,932 |
onnxruntime | onnxruntime/test/testdata/test_arbitrary_external_file.py | .py | import onnx
from onnx import TensorProto, helper
def create_exp_model():
inputs = []
nodes = []
tensors = []
outputs = []
# Create input tensor info
input_ = helper.make_tensor_value_info("input", TensorProto.INT64, [None])
inputs.append(input_)
# Create malicious tensor with externa... | 55 | 1,689 |
onnxruntime | onnxruntime/test/testdata/30_nested_loops.py | .py | import os
import tempfile
import onnx
from onnx import TensorProto, helper
import onnxruntime as ort
def make_nested_loop(depth):
if depth == 0:
body = helper.make_graph(
[
helper.make_node("Identity", ["cond_in"], ["cond_out"]),
helper.make_node("Identity", [... | 70 | 2,210 |
onnxruntime | onnxruntime/test/testdata/make_conv_default_attrs.py | .py | # Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the MIT License.
import numpy as np
import onnx
def main():
inp_shape = (1, 2, 8, 8)
input_0 = onnx.helper.make_tensor_value_info("input_0", onnx.TensorProto.FLOAT, inp_shape)
output_0 = onnx.helper.make_tensor_value_info("outpu... | 37 | 1,276 |
onnxruntime | onnxruntime/test/testdata/ep_dynamic_graph_input_test.py | .py | import onnx
from onnx import TensorProto, helper
# Since NNAPI EP does not support dynamic shape input and we now switch from the approach of immediately rejecting
# the whole graph in NNAPI EP if it has a dynamic input to checking the dynamic shape at individual operator support check level,
# We have a separated te... | 47 | 1,648 |
onnxruntime | onnxruntime/test/testdata/scan_mul.py | .py | from onnx import TensorProto, checker, helper, save, shape_inference
# Scan body: y_t = x_t * 2.0
scan_body = helper.make_graph(
nodes=[
helper.make_node(
"Mul",
inputs=["x_t", "ConstTwo"],
outputs=["y_t"],
name="mul_0",
),
],
name="scan_body"... | 52 | 1,300 |
onnxruntime | onnxruntime/test/testdata/node_output_not_used.py | .py | import onnx
from onnx import TensorProto, helper
def create_model_with_node_output_not_used(model_path):
# Create graph
x = helper.make_tensor_value_info("X", TensorProto.FLOAT, [3, 2])
w = helper.make_tensor_value_info("W", TensorProto.FLOAT, [2, 3])
y = helper.make_tensor_value_info("Y", TensorProto... | 44 | 1,161 |
onnxruntime | onnxruntime/test/testdata/abs_0d_lostdim.py | .py | """
Run this script to recreate the original onnx model.
Example usage:
python abs_0d_lostdim.py out_model_path.onnx
"""
import sys
import onnx
from onnx import TensorProto, helper
def order_repeated_field(repeated_proto, key_name, order):
order = list(order)
repeated_proto.sort(key=lambda x: order.index(ge... | 55 | 1,788 |
onnxruntime | onnxruntime/test/testdata/test_shape_data_propagation_gather_topk.py | .py | # Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the MIT License.
# Regression fixture for the Shape -> Gather(1-D index) -> TopK rank-drop.
#
# The Gather index here is the 1-D constant [-1] (rank 1), so per ONNX Gather
# semantics (output_rank = data_rank - 1 + indices_rank) the Gather ou... | 55 | 2,395 |
onnxruntime | onnxruntime/test/testdata/gh_issue_29071_if_constant_folding.py | .py | #!/usr/bin/env python3
"""Standalone minimal problem for minimal_repro.onnx — the ORT 1.26 ConstantFolding
HasExternalDataInMemory reproducer. Generated from the model; run to recreate
an identical file.
python3 onnxruntime/test/testdata/gh_issue_29071_if_constant_folding.py [out.onnx]
"""
import sys
import nump... | 389 | 13,007 |
onnxruntime | onnxruntime/test/testdata/matmul_integer_to_float.py | .py | import numpy as np
import onnx
from onnx import TensorProto, helper, numpy_helper
def generate_model(
model_name, sign_i, sign_w, output_type_fp16, has_zp=True, bias=False, bias_initializer=False, bias_flip=False
):
nodes = [ # subgraph
helper.make_node(
"MatMulInteger",
["A",... | 137 | 4,631 |
onnxruntime | onnxruntime/test/testdata/test_shape_data_propagation_with_shape_related_nodes_v3.py | .py | import onnx
from onnx import TensorProto, helper
# === Graph input/output ===
input_tensor = helper.make_tensor_value_info("input", TensorProto.FLOAT, ["batch", 3, "width", "height"])
output_tensor = helper.make_tensor_value_info("output", TensorProto.FLOAT, ["batch", 3, "width*height"])
# === Initializers ===
B = he... | 110 | 3,774 |
onnxruntime | onnxruntime/test/testdata/packed_attention_fp16.rbp.py | .py | """
Run this script to recreate the original onnx model.
Example usage:
python packed_attention_fp16.model.py out_model_path.onnx
"""
import sys
import numpy as np
import onnx
from onnx import TensorProto, helper, numpy_helper
def clear_field(proto, field):
proto.ClearField(field)
return proto
def order_r... | 132 | 4,801 |
onnxruntime | onnxruntime/test/testdata/sub_mul_sub.py | .py | from onnx import TensorProto, checker, helper, save
# (A - B) * B - A
graph_proto = helper.make_graph(
nodes=[
helper.make_node(
"Sub",
inputs=["A", "B"],
outputs=["sub_output"],
name="sub_0",
),
helper.make_node(
"Mul",
... | 38 | 963 |
onnxruntime | onnxruntime/test/testdata/topk_and_multiple_graph_outputs.py | .py | import onnx
from onnx import TensorProto, helper
def create_model_with_topk_graph_output(model_path):
# ======================
# ---- Inputs ----
# ======================
input_tensor = helper.make_tensor_value_info("input", TensorProto.FLOAT, ["N"])
# ======================
# ---- Initialize... | 79 | 2,399 |
onnxruntime | onnxruntime/test/testdata/make_qdq_layout_transform_const_folding.py | .py | # Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the MIT License.
import numpy as np
import onnx
import onnxruntime
from onnxruntime.quantization import CalibrationDataReader, QuantFormat, QuantType, quantize_static
from onnxruntime.quantization.shape_inference import quant_pre_process
c... | 110 | 4,185 |
onnxruntime | onnxruntime/test/testdata/webgpu_pow_cast_test.py | .py | import onnx
from onnx import TensorProto, helper
# tests fix for precision error in florence2 model by using WebGPU built-in sqrt(x) function instead of pow(x, y) when the exponent is 0.5.
# The sqrt(x) built-in is both faster and more stable than using pow(x, 0.5).
# Example:
# Cast: input = 576 (int), output = 576 (... | 41 | 1,183 |
onnxruntime | onnxruntime/test/testdata/nnapi_internal_uint8_support.py | .py | import onnx
from onnx import TensorProto, helper
# This is to test the operators without "Qlinear" support but still support uint8 input
# These operators need to be internal to a graph/partition
# def GenerateModel(model_name):
def GenerateModel(model_name): # noqa: N802
nodes = [
helper.make_node(
... | 68 | 1,796 |
onnxruntime | onnxruntime/test/testdata/test_shape_data_propagation_unsqueeze_inmemory_int64.py | .py | import onnx
axis_count = 16
input_tensor = onnx.helper.make_tensor_value_info("input", onnx.TensorProto.FLOAT, [1] * axis_count)
output_tensor = onnx.helper.make_tensor_value_info("output", onnx.TensorProto.INT64, [1] * axis_count + [axis_count])
shape_node = onnx.helper.make_node("Shape", ["input"], ["shape_out"])
i... | 25 | 1,102 |
onnxruntime | onnxruntime/test/testdata/squeeze_mul_relu.py | .py | from onnx import TensorProto, checker, helper, save, shape_inference
# A --> Squeeze --> Mul --> Relu --> Mul(2x) --> C
# ^
# |
# B ----------------+
graph_proto = helper.make_graph(
nodes=[
helper.make_node(
"Squeeze",
inputs=["A"],
o... | 51 | 1,411 |
onnxruntime | onnxruntime/test/testdata/make_transpose_optimizer_per_axis_qdq_models.py | .py | # Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the MIT License.
import numpy as np
import onnx
def subgraph_1d_const_input_dq(inputs, initializers, nodes) -> str:
"""
Creates mul_weight -> DQ. mul_weight is a constant of rank 1.
"""
mul_weight_i8_data = np.array([1, 2, 3... | 208 | 6,871 |
onnxruntime | onnxruntime/test/testdata/input_propagated_to_output.py | .py | """
Run this script to recreate the original onnx model.
Example usage:
python input_propagated_to_output.py input_propagated_to_output.onnx
"""
import sys
import numpy as np
import onnx
def order_repeated_field(repeated_proto, key_name, order):
order = list(order)
repeated_proto.sort(key=lambda x: order.in... | 114 | 4,166 |
onnxruntime | onnxruntime/test/testdata/model_with_external_initializer_come_from_user.py | .py | # Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the MIT License.
import numpy as np
import onnx
from onnx import TensorProto, helper
from onnx.external_data_helper import set_external_data
from onnx.numpy_helper import from_array
def create_external_data_tensor(value, tensor_name): # ty... | 61 | 2,069 |
onnxruntime | onnxruntime/test/testdata/test_shape_data_propagation_decline_combined.py | .py | # Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the MIT License.
# Combined lock fixture for the two custom data-propagation DECLINE paths guarded by
# microsoft/onnxruntime#29072, exercised through a SINGLE shared graph so the regression
# is covered by one onnxruntime::Model::Load instea... | 97 | 5,928 |
onnxruntime | onnxruntime/test/testdata/icm-31000000518483.py | .py | from onnx import TensorProto, helper, save_model
# Add node with a subgraph that has no inputs or outputs.
# Graph::BuildConnections should remove and the list of subgraphs in Graph::Resolve should be updated.
# Other details here don't matter. Copied from ort_github_issue_10305.py
if_body = helper.make_graph(
[
... | 54 | 1,613 |
onnxruntime | onnxruntime/test/testdata/mobilenet_v3_small_excerpt_gen.py | .py | """
Run this script to recreate the original onnx model.
Example usage:
python mobilenet_v3_small_excerpt_gen.py out_model_path.onnx
The excerpt model and this script were generated from a full model by first extracting the excerpt with
onnx.utils.extract_model [1] and then generating the python script from the excerp... | 126 | 5,062 |
onnxruntime | onnxruntime/test/testdata/make_transpose_optimizer_empty_dq_q_at_output_model.py | .py | # Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the MIT License.
import numpy as np
import onnx
def make_model(model_path: str):
"""
Creates a QDQ model with a (DQ -> Transpose -> Q -> GRAPH OUTPUT) sequence. The Transpose is optimized out
and the TransposeOptimizer should al... | 118 | 4,128 |
onnxruntime | onnxruntime/test/testdata/trt_reshape_test.py | .py | #!/usr/bin/env python3
# Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the MIT License.
import onnx
from onnx import TensorProto, helper
def generate_model(model_name):
nodes = [
helper.make_node(
"Reshape",
["data", "shape"],
["reshaped"],... | 43 | 984 |
onnxruntime | onnxruntime/test/testdata/ort_github_issue_19590.py | .py | import onnx
from onnx import TensorProto, helper
# graph with a QDQ MatMul node unit where one input is and initializer -> DQ and the other is on a path that
# contains a supported node followed by an unsupported node followed by the DQ -> MatMul.
# The DQ of the initializer is prior to the unsupported node. If the pa... | 78 | 2,682 |
onnxruntime | onnxruntime/test/testdata/dummy_whisper_model_generator.py | .py | """Script to generate a dummy ONNX model emulating a Whisper model with BeamSearch op.
The model is intentionally tiny and produces deterministic (but meaningless) outputs.
Its only purpose is to exercise the WhisperBeamSearch encoder/decoder subgraph plumbing,
in particular the decoder "use sequence as input ids" pat... | 329 | 15,637 |
onnxruntime | onnxruntime/test/testdata/if_mul.py | .py | from onnx import TensorProto, checker, helper, save, shape_inference
# if A: C = B * 2
# else: C = B * 3
if_then_branch = helper.make_graph(
nodes=[
helper.make_node(
"Mul",
inputs=["B", "ConstTwo"],
outputs=["if_output"],
name="mul_0",
),
],
... | 71 | 1,754 |
onnxruntime | onnxruntime/test/testdata/ort_github_issue_4031.py | .py | import onnx
from onnx import TensorProto, helper
if_body = helper.make_graph(
[
# need to use main_graph_initializer in a way that can't be constant folded
helper.make_node("Add", ["state_var_in", "main_graph_initializer"], ["add_out"], "If_add"),
helper.make_node("Cast", ["add_out"], ["out... | 81 | 2,779 |
onnxruntime | onnxruntime/test/testdata/sparse_initializer_as_output.py | .py | import argparse
import sys
import traceback
import numpy as np
import onnx
from onnx import (
TensorProto,
ValueInfoProto,
helper,
)
from onnx.helper import make_opsetid
def parse_arguments():
parser = argparse.ArgumentParser()
parser.add_argument("--node_name", required=True, type=str, help="Con... | 128 | 4,110 |
onnxruntime | onnxruntime/test/testdata/test_shape_data_propagation_gather_squeeze_range.py | .py | # Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the MIT License.
# Lock fixture for the Shape -> Gather(1-D index) -> Squeeze -> Range chain.
#
# The Gather index is the 1-D constant [-1] (rank 1), so the Gather output is a
# rank-1, single-element int64 value (the last dimension of X, 200... | 60 | 2,821 |
onnxruntime | onnxruntime/test/testdata/abs_0d_input.py | .py | """
Run this script to recreate the original onnx model.
Example usage:
python abs_0d_input.py out_model_path.onnx
"""
import sys
from onnx import TensorProto, helper, save
def clear_field(proto, field):
proto.ClearField(field)
return proto
def order_repeated_field(repeated_proto, key_name, order):
or... | 59 | 1,845 |
onnxruntime | onnxruntime/test/testdata/gather_with_scalar_indices_then_shape.py | .py | from pathlib import Path
import onnx
from onnx import helper
from onnx.onnx_pb import TensorProto
nodes = [
helper.make_node("Gather", ["X", "indices"], ["Y"], axis=1),
helper.make_node("Shape", ["Y"], ["Y_shape"]),
]
graph = helper.make_graph(
nodes,
"GatherWithScalarIndicesThenShape",
[ # inpu... | 27 | 789 |
onnxruntime | onnxruntime/test/testdata/nnapi_reshape_flatten_test.py | .py | import onnx
from onnx import TensorProto, helper
# Since NNAPI EP handles Reshape and Flatten differently,
# Please see ReshapeOpBuilder::CanSkipReshape in <repo_root>/onnxruntime/core/providers/nnapi/nnapi_builtin/builders/op_builder.cc
# We have a separated test for these skip reshape scenarios
def GenerateModel(mo... | 50 | 1,944 |
onnxruntime | onnxruntime/test/testdata/nn/deform_conv_test_gen.py | .py | # Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the MIT License.
"""
Generate DeformConv ONNX model and test data for cross-platform validation.
Based on ONNX DeformConv spec (opset 19+): https://onnx.ai/onnx/operators/onnx__DeformConv.html
Uses a moderately complex config: groups=2, offs... | 195 | 6,638 |
onnxruntime | onnxruntime/test/testdata/custom_op_library/custom_op_test_float8.py | .py | """
This file was used to generate model `custom_op_test_float8.py`.
"""
from onnx import TensorProto
from onnx.checker import check_model
from onnx.helper import make_graph, make_model, make_node, make_opsetid, make_tensor_value_info
X = make_tensor_value_info("X", TensorProto.FLOAT8E4M3FN, [None])
Y = make_tensor_v... | 26 | 828 |
onnxruntime | onnxruntime/test/testdata/CNTK/gen.py | .py | # Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the MIT License.
import os
import cntk as C
import numpy as np
import onnx
from onnx import numpy_helper
model_file = "model.onnx"
data_dir = "test_data_set_0"
def SaveTensorProto(file_path, variable, data, name): # noqa: N802
# ONNX... | 277 | 9,218 |
onnxruntime | onnxruntime/test/testdata/test_data_generation/lr_scheduler/lr_scheduler_test_data_generator.py | .py | # Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the MIT License.
"""This file is used to generate test data for LR scheduler optimizer tests in
orttraining/orttraining/test/training_api/core/training_api_tests.cc."""
import inspect
import logging
import torch
from torch.optim.lr_schedule... | 136 | 4,870 |
onnxruntime | onnxruntime/test/testdata/test_data_generation/adamw_test/adamw_test_data_generator.py | .py | # Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the MIT License.
"""This file is used to generate test data for Adam optimizer tests in
orttraining/orttraining/test/training_ops/cuda/optimizer/adamw_test.cc."""
import torch
class SingleParameterModule(torch.nn.Module):
"""A dummy mo... | 200 | 7,133 |
onnxruntime | onnxruntime/test/testdata/test_data_generation/sgd_test/sgd_test_data_generator.py | .py | # Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the MIT License.
"""This file is used to generate test data for SGD optimizer tests in
orttraining/orttraining/test/training_ops/cuda/optimizer/sgd_test.cc."""
import torch
class SingleParameterModule(torch.nn.Module):
"""A dummy modul... | 170 | 5,656 |
onnxruntime | onnxruntime/test/testdata/custom_op_local_function/custom_op_test_local_function.py | .py | # Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the MIT License.
import os
import sys
import unittest
import numpy as np
import onnx
from onnxruntime import InferenceSession, SessionOptions
class TestOnnxToolsGraph(unittest.TestCase):
def test_basic_all(self):
if sys.platfor... | 48 | 1,501 |
onnxruntime | onnxruntime/test/testdata/transform/constant_float16_topk.py | .py | import onnx
# input tensor
X = onnx.helper.make_tensor_value_info("X", onnx.TensorProto.FLOAT16, [3, 4])
# output tensors
Values = onnx.helper.make_tensor_value_info("Values", onnx.TensorProto.FLOAT16, [3, 2])
Indices = onnx.helper.make_tensor_value_info("Indices", onnx.TensorProto.INT64, [3, 2])
# constant for k
k_... | 19 | 696 |
onnxruntime | onnxruntime/test/testdata/transform/transpose_graph_gen.py | .py | # -------------------------------------------------------------------------
# Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the MIT License.
# --------------------------------------------------------------------------
import onnx
from onnx import TensorProto, helper
def GenerateModel(mode... | 42 | 1,481 |
onnxruntime | onnxruntime/test/testdata/transform/computation_reduction.py | .py | import numpy as np
import onnx
from onnx import OperatorSetIdProto, TensorProto, helper, numpy_helper
vocab_size = 256 # 30258
X = helper.make_tensor_value_info("input", TensorProto.FLOAT, ["batch", "seqlen", 128])
unsqueezed_masked_lm_positions = helper.make_tensor_value_info(
"unsqueezed_masked_lm_positions",
... | 145 | 5,147 |
onnxruntime | onnxruntime/test/testdata/transform/transform_nested_ifs_toplogical_sorted_nodes.py | .py | import google.protobuf.text_format
import onnx
from numpy import array, float16
import onnxruntime as ort
# Run n times
N = 1
onnx_model_text = """
ir_version: 8
producer_name: "pytorch"
producer_version: "2.2.0"
graph {
node {
output: "_val_1"
name: "Constant_0"
op_type: "Constant"
attribute {
... | 860 | 21,546 |
onnxruntime | onnxruntime/test/testdata/transform/id-elim.py | .py | import onnx
from onnx import OperatorSetIdProto, TensorProto, helper
X1 = helper.make_tensor_value_info("x1", TensorProto.INT64, [4, 4])
X2 = helper.make_tensor_value_info("x2", TensorProto.INT64, [4, 4])
Y1 = helper.make_tensor_value_info("output1", TensorProto.INT64, [4, 4])
Y2 = helper.make_tensor_value_info("outpu... | 34 | 1,321 |
onnxruntime | onnxruntime/test/testdata/transform/convert_qdq_ops_to_ms_domain.py | .py | # -------------------------------------------------------------------------
# Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the MIT License.
# --------------------------------------------------------------------------
"""
Loads a model and updates the domain of QuantizeLinear and Dequantize... | 189 | 8,284 |
onnxruntime | onnxruntime/test/testdata/transform/pre_shape_node_elimination.py | .py | # -------------------------------------------------------------------------
# Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the MIT License.
# --------------------------------------------------------------------------
import onnx
from onnx import OperatorSetIdProto, TensorProto, helper
in... | 41 | 1,586 |
onnxruntime | onnxruntime/test/testdata/transform/expand_elimination.py | .py | import numpy as np
import onnx
from onnx import OperatorSetIdProto, TensorProto, helper, numpy_helper
X1 = helper.make_tensor_value_info("input1", TensorProto.FLOAT, [2, 1])
X2 = helper.make_tensor_value_info("input2", TensorProto.FLOAT, ["dynamic", 4])
Y = helper.make_tensor_value_info("output", TensorProto.FLOAT, [1... | 75 | 3,127 |
onnxruntime | onnxruntime/test/testdata/transform/concat_slice_elimination.py | .py | import numpy as np
import onnx
from onnx import OperatorSetIdProto, TensorProto, helper, numpy_helper
batch = 3
hidden_size = 4
attention_head = 2
hidden_per_attention = 2
relative_attention_num_buckets = 32
input_len = 8
output_len = 8
X = helper.make_tensor_value_info("input", TensorProto.FLOAT, [batch, input_len,... | 186 | 5,999 |
onnxruntime | onnxruntime/test/testdata/transform/qdq_conv_gen.py | .py | import onnx
from onnx import TensorProto, helper
# Generate a basic QDQ Conv model with `num_convs` Conv nodes and their surrounding DQ/Q nodes
def GenerateModel(model_path, num_convs): # noqa: N802
nodes = []
initializers = []
inputs = []
outputs = []
for i in range(num_convs):
def nam... | 83 | 2,834 |
onnxruntime | onnxruntime/test/testdata/transform/dropout_zeroratio_elimination.py | .py | import onnx
from onnx import OperatorSetIdProto, TensorProto, helper
# inputs/outputs
X = helper.make_tensor_value_info("X", TensorProto.FLOAT, [2, 1])
O1 = helper.make_tensor_value_info("O1", TensorProto.FLOAT, [2, 1])
O2 = helper.make_tensor_value_info("O2", TensorProto.FLOAT, [2, 1])
O3 = helper.make_tensor_value_i... | 61 | 2,837 |
onnxruntime | onnxruntime/test/testdata/transform/cast_elimination.py | .py | import onnx
from onnx import OperatorSetIdProto, TensorProto, helper
X1 = helper.make_tensor_value_info("x1", TensorProto.INT64, [4, 4])
X2 = helper.make_tensor_value_info("x2", TensorProto.INT64, [4, 1])
X3 = helper.make_tensor_value_info("x3", TensorProto.INT64, [4, 1])
Y = helper.make_tensor_value_info("output", Te... | 46 | 1,960 |
onnxruntime | onnxruntime/test/testdata/transform/stft_negative_frame_length.py | .py | from onnx import TensorProto, helper, save
def make_stft_model(frame_length_value, frame_step_value, has_window, filename):
batch = 1
signal_length = 16
dft_size = abs(frame_length_value) if frame_length_value != 0 else 4
onesided_bins = dft_size // 2 + 1
num_frames = max(1, (signal_length - dft_s... | 47 | 1,749 |
onnxruntime | onnxruntime/test/testdata/transform/noop-add.py | .py | import onnx
from onnx import OperatorSetIdProto, TensorProto, helper
opsets = []
onnxdomain = OperatorSetIdProto()
onnxdomain.version = 12
onnxdomain.domain = "" # The empty string ("") or absence of this field implies the operator set that is defined as part of the ONNX specification.
opsets.append(onnxdomain)
msdo... | 82 | 3,274 |
onnxruntime | onnxruntime/test/testdata/transform/gh_issue_18338.py | .py | import google.protobuf.text_format
import onnx
from numpy import array, float16
import onnxruntime as ort
# Run n times
N = 1
onnx_model_text = """
ir_version: 8
producer_name: "pytorch"
producer_version: "2.2.0"
graph {
node {
output: "_val_1"
name: "Constant_0"
op_type: "Constant"
attribute {
... | 860 | 21,558 |
onnxruntime | onnxruntime/test/testdata/transform/concat_graph_gen.py | .py | import numpy as np
import onnx
from onnx import TensorProto, helper
def GenerateModel(model_name): # noqa: N802
nodes = [
helper.make_node("Gather", ["embed_weights", "input_1"], ["gather_out"], "gather"),
helper.make_node("Add", ["gather_out", "add_q_weight"], ["add_q_out"], "add_q"),
he... | 88 | 2,643 |
onnxruntime | onnxruntime/test/testdata/transform/id-scan9_sum.py | .py | import onnx
from onnx import OperatorSetIdProto, TensorProto, helper
initial = helper.make_tensor_value_info("initial", TensorProto.FLOAT, [2])
x = helper.make_tensor_value_info("x", TensorProto.FLOAT, [3, 2])
y = helper.make_tensor_value_info("y", TensorProto.FLOAT, [3, 2])
z = helper.make_tensor_value_info("z", Tens... | 41 | 1,626 |
onnxruntime | onnxruntime/test/testdata/transform/scalar_const_not_share.py | .py | # Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the MIT License.
import numpy as np
import onnx
import onnxscript
from onnx import numpy_helper
from onnxscript import opset17 as op
@onnxscript.script()
def build_model(x: onnxscript.FLOAT):
y_scale = op.Constant(value_float=1.0)
y... | 20 | 563 |
onnxruntime | onnxruntime/test/testdata/transform/propagate_cast/gen_propagate_cast.py | .py | import itertools
import numpy as np
import onnx
from onnx import OperatorSetIdProto, TensorProto, helper
onnxdomain = OperatorSetIdProto()
onnxdomain.version = 12
# The empty string ("") or absence of this field implies the operator set that is defined as part of the ONNX specification.
onnxdomain.domain = ""
msdomai... | 400 | 15,042 |
onnxruntime | onnxruntime/test/testdata/transform/model_parallel/bart_self_attention_megatron_basic_test.py | .py | import numpy as np
import onnx
from onnx import OperatorSetIdProto, TensorProto, helper, numpy_helper
batch = 6
hidden_size = 4
attention_head = 2
hidden_per_attention = 2
relative_attention_num_buckets = 32
input_len = 8
output_len = 8
X = helper.make_tensor_value_info("input", TensorProto.FLOAT, [batch, input_len,... | 253 | 9,100 |
onnxruntime | onnxruntime/test/testdata/transform/model_parallel/bart_mlp_megatron_basic_test.py | .py | import numpy as np
import onnx
from onnx import OperatorSetIdProto, TensorProto, helper, numpy_helper
hidden_size = 4
weight_dim_to_split = 16
X = helper.make_tensor_value_info("input", TensorProto.FLOAT, ["batch", "seqlen", hidden_size])
Y = helper.make_tensor_value_info("output", TensorProto.FLOAT, ["batch", "seqle... | 145 | 4,063 |
onnxruntime | onnxruntime/test/testdata/transform/model_parallel/mlp_megatron_basic_test.py | .py | import numpy as np
import onnx
from onnx import OperatorSetIdProto, TensorProto, helper, numpy_helper
hidden_size = 4
weight_dim_to_split = 16
X = helper.make_tensor_value_info("input", TensorProto.FLOAT, ["batch", "seqlen", hidden_size])
Y = helper.make_tensor_value_info("output", TensorProto.FLOAT, ["batch", "seqle... | 102 | 3,044 |
onnxruntime | onnxruntime/test/testdata/transform/model_parallel/self_attention_megatron_basic_test.py | .py | import numpy as np
import onnx
from onnx import OperatorSetIdProto, TensorProto, helper, numpy_helper
hidden_size = 4
attention_head = 2
hidden_per_attention = 2
# Self-attention.
# Handle self-attention.
# MatMul->Add->Split->Reshape->Transpose->MatMul->Div->Mul->Sub->Softmax->Dropout->MatMul->Transpose->Reshape->Ma... | 152 | 6,087 |
onnxruntime | onnxruntime/test/testdata/transform/runtime_optimization/matmulnbits_add_gen.py | .py | # generated by onnxconverter_common.onnx2py
"""
Run this script to recreate the original onnx model.
Example usage:
python matmulnbits_add_gen.py out_model_path.onnx
"""
import os
import sys
import numpy as np
import onnx
from onnx import TensorProto, helper, numpy_helper
DATA_DIR = os.path.join(os.path.dirname(os.... | 83 | 2,514 |
onnxruntime | onnxruntime/test/testdata/transform/runtime_optimization/add_with_surrounding_identities_gen.py | .py | import onnx
from onnx import TensorProto, helper
graph = helper.make_graph(
[ # nodes
helper.make_node("Identity", ["A"], ["A_inner"], "id0"),
helper.make_node("Identity", ["B"], ["B_inner"], "id1"),
helper.make_node("Add", ["A_inner", "B_inner"], ["C_inner"], "add0"),
helper.make_... | 24 | 785 |
onnxruntime | onnxruntime/test/testdata/transform/approximation/gelu_approximation_gen.py | .py | import onnx
from onnx import TensorProto, helper
graph = helper.make_graph(
[ # nodes
# Add node before Gelu
helper.make_node("Gelu", ["A"], ["C"], "Gelu_1", domain="com.microsoft"),
],
"Gelu_NoBias", # name
[ # inputs
helper.make_tensor_value_info("A", TensorProto.FLOAT, ["b... | 61 | 1,929 |
onnxruntime | onnxruntime/test/testdata/transform/computation_reduction/reshape/mlm_bert_e2e.py | .py | import onnx
from onnx import OperatorSetIdProto, TensorProto, helper
# inputs and outputs
hidden = 1024
head = 16
vocab_size = 30522
inputs = [
helper.make_tensor_value_info("input", TensorProto.FLOAT, ["batch_size", "sequence_length", hidden]),
helper.make_tensor_value_info("attention_mask", TensorProto.INT64... | 262 | 13,155 |
onnxruntime | onnxruntime/test/testdata/transform/computation_reduction/gather/gather_matmul.py | .py | import onnx
from onnx import OperatorSetIdProto, TensorProto, helper
def _create_model_proto(output_shapes, axis_to_gather, slice_dims, slices_values, model_name):
# inputs and outputs
hidden = 1024
inputs = [
helper.make_tensor_value_info("input1", TensorProto.FLOAT, ["batch_size", "sequence_leng... | 66 | 2,458 |
onnxruntime | onnxruntime/test/testdata/transform/computation_reduction/gather/gather_reshape.py | .py | import onnx
from onnx import OperatorSetIdProto, TensorProto, helper
hidden = 1024
head = 16
def _create_model_proto(
input_shapes, output_shapes, axis_to_gather, slice_dims, slices_values, shape_dims, shape_values, model_name
):
# inputs and outputs
inputs = [
helper.make_tensor_value_info("inpu... | 90 | 2,671 |
onnxruntime | onnxruntime/test/testdata/transform/computation_reduction/gather/gather_roberta_e2e.py | .py | import onnx
from onnx import OperatorSetIdProto, TensorProto, helper
# inputs and outputs
hidden = 1024
head = 16
inputs = [
helper.make_tensor_value_info("input", TensorProto.FLOAT, ["batch_size", "sequence_length", hidden]),
helper.make_tensor_value_info("attention_mask", TensorProto.INT64, ["batch_size", "s... | 212 | 10,567 |
onnxruntime | onnxruntime/test/testdata/transform/computation_reduction/gathernd/gathernd_gelu.py | .py | import onnx
from onnx import OperatorSetIdProto, TensorProto, helper
X = helper.make_tensor_value_info("input", TensorProto.FLOAT, ["batch", "seqlen", 128])
unsqueezed_masked_lm_positions = helper.make_tensor_value_info(
"unsqueezed_masked_lm_positions",
TensorProto.INT64,
["batch", "dynamic_prediction_cou... | 48 | 1,495 |
onnxruntime | onnxruntime/test/testdata/transform/computation_reduction/gathernd/gathernd_div.py | .py | import numpy as np
import onnx
from onnx import OperatorSetIdProto, TensorProto, helper, numpy_helper
X = helper.make_tensor_value_info("input", TensorProto.FLOAT, ["batch", "seqlen", 128])
unsqueezed_masked_lm_positions = helper.make_tensor_value_info(
"unsqueezed_masked_lm_positions",
TensorProto.INT64,
... | 73 | 2,295 |
onnxruntime | onnxruntime/test/testdata/transform/computation_reduction/gathernd/gathernd_add.py | .py | import numpy as np
import onnx
from onnx import OperatorSetIdProto, TensorProto, helper, numpy_helper
X = helper.make_tensor_value_info("input", TensorProto.FLOAT, ["batch", "seqlen", 128])
unsqueezed_masked_lm_positions = helper.make_tensor_value_info(
"unsqueezed_masked_lm_positions",
TensorProto.INT64,
... | 73 | 2,259 |
onnxruntime | onnxruntime/test/testdata/transform/computation_reduction/gathernd/gathernd_layernormalization.py | .py | import numpy as np
import onnx
from onnx import OperatorSetIdProto, TensorProto, helper, numpy_helper
X = helper.make_tensor_value_info("input", TensorProto.FLOAT, ["batch", "seqlen", 128])
unsqueezed_masked_lm_positions = helper.make_tensor_value_info(
"unsqueezed_masked_lm_positions",
TensorProto.INT64,
... | 71 | 2,278 |
onnxruntime | onnxruntime/test/testdata/transform/computation_reduction/gathernd/e2e.py | .py | import numpy as np
import onnx
from onnx import OperatorSetIdProto, TensorProto, helper, numpy_helper
vocab_size = 256
X = helper.make_tensor_value_info("input", TensorProto.FLOAT, ["batch", "seqlen", 128])
unsqueezed_masked_lm_positions = helper.make_tensor_value_info(
"unsqueezed_masked_lm_positions",
Tenso... | 160 | 5,514 |
onnxruntime | onnxruntime/test/testdata/transform/computation_reduction/gathernd/gathernd_matmul.py | .py | import numpy as np
import onnx
from onnx import OperatorSetIdProto, TensorProto, helper, numpy_helper
X = helper.make_tensor_value_info("input", TensorProto.FLOAT, ["batch", "seqlen", 128])
unsqueezed_masked_lm_positions = helper.make_tensor_value_info(
"unsqueezed_masked_lm_positions",
TensorProto.INT64,
... | 53 | 1,769 |
onnxruntime | onnxruntime/test/testdata/transform/cse/generate.py | .py | import os
import onnx
from onnx import TensorProto, helper, shape_inference
_this_dir = os.path.abspath(os.path.dirname(__file__))
def _onnx_export(graph_def, relative_path, verbose=False):
model = helper.make_model(
graph_def,
producer_name="makalini",
opset_imports=[helper.make_operato... | 363 | 12,317 |
onnxruntime | onnxruntime/test/testdata/transform/recompute/recompute_test_graph_generator.py | .py | # Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the MIT License.
"""This file is used to generate test data for MemoryOptimizer tests in
onnxruntime/test/optimizer/memory_optimizer_test.cc.
Be noticed, after run this script, manually rename recompute_XXXX_execution_model_training.onnx to
... | 89 | 2,683 |
onnxruntime | onnxruntime/test/testdata/transform/recompute/3layer_bloom_optimized_training.py | .py | # Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the MIT License.
"""This file is used to generate test data for MemoryOptimizer tests in
onnxruntime/test/optimizer/memory_optimizer_test.cc.
The libs used to generate 3 layer bloom model.
optimum: f6adbef5c4a6bd16a17e3b22712028... | 85 | 2,717 |
onnxruntime | onnxruntime/test/testdata/transform/fusion/layer_norm_with_cast_3.py | .py | import onnx
from onnx import OperatorSetIdProto, TensorProto, helper
def GenerateModel(model_name): # noqa: N802
nodes = [ # LayerNormWithCast3 subgraph
helper.make_node("ReduceMean", ["A"], ["rd1_out"], "reduce", axes=[-1]),
helper.make_node("Sub", ["A", "rd1_out"], ["sub1_out"], "sub"),
... | 103 | 4,299 |
onnxruntime | onnxruntime/test/testdata/transform/fusion/layer_norm_fusion_scale_bias.py | .py | # Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the MIT License.
import onnx
from onnx import OperatorSetIdProto, TensorProto, helper
def GenerateModel(model_name, has_casts=False, has_identity=False): # noqa: N802
nodes = [ # LayerNorm subgraph
helper.make_node("ReduceMean"... | 82 | 3,230 |
onnxruntime | onnxruntime/test/testdata/transform/fusion/fast_gelu3_with_casts.py | .py | import numpy as np
import onnx
from onnx import OperatorSetIdProto, TensorProto, helper, numpy_helper
# Gelu formula: x * 0.5 * (1.0 + tanh((sqrt(2 / pi) * (x + 0.044715 * pow(x, 3)))))
X = helper.make_tensor_value_info("input", TensorProto.FLOAT, ["batch", "seqlen", 64])
Y = helper.make_tensor_value_info("output", T... | 98 | 3,424 |
onnxruntime | onnxruntime/test/testdata/transform/fusion/transpose_matmul_gen.py | .py | import onnx
from onnx import OperatorSetIdProto, TensorProto, helper
onnxdomain = OperatorSetIdProto()
onnxdomain.version = 12
# The empty string ("") or absence of this field implies the operator set that is defined as part of the ONNX specification.
onnxdomain.domain = ""
msdomain = OperatorSetIdProto()
msdomain.ver... | 316 | 11,409 |
onnxruntime | onnxruntime/test/testdata/transform/fusion/layer_norm_with_cast_2.py | .py | import onnx
from onnx import OperatorSetIdProto, TensorProto, helper
def GenerateModel(model_name): # noqa: N802
nodes = [ # LayerNormWithCast2 subgraph
helper.make_node("ReduceMean", ["A"], ["rd1_out"], "reduce", axes=[-1]),
helper.make_node("Sub", ["A", "rd1_out"], ["sub1_out"], "sub"),
... | 52 | 2,107 |
onnxruntime | onnxruntime/test/testdata/transform/fusion/gelu_gen.py | .py | import numpy as np
import onnx
from onnx import OperatorSetIdProto, TensorProto, helper, numpy_helper
"""
Generate test model for Gelu subgraph pattern 2:
+------------------------------------+
| |
| ... | 124 | 4,004 |
onnxruntime | onnxruntime/test/testdata/transform/fusion/not_where.py | .py | import onnx
from onnx import OperatorSetIdProto, TensorProto, helper
opsets = []
onnxdomain = OperatorSetIdProto()
onnxdomain.version = 12
onnxdomain.domain = "" # The empty string ("") or absence of this field implies the operator set that is defined as part of the ONNX specification.
opsets.append(onnxdomain)
msdo... | 65 | 2,409 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.