MCPcopy Create free account
hub / github.com/SwayStar123/SpeedrunDiT / assert_shape

Function assert_shape

preprocessing/torch_utils/misc.py:93–106  ·  view source on GitHub ↗
(tensor, ref_shape)

Source from the content-addressed store, hash-verified

91# Performs symbolic assertion when used in torch.jit.trace().
92
93def assert_shape(tensor, ref_shape):
94 if tensor.ndim != len(ref_shape):
95 raise AssertionError(f'Wrong number of dimensions: got {tensor.ndim}, expected {len(ref_shape)}')
96 for idx, (size, ref_size) in enumerate(zip(tensor.shape, ref_shape)):
97 if ref_size is None:
98 pass
99 elif isinstance(ref_size, torch.Tensor):
100 with suppress_tracer_warnings(): # as_tensor results are registered as constants
101 symbolic_assert(torch.equal(torch.as_tensor(size), ref_size), f'Wrong size for dimension {idx}')
102 elif isinstance(size, torch.Tensor):
103 with suppress_tracer_warnings(): # as_tensor results are registered as constants
104 symbolic_assert(torch.equal(size, torch.as_tensor(ref_size)), f'Wrong size for dimension {idx}: expected {ref_size}')
105 elif size != ref_size:
106 raise AssertionError(f'Wrong size for dimension {idx}: got {size}, expected {ref_size}')
107
108#----------------------------------------------------------------------------
109# Function decorator that calls torch.autograd.profiler.record_function().

Callers

nothing calls this directly

Calls 1

suppress_tracer_warningsFunction · 0.85

Tested by

no test coverage detected