[MPS] `torch.mm` raises opaque function-state RuntimeError for `bool` matrices
- Dominant language
- Python
- Stars
- 103k
- Forks
- 29.6k
- PR merge metrics
- PR metrics pending
Description
### 🐛 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
```python
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
Contributor guide
Research direction
The issue names no source file or test. Start by running the provided torch.mm reproduction on MPS and tracing the MPS dispatch path for boolean matrices; done means the unsupported dtype produces a clear NotImplementedError or equivalent and a regression test covers the case.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- backend, machine-learning
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Quiet
- Clarity
- Mostly clear
- Newbie friendliness
- 55/100