Skip to content

Fix multi-GPU loading for quantized models in distributed training - #3917

Merged
danielhanchen merged 1 commit into
unslothai:mainfrom
Fizza-Mukhtar:fix/grpo-multigpu-quantized-loading-v2
Feb 9, 2026
Merged

danielhanchen merged 1 commit into
unslothai:mainfrom
Fizza-Mukhtar:fix/grpo-multigpu-quantized-loading-v2

Conversation

@Fizza-Mukhtar

Copy link
Copy Markdown
Contributor

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

  • Detect distributed training at load time
  • Load quantized models on the correct per-rank GPU
  • Preserve existing behavior for single-GPU and expert users

Impact

Enables stable multi-GPU training for GRPO and Vision models with quantization.

fixes #3914

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 #3914
@danielhanchen

Copy link
Copy Markdown
Member

Thanks @Fizza-Mukhtar - had to fix some of your changes - appreciate the help

@danielhanchen
danielhanchen merged commit da1eacc into unslothai:main Feb 9, 2026
@Fizza-Mukhtar
Fizza-Mukhtar deleted the fix/grpo-multigpu-quantized-loading-v2 branch February 10, 2026 06:42
abiswas-realadvice pushed a commit to abiswas-realadvice/unsloth that referenced this pull request May 14, 2026
…nslothai#3917)

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

Co-authored-by: Daniel Hanchen <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Qwen3_VL_(8B)-Vision-GRPO.ipynb failed when use multiple GPUs

2 participants