liveBook · Manning

Operator

As explained in Domain-Specific Small Language Models

A computation node in an ONNX graph that performs a specific operation during model execution.

An operator is a computation node in an ONNX directed graph. It consumes typed tensor inputs, performs a defined operation, and passes results to downstream nodes. Standard operators cover common machine-learning workloads; custom operators extend the graph when standard operations are insufficient. section 5.1 section 5.2

Operators matter operationally because they define both graph semantics and deployment constraints:

  • Express numerical computation through matrix operations, reductions, image transformations, neural-network layers, and activation functions. section 5.2
  • Require explicit input and output shapes and element types because ONNX is strongly typed. section 5.2
  • Run through ONNX Runtime and its execution providers across CPUs, GPUs, and edge devices, with performance depending on the deployment target. section 5.1 section 5.7

Linear regression as two operators

The expression Y = XA + B becomes a graph containing MatMul(X, A) followed by Add(XA, B). Python bindings construct its typed values with make_tensor_value_info, create nodes with make_node, assemble the graph with make_graph, and validate it with check_model. section 5.2

Table 5.1 The most relevant ONNX operators for LLMs

Operator

Description

Add

Performs element-wise binary addition. It supports multidirectional broadcasting (like NumPy).

And

Returns the tensor resulted from performing the and logical operation elementwise on the input tensors

ArgMax

Computes the indices of the max elements of the input tensor’s element along the provided axis

ArgMin

Computes the indices of the min elements of the input tensor’s element along the provided axis

Atan

Calculates the arctangent (inverse of tangent) of the given input tensor, element-wise

AveragePool

Consumes an input tensor and applies average pooling across the tensor according to kernel sizes, stride sizes, and pad lengths. Average pooling consists of computing the average on all values of a subset of the input tensor according to the kernel size and downsampling the data into the output tensor for further processing.

BatchNormalization

Applies batch normalization to deep neural networks

Conv

Applies convolution to the input tensor

DFT

Computes the discrete fourier transform of the input

Det

Calculates the determinant of a square matrix (or a batch of square matrices)

Div

Performs element-wise binary division of the input

Equal

Returns the tensor resulted from performing the equal logical operation element-wise on the input tensors

Exp

Calculates the exponential of the given input tensor, element-wise

Floor

Takes one input tensor and produces an output tensor where the floor is
y = floor(x), applied element-wise

GreaterOrEqual

Returns the tensor resulted from performing the greater_equal logical operation element-wise on the input tensors

Identity

The identity operator

IsNaN

Returns which elements of the input are NaN

LayerNormalization

Layer normalization defined as a function

LessOrEqual

Returns the tensor resulted from performing the less equal logical operation element-wise on the input tensors

Loop

The generic loop construct

MatMul

The matrix product

MaxPool

Consumes an input tensor and applies max pooling across the tensor according to kernel sizes, stride sizes, and pad lengths. The max pooling operation consists of computing the max on all values of a subset of the input tensor according to the kernel size and downsampling the data into the output tensor for further processing.

Mean

Element-wise mean of each of the input tensors

Pad

Given a tensor containing the data to be padded, a tensor containing the number of start and end pad values for axis, and, optionally, a mode and a constant value, a padded tensor is generated as output.

QuantizeLinear

The linear quantization operator. It consumes a high-precision tensor, a scale, and a zero point to compute the low-precision/quantized tensor.

Reciprocal

Takes one input tensor and produces one output tensor where the reciprocal, y = 1/x, is applied to the tensor element-wise

RegexFullMatch

Performs a full regex match on each element of the input tensor. If an element fully matches the regex pattern specified as an attribute, the corresponding element in the output is true, and it is false otherwise.

Reshape

Reshapes the input tensor. First input is the data tensor; second input is a shape tensor which specifies the output shape. It outputs the reshaped tensor.

Softmax

Computes the normalized exponential values for the given input: Softmax(input, axis) = Exp(input) / ReduceSum(Exp(input), axis=axis, keepdims=1) The axis attribute indicates the dimension along which Softmax will be performed. The output tensor has the same shape and contains the Softmax values of the corresponding input.

Transpose

Transposes the input tensor

Unique

Finds the unique elements of a tensor. When an optional attribute axis is provided, unique subtensors sliced along the axis are returned. Otherwise, the input tensor is flattened, and unique values of the flattened tensor are returned.

Browse representative ONNX operators and their tensor-level behavior, including broadcasting, reductions, pooling, and activation operations. section 5.2

How Domain-Specific Small Language Models covers it

How deep it goes
Explains operator semantics, typing, graph construction, validation, and a linear-regression example, but defers the complete operator catalog.
Examples
Uses MatMul and Add in a linear-regression graph, Python construction functions, model validation, serialized output, and an operator catalog.
What it assumes
Assumes basic matrix and tensor concepts while teaching ONNX graph structure, operator composition, shapes, types, and construction APIs.
What you can do after
Build it from scratch as a typed ONNX graph, validate the model, serialize it, and select runtime deployment options.
How it connects
Connects operators with tensors, directed graphs, ONNX Runtime, execution providers, custom operators, and protobuf serialization.

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Domain-Specific Small Language Models. The section links point to the parts of the book it draws on.