yobx.torch.new_tracing.tensor#
- class yobx.torch.new_tracing.tensor.TracingTensor(size: Tuple[int, ...] | TracingShape, dtype: dtype, device: str | device | None = None, requires_grad: bool = False, tracer: GraphTracer | None = None)[source]#
A
torch.Tensorsubclass that records all dispatch-level operations into atorch.fx.Graphvia__torch_dispatch__.TracingTensoruses__torch_dispatch__to intercept all tensor operations at the C++ dispatcher level and records them as nodes in atorch.fx.Graph. This produces a full computation graph without requiring Python-level symbolic proxy objects.Note
TracingTensorinstances are created internally byDispatchTracer. Usetrace()to trace a callable rather than constructingTracingTensordirectly.It contains two attributes:
_tracer: TheDispatchTracermanaging this tensor’s graph._node: Thetorch.fx.Nodecorresponding to this tensor in the graph.
- classmethod from_tensor(t: Tensor, dynamic_shapes: Dict[int, Any] | None = None, tracer: GraphTracer | None = None) TracingTensor[source]#
Creates a tracing tensor.
- make_empty_instance(dyanmic_shape_values: Dict[str, int] | None = None) Tensor[source]#
Allocates an uninitialised
torch.empty()tensor whose dtype and device match thisTracingTensor.Concrete integer dimensions are used as-is. Symbolic (string) dimensions must be resolved by supplying dyanmic_shape_values, a mapping from dimension name to its concrete integer value. A missing entry for any symbolic dimension raises
AssertionError.- Parameters:
dyanmic_shape_values – Optional mapping from symbolic dimension names (e.g.
"batch") to their concrete integer sizes.- Returns:
A real
torch.Tensorwith the resolved shape, the samedtype, and the samedeviceas thisTracingTensor. The tensor is uninitialised (contents are undefined).- Raises:
AssertionError – If a symbolic dimension name is not present in dyanmic_shape_values.
NotImplementedError – If a dimension has an unexpected type (i.e. neither
intnorstr).
- property shape: TracingShape#
Returns the shape as a TracingShape.