-
Notifications
You must be signed in to change notification settings - Fork 2.8k
[enhancement]: Fix for MPS producing noise/garbage on AMD RDNA2 GPUs (RX 6000 series on Intel Mac Pro) #9005
Copy link
Copy link
Open
Labels
enhancementNew feature or requestNew feature or request
Description
Is there an existing issue for this?
- I have searched the existing issues
Contact Details
No response
What should this feature add?
If you're running InvokeAI on a Mac Pro with an aftermarket AMD RDNA2 GPU (like the RX 6900 XT) and getting noise/colorful garbage instead of real images, here's the fix.
The Problem
PyTorch's F.linear has a bug in its Metal kernel that produces wrong results on RDNA2 GPUs when input dimensions are >= 256. This affects ALL neural network inference — every model produces garbage on MPS.
The Fix
Save this as mps_rdna2_fix.py in your InvokeAI venv's site-packages directory:
"""Fix for broken F.linear on MPS with AMD RDNA2 GPUs."""
import torch
_patched = False
_original_linear = torch.nn.functional.linear
def _patched_linear(input, weight, bias=None):
if input.device.type == "mps" and input.shape[-1] >= 256:
orig_shape = input.shape
input_2d = input.reshape(-1, orig_shape[-1])
output = torch.mm(input_2d, weight.t().contiguous())
output = output.reshape(*orig_shape[:-1], weight.shape[0])
if bias is not None:
output = output + bias
return output
return _original_linear(input, weight, bias)
def apply():
global _patched
if _patched or not torch.backends.mps.is_available():
return
torch.nn.functional.linear = _patched_linear
_patched = True
print("[mps_rdna2_fix] Patched F.linear for MPS/RDNA2 compatibility")Then create mps_rdna2_fix.pth in the same directory with:
import mps_rdna2_fix; mps_rdna2_fix.apply()
Restart InvokeAI. Images should now generate correctly on MPS.
Affected Hardware
- AMD Radeon RX 6900 XT (confirmed)
- Likely all RDNA2 GPUs: RX 6600, 6700, 6800, 6900 series
- Possibly RDNA1 (RX 5000 series) — unconfirmed
- NOT affected: Vega 56/64 (GCN), which are the stock Mac Pro GPUs
Tested On
- Mac Pro (2019), macOS 15.7.4
- InvokeAI 5.9.1
- PyTorch 2.2.2
- Juggernaut XL v9 (SDXL) — generates correct images at ~1.8 it/s on MPS with the fix
Alternatives
No response
Additional Content
No response
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
enhancementNew feature or requestNew feature or request