Fix multi-GPU loading for quantized models in distributed training#3917
Merged
danielhanchen merged 1 commit intounslothai:mainfrom Feb 9, 2026
Merged
Conversation
When using torchrun with quantized models (4bit/8bit/fp8), each rank
must load the model directly onto its own GPU. The default device_map
("sequential") places everything on GPU 0, causing illegal memory
access errors when Accelerate tries to relocate quantized weights.
Use the existing prepare_device_map() utility from loader_utils to
detect distributed training via LOCAL_RANK/WORLD_SIZE env vars and
override device_map to target each rank's local GPU. This is applied
in both FastLanguageModel.from_pretrained and FastModel.from_pretrained,
covering text, vision, and audio model paths.
Fixes unslothai#3914
be668e0 to
b2a66fc
Compare
Contributor
|
Thanks @Fizza-Mukhtar - had to fix some of your changes - appreciate the help |
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.
Problem
Multi-GPU training fails for quantized (4bit/8bit/fp8) models due to
Accelerate attempting to move the model across devices.
Root Cause
Quantized models cannot be relocated after loading.
The model was loaded before per-rank device placement was enforced.
Solution
Impact
Enables stable multi-GPU training for GRPO and Vision models with quantization.
fixes #3914