From 43827871ef6deb9e1f180d92595e0ae6e4507fba Mon Sep 17 00:00:00 2001 From: Bay Foley-Cox Date: Wed, 25 Mar 2026 05:11:21 +0000 Subject: [PATCH 1/2] Fix crash on scalar tensors (empty shape) in tensors() MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit `view(*shape)` fails when shape is `[]` (scalar tensor) because it expands to `view()` with no arguments, raising TypeError. This occurs with FP8-quantized models (e.g. DeepSeek V3) which store per-tensor quantization scales as scalar float32 tensors. Repro: `torch.zeros(4).view(torch.float32).view(*[])` Fix: use `view(shape)` instead of `view(*shape)` — passing the shape list directly instead of unpacking it handles empty lists correctly. Co-authored-by: Isaac --- instanttensor/_impl.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/instanttensor/_impl.py b/instanttensor/_impl.py index 01bab8f..4503640 100644 --- a/instanttensor/_impl.py +++ b/instanttensor/_impl.py @@ -554,7 +554,7 @@ def tensors(self) -> Generator[tuple[str, torch.Tensor], None, None]: tensor_size = get_tensor_size(shape, torch_dtype) dl_tensor = instanttensor._C.get_dl_tensor(self.loader_handle, tensor_index, tensor_size) # always returns int8 tensor tensor_int8 = torch.from_dlpack(dl_tensor) - tensor = tensor_int8.view(torch_dtype).view(*shape) + tensor = tensor_int8.view(torch_dtype).reshape(shape) if tensor.data_ptr() % tensor.element_size() != 0: raise ValueError(f"Tensor {name} address {tensor.data_ptr():#x} is not aligned to dtype {torch_dtype} size {tensor.element_size()}B") From a10e4577e8d69cc4c1bdf84c8ba7d920a43ba0a9 Mon Sep 17 00:00:00 2001 From: vector Date: Thu, 26 Mar 2026 12:04:48 +0800 Subject: [PATCH 2/2] Fix tensor reshaping to use view with Size --- instanttensor/_impl.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/instanttensor/_impl.py b/instanttensor/_impl.py index 4503640..245b33e 100644 --- a/instanttensor/_impl.py +++ b/instanttensor/_impl.py @@ -554,7 +554,7 @@ def tensors(self) -> Generator[tuple[str, torch.Tensor], None, None]: tensor_size = get_tensor_size(shape, torch_dtype) dl_tensor = instanttensor._C.get_dl_tensor(self.loader_handle, tensor_index, tensor_size) # always returns int8 tensor tensor_int8 = torch.from_dlpack(dl_tensor) - tensor = tensor_int8.view(torch_dtype).reshape(shape) + tensor = tensor_int8.view(torch_dtype).view(torch.Size(shape)) if tensor.data_ptr() % tensor.element_size() != 0: raise ValueError(f"Tensor {name} address {tensor.data_ptr():#x} is not aligned to dtype {torch_dtype} size {tensor.element_size()}B")