Add MPS backend for Apple Silicon#1853
Open
imperatormk wants to merge 3 commits intobitsandbytes-foundation:mainfrom
Open
Add MPS backend for Apple Silicon#1853imperatormk wants to merge 3 commits intobitsandbytes-foundation:mainfrom
imperatormk wants to merge 3 commits intobitsandbytes-foundation:mainfrom
Conversation
Adds native Metal GPU acceleration for MPS devices via mps-bitsandbytes. When installed, automatically registers optimized kernels for: - 4-bit quantization (NF4/FP4): quantize, dequantize, gemv - 8-bit blockwise quantization - INT8 linear operations - 8-bit optimizers (Adam, Lion, SGD, RMSprop) Falls back to default PyTorch implementation if mps-bitsandbytes is not installed. Tested on Apple M3 Max with 218/218 Linear4bit tests passing.
Attention operations can produce non-contiguous tensors that fail with .view(). Using .reshape() handles both contiguous and non-contiguous cases.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Dependencies
Requires mps-bitsandbytes for Metal kernels:
Implementation Details
bitsandbytes/backends/mps/module with ops registrationtorch.library.register_kernelfor seamless integration with existingtorch.ops.bitsandbytescallsRegistered kernels:
quantize_4bit,dequantize_4bit,gemv_4bitquantize_blockwise,dequantize_blockwiseint8_linear_matmul,int8_mm_dequant,int8_vectorwise_quant,int8_vectorwise_dequant,int8_scaled_mmoptimizer_update_8bit_blockwise(Adam, Momentum, RMSprop, Lion, AdEMAMix)Notes
12 bf16/fp16 8-bit optimizer test failures: