[MPS] `torch.mm` raises opaque function-state RuntimeError for `bool` matrices
🐛 Describe the bug
[MPS] torch.mm raises opaque function-state RuntimeError for bool matrices
Description
torch.mm on MPS raises an internal RuntimeError: Failed to create function state object for: matmul_bool when both operands have dtype torch.bool. The same call on CPU is rejected cleanly with NotImplementedError: "addmm_impl_cpu_" not implemented for 'Bool'.
API under test
torch.mm(input, mat2, *, out=None)
Broken convention
torch.mm performs matrix multiplication and expects numeric dtypes suitable for matmul / addmm. Boolean tensors are outside the supported domain for this op.
- Valid: floating and (where implemented) integer numeric dtypes with compatible 2D shapes
(n, m) @ (m, p) - Invalid:
torch.bool(no boolean matrix-multiply kernel)
CPU enforces this with a clear dtype rejection. MPS does not guard at dispatch and instead routes the call into a Metal kernel path (matmul_bool) that fails during function-state initialization.
To Reproduce
import torch
a = torch.randint(0, 2, (4, 4), dtype=torch.bool, device="mps")
b = torch.randint(0, 2, (4, 4), dtype=torch.bool, device="mps")
torch.mm(a, b)
Actual behavior
RuntimeError: Failed to create function state object for: matmul_bool
Expected behavior
Raise a clear NotImplementedError (or equivalent) stating that bool is unsupported for mm on MPS, matching CPU:
NotImplementedError: "addmm_impl_cpu_" not implemented for 'Bool'
Environment
- PyTorch version: 2.8.0
- OS: macOS 26.5 arm64
- Device: Apple Silicon (MPS)
Versions
PyTorch version: 2.12.0
Is debug build: False
CUDA used to build PyTorch: None
ROCM used to build PyTorch: N/A
OS: macOS 26.5 (arm64)
GCC version: Could not collect
Clang version: 21.0.0 (clang-2100.1.1.101)
CMake version: version 4.3.4
Libc version: N/A
Python version: 3.14.5 (main, May 10 2026, 19:20:57) [Clang 22.1.3 ] (64-bit runtime)
Python platform: macOS-26.5-arm64-arm-64bit-Mach-O
Is CUDA available: False
CUDA runtime version: No CUDA
CUDA_MODULE_LOADING set to: N/A
GPU models and configuration: No CUDA
Nvidia driver version: No CUDA
cuDNN version: No CUDA
Is XPU available: False
HIP runtime version: N/A
MIOpen runtime version: N/A
Is XNNPACK available: True
Caching allocator config: N/A
CPU:
Apple M5
Versions of relevant libraries:
[pip3] numpy==2.4.6
[pip3] torch==2.12.0
[conda] Could not collect
cc @malfet @kulinseth @DenisVieriu97 @jhavukainen @aditvenk @Isalia20
Sure, will accept the PR that adds the check and may be OpInfo error test, but not the one to test_mps.py
I'd like to take this. It still reproduces on 2.16.0.dev20261119 (M4), and not only for mm: matmul, bmm and addmm on bool MPS tensors fail the same way (Failed to create function state object for: matmul_bool / naive_bmm_bool / addmm_bool). I'll add the dtype check for these and an OpInfo error-input test, as suggested above.