TECHNOLOGY

ONNX optional inputs: preserve positions when a middle argument is absent

In this article
THE QUICK TAKE

An absent positional input is different from an empty tensor; preserve the schema position instead of shifting later arguments.

A graph editor silently moves the upper bound

Imagine a graph rewrite that keeps a clipping operation’s upper bound but removes its unused lower bound. If the tool compacts the input-name list, the remaining bound occupies the wrong formal position. The tensor itself can still have a valid type, so a superficial inspection may miss the change. Diagnose the correspondence between each input name and the operator schema before examining GPU kernels or attributing the output difference to numerical precision.

Missing static inputs have an explicit representation

The ONNX IR rules allow trailing optional inputs to be omitted. A missing input before a later supplied argument needs an empty name in its position. That marker is not a tensor containing no elements and is not a request to allocate an empty device buffer. It represents absence at the graph interface. Preserve this distinction when serializing, cloning or rewriting nodes, rather than normalizing all empty-looking values into one representation.

Consult the selected operator schema

The Clip specification provides a concrete case with optional bounds. Read the schema selected by the model’s imported operator set, because historical versions can express parameters differently. Associate names with that exact ordered signature. The schema contract guide offers a related lesson: structural positions carry meaning even when individual values look plausible. A syntactically valid list can still describe the wrong operation.

Validate structure and observable behavior

Use the ONNX checker after editing the graph, then compare outputs against the untouched model. For the clipping example, include values below and above the intended bound and values that should pass unchanged. These examples distinguish a missing lower bound from a misplaced upper bound. Retain the rewritten node and the associated import information in the review evidence; a successful checker result alone does not establish that the rewrite preserved intent.

Keep absence separate throughout the toolchain

Do not replace the missing argument with a fabricated constant merely to satisfy a generic list utility. That creates a different graph and can alter optimization or broadcasting behavior. Track the changed artifact through release verification so the tested rewrite is the deployed rewrite. The practical outcome is a position-preserving serializer with behavioral evidence, rather than a rule that every omitted argument can be safely deleted from an ordered input list.

Earn rental income from GPUs

Have idle GPUs or looking to fund AI infrastructure? Retrivium finds a rental platform, sets up the server and helps you assess income and costs with a pilot.

Explore GPU hosting
← All articles