Developer Tools

PyTorch fixes block_diag_scipy dtype for NumPy 2 on Windows

NumPy 2 changed default integer dtype, breaking PyTorch tests on 64-bit Windows.

Deep Dive

A recent pull request to PyTorch (PR #189478) addresses test failures caused by NumPy 2’s change to default integer dtypes on Windows. Previously, PyTorch’s test for `scipy.linalg.block_diag` expected integer output to be `int32` on Windows, but NumPy 2 uses `int64` as the default integer dtype on 64-bit Windows. This mismatch broke both CPU and CUDA variants, particularly on Windows ARM64, where `torch.int64` did not match the expected `torch.int32`.

The fix replaces the hardcoded `IS_WINDOWS` logic with a call to `numpy_to_torch_dtype`, which automatically resolves the underlying platform’s default integer dtype for any NumPy version. This ensures the test correctly expects `int64` on 64-bit Windows with NumPy 2, while remaining backward-compatible with older NumPy versions that use `int32`. The change was reviewed by PyTorch core developers albanD and malfet, and is now merged into the trunk branch. This update is crucial for users running PyTorch on Windows ARM64 or those upgrading to NumPy 2, as it prevents silent data corruption or test failures in linear algebra operations relying on `block_diag`.

Key Points
  • NumPy 2 changes default integer dtype on 64-bit Windows from int32 to int64, breaking PyTorch's block_diag_scipy test.
  • The fix replaces hardcoded Windows dtype with a generic numpy_to_torch_dtype function that auto-adapts to NumPy's actual defaults.
  • Fix applies to both CPU and CUDA variants, ensuring compatibility on Windows ARM64 and across NumPy versions.

Why It Matters

Ensures PyTorch linear algebra operations work correctly with NumPy 2 on all Windows architectures.

📬 Get the top 10 AI stories daily