Fix crash on scalar tensors in tensors()#6
Merged
arlo-scitix merged 2 commits intoscitix:mainfrom Mar 26, 2026
Merged
Conversation
`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
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! |
Collaborator
|
Thanks. |
Contributor
Author
I'm using the NVFP4 quantized version: https://huggingface.co/nvidia/DeepSeek-V3.2-NVFP4/blob/main/model-00016-of-000163.safetensors |
Collaborator
|
Got it. Merged. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
view(*shape)in_impl.pycrashes whenshapeis[](scalar tensor) becauseview(*[])expands toview()with no arguments, raisingTypeErrorreshape(shape)instead ofview(*shape)—reshapeis zero-copy here since the tensor is always contiguous (freshly created fromtorch.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 scalarfloat32tensors with shape[]. These models have thousands of such tensors.Minimal repro:
Testing
Ran test script locally and seems things still pass