yobx.torch.new_tracing.shape#
- class yobx.torch.new_tracing.shape.TracingBool(value: bool | str)[source]#
Represents a boolean comparison that may involve symbolic
TracingIntdimensions and therefore cannot always be evaluated at trace time.- Parameters:
value – Either a concrete
boolor astrcontaining 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
TracingBoolinstances can be resolved to a concreteTruewhen the condition has been registered viaregister_condition()(typically by thetorch._check()interception inGraphTracer).
- 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 astr(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
TracingTensoras an ordered collection ofTracingIntorintdimension values.Unlike
torch.Size, individual dimensions may be symbolic (TracingIntwith astrvalue).- Parameters:
dims – Iterable of
TracingIntorintvalues.
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
TracingShapefrom 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 namedtorch.export.Diminstance (e.g.torch.export.Dim("batch")), or an unnamedtorch.export.Dimsentinel such astorch.export.Dim.DYNAMICortorch.export.Dim.AUTO. For every keydthe integershape[d]is replaced by the resolved symbolic name in the resultingTracingShape. WhenNoneor empty, all dimensions remain concrete integers.
- Returns:
A
TracingShapewhosedimsareintvalues for static dimensions andTracingIntvalues for dynamic ones.
- 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)
TracingBoolinstances are registered; concrete booleans are ignored.- Parameters:
cond – A
TracingBoolthat has been asserted viatorch._check()and is therefore known to hold.