Skip to content

Comments

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

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

Fix multi-GPU loading for quantized models in distributed training#3917
danielhanchen merged 1 commit intounslothai:mainfrom
Fizza-Mukhtar:fix/grpo-multigpu-quantized-loading-v2

Conversation

@Fizza-Mukhtar
Copy link
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 unslothai#3914
@danielhanchen danielhanchen force-pushed the fix/grpo-multigpu-quantized-loading-v2 branch from be668e0 to b2a66fc Compare February 9, 2026 12:23
@danielhanchen
Copy link
Contributor

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

@danielhanchen danielhanchen merged commit da1eacc into unslothai:main Feb 9, 2026
1 check passed
@Fizza-Mukhtar Fizza-Mukhtar deleted the fix/grpo-multigpu-quantized-loading-v2 branch February 10, 2026 06:42
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