mirror of
https://github.com/deepseek-ai/DeepGEMM.git
synced 2026-11-05 00:47:26 +00:00
[PR #483] fix(utils): enhance tensor view contiguity, squeeze safety, and scale indexing #483
Labels
No labels
pull-request
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
deepseek-ai/DeepGEMM#483
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
📋 Pull Request Information
Original PR: https://github.com/deepseek-ai/DeepGEMM/pull/483
Author: @reginaldalfret
Created: 10/25/2026
Status: 🔄 Open
Base:
main← Head:fix/math-utils-contiguous-and-shape-safety📝 Commits (1)
b696727fix(utils): enhance tensor view contiguity, squeeze safety, and scale indexing📊 Changes
3 files changed (+113 additions, -6 deletions)
View changed files
📝
deep_gemm/locality_domain.py(+1 -0)📝
deep_gemm/utils/math.py(+10 -6)➕
tests/test_math_utils.py(+102 -0)📄 Description
Problem
deep_gemm/utils/math.py,pack_ue8m0_to_int()andunpack_ue8m0_from_int()called.view(torch.int)directly onx_intand(x_int >> 23).to(torch.uint8). In PyTorch, if input tensors or intermediate slices are non-contiguous,.view()raisesRuntimeError: view size is not compatible with input tensor's size and stride.per_custom_dims_cast_to_fp8(),sf.squeeze()squeezed all dimensions of size 1. If any dimension specified indimshad size 1 (e.g. batch dimension of 1 or head count 1),sf.squeeze()inadvertently collapsed it to a scalar or lower-rank tensor.cast_back_from_fp8()andcast_back_from_fp4()indexedsf[:, group_idx], raisingIndexErrorwhensfis a 1D tensor.deep_gemm/locality_domain.py,localize()executeddim % t.dim()without checkingt.dim() > 0, raisingZeroDivisionErroron 0-D scalar inputs.Solution
.contiguous()before.view(torch.int)inpack_ue8m0_to_int()andunpack_ue8m0_from_int().excluded_dimsinper_custom_dims_cast_to_fp8()(sf.squeeze(dim=excluded_dims)), preserving requested dimensions of size 1.cast_back_from_fp8()andcast_back_from_fp4().t.dim() > 0inlocalize().tests/test_math_utils.pyverifying all edge cases.🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.