-
Notifications
You must be signed in to change notification settings - Fork 15
feat: optional multi-GPU (DDP) finetuning #21
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
evasnow1992
merged 7 commits into
NVIDIA-BioNeMo:main
from
evasnow1992:evax/finetune-ddp
Jul 13, 2026
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
151ed53
feat(finetune): add optional multi-GPU DDP training
evasnow1992 257df55
feat(kermt-finetune skill): expose optional multi-GPU DDP finetune
evasnow1992 431ed06
refactor(ddp): consolidate determinism + DDP setup into shared helpers
evasnow1992 00b59da
fix(finetune-ddp): normalize loss by global valid-label count under DDP
evasnow1992 e4c4dc0
fix(finetune-ddp): stop dropping data and redundant per-rank validation
evasnow1992 dc9110e
docs(finetune): fix stale --gpus multi-id hint in defaults_finetune.json
evasnow1992 675d02e
refactor(finetune): consolidate DDP finetune into main.py entrypoint
evasnow1992 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
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
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,77 @@ | ||
| # SPDX-FileCopyrightText: Copyright (c) 2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved. | ||
| # SPDX-License-Identifier: Apache-2.0 | ||
| # | ||
| # Licensed under the Apache License, Version 2.0 (the "License"); | ||
| # you may not use this file except in compliance with the License. | ||
| # You may obtain a copy of the License at | ||
| # | ||
| # http://www.apache.org/licenses/LICENSE-2.0 | ||
| # | ||
| # Unless required by applicable law or agreed to in writing, software | ||
| # distributed under the License is distributed on an "AS IS" BASIS, | ||
| # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| # See the License for the specific language governing permissions and | ||
| # limitations under the License. | ||
| """ | ||
| Shared DistributedDataParallel (DDP) helpers for KERMT. | ||
|
|
||
| Used by the pretraining and finetuning DDP launchers so both share a single, | ||
| proven single-node DDP bootstrap. The logic here matches what pretraining has | ||
| used in production (localhost rendezvous, NCCL backend, per-process GPU pinning | ||
| by rank, and topology-aware NCCL P2P configuration). | ||
| """ | ||
| import os | ||
| import subprocess | ||
|
|
||
| import torch | ||
| from torch.distributed import init_process_group | ||
|
|
||
|
|
||
| def configure_nccl_for_topology(): | ||
|
evasnow1992 marked this conversation as resolved.
|
||
| """ | ||
| Auto-configure NCCL settings based on GPU topology. | ||
| This handles cases where P2P (peer-to-peer) GPU communication is not available. | ||
| Must be called BEFORE spawning processes (in main process). | ||
| """ | ||
| # Check if user has already set NCCL settings (don't override) | ||
| if "NCCL_P2P_DISABLE" in os.environ: | ||
| print(f"[INFO] Using user-provided NCCL settings: NCCL_P2P_DISABLE={os.environ['NCCL_P2P_DISABLE']}") | ||
| return | ||
|
|
||
| # Try to detect GPU topology | ||
| try: | ||
| result = subprocess.run(['nvidia-smi', 'topo', '-m'], | ||
| capture_output=True, text=True, timeout=5) | ||
| topo_output = result.stdout | ||
|
|
||
| # Check for poor GPU connectivity (SYS or NODE topology) | ||
| # These topologies typically don't support P2P well | ||
| if 'SYS' in topo_output or 'NODE' in topo_output: | ||
| print("[INFO] Detected cross-NUMA or system-level GPU topology (SYS/NODE).") | ||
| print("[INFO] Disabling P2P for stability. This is normal for multi-socket systems.") | ||
| os.environ["NCCL_P2P_DISABLE"] = "1" | ||
| os.environ["NCCL_IB_DISABLE"] = "1" | ||
| os.environ["NCCL_SHM_DISABLE"] = "0" | ||
| else: | ||
| print("[INFO] GPU topology appears to support P2P. Enabling P2P communication.") | ||
| except Exception as e: | ||
| # If detection fails, use safe defaults (disable P2P) | ||
| print(f"[WARNING] Could not detect GPU topology: {e}") | ||
| print("[INFO] Using safe default: P2P disabled. Set NCCL_P2P_DISABLE=0 to enable if your system supports it.") | ||
| os.environ["NCCL_P2P_DISABLE"] = "1" | ||
| os.environ["NCCL_IB_DISABLE"] = "1" | ||
| os.environ["NCCL_SHM_DISABLE"] = "0" | ||
|
|
||
|
|
||
| def ddp_setup(rank: int, world_size: int): | ||
|
evasnow1992 marked this conversation as resolved.
|
||
| """ | ||
| Initialize the process group for single-node DDP and pin this process to its GPU. | ||
|
|
||
| Args: | ||
| rank: Unique identifier of each process (also the GPU index it is pinned to). | ||
| world_size: Total number of processes. | ||
| """ | ||
| os.environ["MASTER_ADDR"] = "localhost" | ||
| os.environ["MASTER_PORT"] = "12355" | ||
| torch.cuda.set_device(rank) | ||
| init_process_group(backend="nccl", rank=rank, world_size=world_size) | ||
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
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.