Developer Tools

PyTorch fixes empty tensor handling on XPU for addmv operation

New patch prevents crashes when matrix-vector multiply gets zero-element inputs on Intel XPU.

Deep Dive

A new commit (0690618) merged into PyTorch's trunk addresses a critical edge case for the `addmv` (matrix-vector multiply with addition) kernel on XPU (Intel's accelerator platform). The patch, authored by Sławomir Siwek and co-authored by Intel engineers Yu Guangye and Wang Eikan, fixes issue #2815 in the intel/torch-xpu-ops repository.

Specifically, the code now properly handles tensors where `mat.numel() == 0` (empty input matrix). Under the old behavior, such inputs could cause undefined behavior or crashes. The fix ensures that when beta equals 0, the output tensor is filled with zeros. Otherwise, the output is computed as `beta * self` (multiplication of the beta scaling factor by the self tensor). The change was reviewed by contributors guangyey and EikanWang and is part of ongoing improvements to PyTorch's XPU support.

Key Points
  • Fix for xpu::addmv_out when input mat has zero elements (numel == 0)
  • Output becomes zeros when beta=0; otherwise output = beta * self
  • Resolves issue #2815 in intel/torch-xpu-ops; merged into PyTorch trunk

Why It Matters

Ensures PyTorch models running on Intel XPUs don't crash on edge-case inputs with empty tensors.

📬 Get the top 10 AI stories daily