Open Neural Network Exchange (ONNX) - Weekly Builds

1.22.0.dev20260330 · active · verified Wed Apr 15

ONNX (Open Neural Network Exchange) is an open ecosystem for AI developers, providing an open standard format for machine learning models, including deep learning and traditional ML. It defines an extensible computation graph model, built-in operators, and standard data types to enable model interoperability across various frameworks. The `onnx-weekly` package offers continuous integration builds, providing early access to experimental features and allowing users to test upcoming changes ahead of official stable releases. The current version is 1.22.0.dev20260330, reflecting a rapid release cadence for development purposes.

Warnings

Install

Imports

Quickstart

This quickstart demonstrates how to programmatically construct a simple ONNX model (a linear regression: Y = X * A + B) using the `onnx.helper` module, and then validate it using `onnx.checker`. This illustrates the core functionality of defining and manipulating ONNX graphs.

import onnx
from onnx import helper, checker, TensorProto

# Create a simple ONNX graph for Y = X * A + B
# Define inputs and outputs
X = helper.make_tensor_value_info('X', TensorProto.FLOAT, [None, 2])
A = helper.make_tensor_value_info('A', TensorProto.FLOAT, [2, 3])
B = helper.make_tensor_value_info('B', TensorProto.FLOAT, [3])
Y = helper.make_tensor_value_info('Y', TensorProto.FLOAT, [None, 3])

# Create nodes (operators)
# MatMul operation: C = X * A
node_matmul = helper.make_node(
    'MatMul',
    inputs=['X', 'A'],
    outputs=['C'],
)

# Add operation: Y = C + B
node_add = helper.make_node(
    'Add',
    inputs=['C', 'B'],
    outputs=['Y'],
)

# Create the graph
graph_def = helper.make_graph(
    [node_matmul, node_add], # Nodes in the graph
    'simple-linear-regression', # Graph name
    [X, A, B], # Graph inputs
    [Y], # Graph outputs
)

# Create the model
model_def = helper.make_model(graph_def, producer_name='onnx-example')

# Check the model for validity
try:
    checker.check_model(model_def)
    print("Model is valid!")
except checker.ValidationError as e:
    print(f"Model is invalid: {e}")

# Optionally, save the model
# onnx.save(model_def, "simple_model.onnx")

view raw JSON →