yobx.torch.new_tracing.shape#

class yobx.torch.new_tracing.shape.TracingBool(value: bool | str)[source]#

Represents a boolean comparison that may involve symbolic TracingInt dimensions and therefore cannot always be evaluated at trace time.

Parameters:

value – Either a concrete bool or a str containing a symbolic expression such as "(batch==4)".

  • TracingBool(True) / TracingBool(False) — concrete result.

  • TracingBool("(n==4)") — symbolic; cannot be used as a Python bool.

Symbolic TracingBool instances can be resolved to a concrete True when the condition has been registered via register_condition() (typically by the torch._check() interception in GraphTracer).

yobx.torch.new_tracing.shape.TracingDimension[source]#

alias of TracingInt

class yobx.torch.new_tracing.shape.TracingInt(value: int | str)[source]#

Represents a single symbolic or concrete integer (e.g. a tensor dimension).

Parameters:

value – Either a concrete int (concrete dimension) or a str (symbolic/dynamic dimension name such as "batch").

Examples:

# Concrete dimension
d = TracingInt(4)
print(int(d))       # 4
print(d + 2)        # TracingInt(6)

# Symbolic/dynamic dimension
s = TracingInt("batch")
print(str(s))       # batch
print(s + 2)        # TracingInt('(batch+2)')
print(s == 4)       # TracingBool('(batch==4)')
class yobx.torch.new_tracing.shape.TracingShape(dims: Sequence[TracingInt | int])[source]#

Represents the shape of a TracingTensor as an ordered collection of TracingInt or int dimension values.

Unlike torch.Size, individual dimensions may be symbolic (TracingInt with a str value).

Parameters:

dims – Iterable of TracingInt or int values.

Example:

shape = TracingShape([TracingInt(4), 16])
print(shape)              # TracingShape([TracingInt(4), 16])
print(shape.numel())      # 64
print(shape.is_concrete)  # True

sym_shape = TracingShape([TracingInt("n"), 8])
print(sym_shape.is_concrete)  # False
classmethod from_existing_shape(shape: Tuple[int, ...], dynamic_shapes: Dict[int, Any] | None = None) TracingShape[source]#

Build a TracingShape from a concrete shape tuple, optionally making selected dimensions symbolic.

Parameters:
  • shape – The concrete shape (e.g. from tensor.shape).

  • dynamic_shapes – An optional mapping from dimension index to a symbolic name. Each value may be a plain str, a named torch.export.Dim instance (e.g. torch.export.Dim("batch")), or an unnamed torch.export.Dim sentinel such as torch.export.Dim.DYNAMIC or torch.export.Dim.AUTO. For every key d the integer shape[d] is replaced by the resolved symbolic name in the resulting TracingShape. When None or empty, all dimensions remain concrete integers.

Returns:

A TracingShape whose dims are int values for static dimensions and TracingInt values for dynamic ones.

property is_concrete: bool#

Return True if every dimension has a concrete integer value.

numel() int[source]#

Returns the total number of elements (product of all dimensions).

Raises:

ValueError – If any dimension is purely symbolic (no concrete integer value).

to_torch_size() Size[source]#

Converts to torch.Size (requires all dimensions to be concrete).

Raises:

ValueError – If any dimension is purely symbolic.

yobx.torch.new_tracing.shape.clear_conditions() None[source]#

Clears the registry of known-True conditions.

Called at the start of each GraphTracer.trace() invocation so that constraints do not leak between independent traces.

yobx.torch.new_tracing.shape.register_condition(cond: TracingBool) None[source]#

Registers cond as a condition known to be True during tracing.

Only symbolic (string-valued) TracingBool instances are registered; concrete booleans are ignored.

Parameters:

cond – A TracingBool that has been asserted via torch._check() and is therefore known to hold.