onnx_ir.schemasΒΆ

The onnx_ir.schemas module provides classes for representing operator signatures and their parameters. These classes are useful for introspecting operator definitions and validating operator usage.

OpSignatureΒΆ

The OpSignature class represents the schema for an ONNX operator, including its inputs, outputs, and attributes.

class onnx_ir.schemas.OpSignature(domain, name, overload, params, outputs, since_version=1)[source]ΒΆ

Schema for an operator.

Parameters:
domainΒΆ

Domain of the operator. E.g. β€œβ€.

Type:

str

nameΒΆ

Name of the operator. E.g. β€œAdd”.

Type:

str

overloadΒΆ

Overload name of the operator.

Type:

str

paramsΒΆ

Input parameters. When the op is an ONNX function definition, the order is according to the function signature. This mean we can interleave ONNX inputs and ONNX attributes in the list.

Type:

collections.abc.Sequence[onnx_ir.schemas.Parameter | onnx_ir.schemas.AttributeParameter]

outputsΒΆ

Output parameters.

Type:

collections.abc.Sequence[onnx_ir.schemas.Parameter]

since_versionΒΆ

The version of the operator set. E.g. 1.

Type:

int

property attributes: Sequence[AttributeParameter]ΒΆ

Returns the attribute parameters.

domain: strΒΆ
classmethod from_op_schema(op_schema)[source]ΒΆ

Produce an OpSignature from an ONNX OpSchema.

Parameters:

op_schema (OpSchema)

Return type:

OpSignature

get(name, default=None)[source]ΒΆ
Parameters:
Return type:

Parameter | AttributeParameter | None

property inputs: Sequence[Parameter]ΒΆ

Returns the input parameters.

name: strΒΆ
outputs: Sequence[Parameter]ΒΆ
overload: strΒΆ
params: Sequence[Parameter | AttributeParameter]ΒΆ
params_map: Mapping[str, Parameter | AttributeParameter]ΒΆ
since_version: int = 1ΒΆ

ParameterΒΆ

The Parameter class represents a formal input parameter of an operator.

class onnx_ir.schemas.Parameter(name, type_constraint, required, variadic, homogeneous=True, min_arity=1, default=_EMPTY_DEFAULT)[source]ΒΆ

A formal parameter of an operator.

Parameters:
default: Any = _EMPTY_DEFAULTΒΆ
has_default()[source]ΒΆ
Return type:

bool

homogeneous: bool = TrueΒΆ
is_attribute()[source]ΒΆ
Return type:

bool

is_param()[source]ΒΆ

This parameter is an ONNX input or output parameter, as opposed to an ONNX attribute parameter.

Return type:

bool

min_arity: int = 1ΒΆ
name: strΒΆ
required: boolΒΆ
type_constraint: TypeConstraintParamΒΆ
variadic: boolΒΆ

AttributeParameterΒΆ

The AttributeParameter class represents an attribute parameter in the operator signature.

class onnx_ir.schemas.AttributeParameter(name, type, required, default=None)[source]ΒΆ

A parameter in the function signature that represents an ONNX attribute.

Parameters:
default: Attr | None = NoneΒΆ
has_default()[source]ΒΆ
Return type:

bool

is_attribute()[source]ΒΆ

This parameter is an ONNX attribute parameter, as opposed to an ONNX input or output parameter.

Return type:

bool

is_param()[source]ΒΆ
Return type:

bool

name: strΒΆ
required: boolΒΆ
type: AttributeTypeΒΆ

TypeConstraintParamΒΆ

The TypeConstraintParam class represents type constraints for parameters, specifying which types are allowed.

class onnx_ir.schemas.TypeConstraintParam(name, allowed_types, description='')[source]ΒΆ

Type constraint for a parameter.

Parameters:
nameΒΆ

Name of the parameter. E.g. β€œTFloat”

Type:

str

allowed_typesΒΆ

Allowed types for the parameter.

Type:

frozenset[onnx_ir.TypeProtocol]

descriptionΒΆ

Human-readable description of the type constraint.

Type:

str

allowed_types: frozenset[TypeProtocol]ΒΆ
classmethod any_tensor(name, description='')[source]ΒΆ
Parameters:
  • name (str)

  • description (str)

Return type:

TypeConstraintParam

classmethod any_value(name, description='')[source]ΒΆ
Parameters:
  • name (str)

  • description (str)

Return type:

TypeConstraintParam

description: str = ''ΒΆ
name: strΒΆ