This commit is contained in:
sayakpaul
2024-12-27 15:02:21 +05:30
parent 4461cdd98f
commit 84c17561eb
2 changed files with 8 additions and 1 deletions
+6
View File
@@ -27,3 +27,9 @@ def align_device_and_dtype(
if dtype is not None:
x = {k: align_device_and_dtype(v, device, dtype) for k, v in x.items()}
return x
def expand_tensor_to_dims(tensor, ndim):
while len(tensor.shape) < ndim:
tensor = tensor.unsqueeze(-1)
return tensor