[Performance] mlx.core.conv_general is really slow
Nobody has claimed this yet.
- Dominant language
- C++
- Stars
- 28.5k
- Forks
- 2.3k
- Avg merge
- 3d 8h
- Merged PRs (30d)
- 62
Description
Describe the bug
Method mlx.core.conv_general is significantly slower than PyTorch analog. Can vary from 10x to 150x slower.
To Reproduce
Just run the attached code.
Include code snippet
import mlx.core as mx
import time
import torch
def mlx_sample():
x = mx.random.normal([8, 16, 128, 128, 32], dtype=mx.float32)
weight = mx.random.normal([4, 1, 1, 1, 32], dtype=mx.float32)
stride = [1, 1, 1]
padding = [0, 0, 0]
dilation = [1, 1, 1]
start = time.time()
n = 10
for _ in range(n):
out = mx.conv_general(x, weight, stride, padding, dilation, stream=mx.gpu)
mx.eval(out)
print(f'MLX time: {(time.time() - start) * 1000 / n:0.2f}ms')
def torch_sample():
x = torch.randn([8, 32, 16, 128, 128], dtype=torch.float32, device='mps')
weight = torch.randn([4, 32, 1, 1, 1], dtype=torch.float32, device='mps')
bias = torch.randn([4], dtype=torch.float32, device='mps')
stride = [1, 1, 1]
padding = [0, 0, 0]
dilation = [1, 1, 1]
start = time.time()
n = 10
for _ in range(n):
out = torch.convolution(x, weight, bias, stride, padding, dilation, False, [0, 0, 0], 1)
out.max()
print(f'MPS time: {(time.time() - start) * 1000 / n:0.2f}ms')
def main():
mlx_sample()
torch_sample()
if __name__ == '__main__':
main()
Output:
MLX time: 20.65ms
MPS time: 0.93ms
Expected behavior
At least the same speed as in PyTorch.
Desktop (please complete the following information):
- OS Version: [e.g. MacOS 14.6.1]
- Version [e.g. 0.17.3]
- Tested on M2 Ultra and M1 Pro Max
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by running the supplied Python benchmark for mlx.core.conv_general and compare its MLX and PyTorch timings on the reported Apple silicon setups. Investigate the conv_general implementation and its GPU execution path, then verify that the benchmark shows performance closer to the PyTorch result.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python, pytorch
- Domain
- performance
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100