Skip to content

Fix crash on scalar tensors in tensors()#6

Merged
arlo-scitix merged 2 commits intoscitix:mainfrom
Bafoleco:fix-scalar-tensor-view
Mar 26, 2026
Merged

Fix crash on scalar tensors in tensors()#6
arlo-scitix merged 2 commits intoscitix:mainfrom
Bafoleco:fix-scalar-tensor-view

Conversation

@Bafoleco
Copy link
Contributor

@Bafoleco Bafoleco commented Mar 25, 2026

Summary

  • view(*shape) in _impl.py crashes when shape is [] (scalar tensor) because view(*[]) expands to view() with no arguments, raising TypeError
  • Fix: reshape(shape) instead of view(*shape)reshape is zero-copy here since the tensor is always contiguous (freshly created from torch.from_dlpack).

Context

This occurs with FP8-quantized models (e.g. DeepSeek V3/V3.2) which store per-tensor quantization scales (input_scale, weight_scale_2) as scalar float32 tensors with shape []. These models have thousands of such tensors.

Minimal repro:

torch.zeros(4).view(torch.float32).view(*[])
# TypeError: view() received an invalid combination of arguments

torch.zeros(4).view(torch.float32).reshape([])
# Works — returns scalar tensor with shape torch.Size([])

Testing

Ran test script locally and seems things still pass

`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
@Bafoleco Bafoleco marked this pull request as draft March 25, 2026 05:12
@Bafoleco Bafoleco marked this pull request as ready for review March 25, 2026 05:25
@Bafoleco
Copy link
Contributor Author

Hey @arlo-scitix, noticed the existing implementation seems to crash for DeepSeek-V3.2, so wondering if we could make a small fix here? Super excited to use this project btw, speeds look really good!

@arlo-scitix
Copy link
Collaborator

Thanks.
Are you using the official model? Could you provide the model’s Hugging Face URL?

@Bafoleco
Copy link
Contributor Author

Thanks. Are you using the official model? Could you provide the model’s Hugging Face URL?

I'm using the NVFP4 quantized version: https://huggingface.co/nvidia/DeepSeek-V3.2-NVFP4/blob/main/model-00016-of-000163.safetensors

@arlo-scitix
Copy link
Collaborator

Got it. Merged.

@arlo-scitix arlo-scitix merged commit 5a6d06b into scitix:main Mar 26, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants