Fix multi-node distributed training with single GPU per node#4143
Conversation
Summary of ChangesHello, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed! This pull request addresses a critical bug affecting multi-node distributed training configurations, specifically when each node utilizes a single GPU. The change ensures that the system correctly identifies and initializes distributed communication, preventing unintended disabling of distributed training and allowing models to leverage multi-node resources as intended. Highlights
🧠 New Feature in Public Preview: You can now enable Memory to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console. Changelog
Activity
Using Gemini Code AssistThe full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips. Invoking Gemini You can request assistance from Gemini at any point by creating a comment using either
Customization To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a Limitations & Feedback Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here. You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension. Footnotes
|
There was a problem hiding this comment.
Code Review
This pull request correctly fixes an issue in multi-node distributed training setups with a single GPU per node. The change introduces a check for the WORLD_SIZE environment variable, preventing distributed training from being incorrectly disabled. The logic is sound. I've added one comment to suggest removing a redundant import statement for better code quality.
| exec(BitsAndBytesConfig__init__, globals()) | ||
|
|
||
| if DEVICE_COUNT == 1: | ||
| import os |
There was a problem hiding this comment.
Good catch, fixed!
|
Fix is tested: now in multi-node, single-gpu setting, correctly launch training with Data Parallel GPUs = 2, and runs as expected. |
e774993 to
44ccf4d
Compare
Datta0
left a comment
There was a problem hiding this comment.
This does make sense to me and seems quite a simple change
mmathew23
left a comment
There was a problem hiding this comment.
There may be some edge cases where are config sets a default value as empty string, but we can patch it if that becomes an issue.
|
@mmathew23 yeah thats a fair point, I was also thinking about that earlier. I figured since its a torchrun override its very rarely set manually, and when it is, throwing an error on a non-integer value would be good to let the user know their env has a bad value set for world size. I didnt test the empty-string case though 😅, for some reason I was thinking since its an env var empty = unset and it'd pick the default, but thinking now I dont think that's true lol. If that becomes an issue someone hits in the future, I am happy to throw up a quick PR to patch that case! |
Fixes #4142
When each node has only one visible GPU (
DEVICE_COUNT == 1), the_prepare_backendpatch incorrectly disables distributed training — even in multi-node setups whereWORLD_SIZE > 1.This adds a
WORLD_SIZEcheck so the patch is only applied when genuinely on a single device in a single-node setup.Changes
One-line change in
unsloth/models/_utils.py:-if DEVICE_COUNT == 1: +if DEVICE_COUNT == 1 and int(os.environ.get("WORLD_SIZE", "1")) <= 1:Context
DEVICE_COUNTcomes fromtorch.cuda.device_count(), which only counts locally visible GPUs. In a multi-node setup with one GPU per node (orCUDA_VISIBLE_DEVICES=0),DEVICE_COUNTis 1, butWORLD_SIZEis > 1. Without this fix,accelerate.state.PartialState._prepare_backendis patched to returnDistributedType.NO, which prevents distributed communication from initializing.