TECHNOLOGY

StableHLO dynamic broadcast: runtime shape computation must accompany dynamic types

In this article
THE QUICK TAKE

A dynamic tensor type describes uncertainty; dynamic operations and shape computations must still define the executable behavior for that uncertainty.

Replacing a type extent does not generalize every operation

A developer exports a function that adds a constant to a variable-length input. Editing the visible result type to contain a dynamic dimension does not automatically replace a statically sized broadcast with a runtime-sized computation. The program must still construct the appropriate result for each accepted input shape. Trace the shape-producing operations as well as the data-producing operations, because a dynamic annotation cannot override a contradictory static operation inside the body.

Dynamic programs carry executable shape information

The dynamism guide explains different forms of dynamism and an example that broadcasts a constant to match an input. Distinguish dimensions determined by input shapes from dimensions depending on tensor contents. The former and latter impose different requirements on compilation and allocation. State which form the exported function actually uses rather than promising support for arbitrary changing dimensions based solely on a question mark in its type.

Dynamic broadcast has explicit operands and constraints

The StableHLO specification defines dynamic_broadcast_in_dim with output dimension data and a mapping of input axes. Review the mapping and output shape computation together. The broadcasting axis guide explains why a compatible rank is insufficient to establish intended semantics. A program can have a dynamic-looking type and still broadcast along the wrong axis or compute an output extent from the wrong input dimension.

Specialization passes can remove resolved dynamism

The StableHLO passes reference describes canonicalization of dynamic operations when their shape information becomes constant. That transformation has a precondition; it does not justify substituting one observed request’s dimensions into a generally dynamic model. Preserve the distinction between a deliberate specialized artifact and a program expected to handle a range of shapes. Record which constraints were resolved and which remain requirements on the caller or runtime.

Validate shape relationships rather than one sample

Exercise inputs that change the relevant extent while preserving the declared relationships. Compare the output shape and numerical result, and verify rejection of unsupported combinations at the appropriate boundary. The tensor descriptor guide supplies background for interpreting the resulting arrays. An effective review follows how runtime shape data reaches each dynamic operation, instead of counting dynamic type markers and assuming that number measures the program’s actual flexibility.

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