zulifeng 5a9bce1274
Some checks failed
CI / Benchmarks (yolo26n, macos-26, 3.13) (push) Has been cancelled
CI / Benchmarks (yolo26n, ubuntu-24.04-arm, 3.13) (push) Has been cancelled
CI / Benchmarks (yolo26n, ubuntu-latest, 3.13) (push) Has been cancelled
CI / Tests (macos-26, 3.13, latest) (push) Has been cancelled
CI / Tests (ubuntu-24.04-arm, 3.13, latest) (push) Has been cancelled
CI / Tests (ubuntu-latest, 3.13, latest) (push) Has been cancelled
CI / Tests (ubuntu-latest, 3.8, 1.8.0, 0.9.0) (push) Has been cancelled
CI / Tests (windows-latest, 3.13, latest) (push) Has been cancelled
CI / SlowTests (export-legacy-torch, ubuntu-latest, 3.10, 1.11.0, 0.12.0) (push) Has been cancelled
CI / SlowTests (export-legacy-torch, ubuntu-latest, 3.10, 1.12.0, 0.13.0) (push) Has been cancelled
CI / SlowTests (export-legacy-torch, ubuntu-latest, 3.10, 1.13.0, 0.14.0) (push) Has been cancelled
CI / SlowTests (export-legacy-torch, ubuntu-latest, 3.11, 2.0.0, 0.15.0) (push) Has been cancelled
CI / SlowTests (export-legacy-torch, ubuntu-latest, 3.11, 2.1.0, 0.16.0) (push) Has been cancelled
CI / SlowTests (export-legacy-torch, ubuntu-latest, 3.12, 2.2.0, 0.17.0) (push) Has been cancelled
CI / SlowTests (export-legacy-torch, ubuntu-latest, 3.9, 1.10.0, 0.11.0) (push) Has been cancelled
CI / SlowTests (export-legacy-torch, ubuntu-latest, 3.9, 1.9.0, 0.10.0) (push) Has been cancelled
CI / SlowTests (macos-26, 3.13, latest) (push) Has been cancelled
CI / SlowTests (ubuntu-24.04-arm, 3.13, latest) (push) Has been cancelled
CI / SlowTests (ubuntu-latest, 3.12, 2.10.0, 0.25.0) (push) Has been cancelled
CI / SlowTests (ubuntu-latest, 3.12, 2.3.0, 0.18.0) (push) Has been cancelled
CI / SlowTests (ubuntu-latest, 3.12, 2.4.0, 0.19.0) (push) Has been cancelled
CI / SlowTests (ubuntu-latest, 3.12, 2.5.0, 0.20.0) (push) Has been cancelled
CI / SlowTests (ubuntu-latest, 3.12, 2.6.0, 0.21.0) (push) Has been cancelled
CI / SlowTests (ubuntu-latest, 3.12, 2.7.0, 0.22.0) (push) Has been cancelled
CI / SlowTests (ubuntu-latest, 3.12, 2.8.0, 0.23.0) (push) Has been cancelled
CI / SlowTests (ubuntu-latest, 3.12, 2.9.0, 0.24.0) (push) Has been cancelled
CI / SlowTests (ubuntu-latest, 3.13, 2.11.0, 0.26.0) (push) Has been cancelled
CI / SlowTests (ubuntu-latest, 3.13, latest) (push) Has been cancelled
CI / SlowTests (ubuntu-latest, 3.8, 1.8.0, 0.9.0) (push) Has been cancelled
CI / SlowTests (windows-latest, 3.13, latest) (push) Has been cancelled
CI / IsolatedExports (push) Has been cancelled
CI / GPU (push) Has been cancelled
CI / RaspberryPi (push) Has been cancelled
CI / NVIDIA_Jetson (JetPack5.1.2, 1.23.5, https://github.com/ultralytics/assets/releases/download/v0.0.0/onnxruntime_gpu-1.16.3-cp38-cp38-linux_aarch64.whl, 3.8, jetson-jp512, https://github.com/ultralytics/assets/releases/download/v0.0.0/torch-2.2.0-cp38-c… (push) Has been cancelled
CI / NVIDIA_Jetson (JetPack6.2, 1.26.4, https://github.com/ultralytics/assets/releases/download/v0.0.0/onnxruntime_gpu-1.20.0-cp310-cp310-linux_aarch64.whl, 3.10, jetson-jp62, https://github.com/ultralytics/assets/releases/download/v0.0.0/torch-2.5.0a0+872d… (push) Has been cancelled
CI / Conda (ubuntu-latest, 3.12) (push) Has been cancelled
Publish Docker Images / Build (, Dockerfile-arm64, linux/arm64, ubuntu-24.04-arm, latest-arm64) (push) Has been cancelled
Publish Docker Images / Build (, Dockerfile-jetson-jetpack4, linux/arm64, ubuntu-24.04-arm, latest-jetson-jetpack4) (push) Has been cancelled
Publish Docker Images / Build (, Dockerfile-jetson-jetpack5, linux/arm64, ubuntu-24.04-arm, latest-jetson-jetpack5) (push) Has been cancelled
Publish Docker Images / Build (, Dockerfile-jetson-jetpack6, linux/arm64, ubuntu-24.04-arm, latest-jetson-jetpack6) (push) Has been cancelled
Publish Docker Images / Build (, Dockerfile-nvidia-arm64, linux/arm64, ubuntu-24.04-arm, latest-nvidia-arm64) (push) Has been cancelled
Publish Docker Images / Build (Dockerfile-jupyter,Dockerfile-cpu,Dockerfile-runner-cpu,Dockerfile-python-export, Dockerfile-python, linux/amd64, ubuntu-latest, latest-python) (push) Has been cancelled
Publish Docker Images / Build (Dockerfile-runner,Dockerfile-export, Dockerfile, linux/amd64, ubuntu-latest, latest) (push) Has been cancelled
Publish Docs / Docs (push) Has been cancelled
Publish to PyPI / check (push) Has been cancelled
CI / Summary (push) Has been cancelled
Publish Docker Images / trigger-actions (push) Has been cancelled
Publish Docker Images / notify (push) Has been cancelled
Publish to PyPI / build (push) Has been cancelled
Publish to PyPI / publish (push) Has been cancelled
Publish to PyPI / sbom (push) Has been cancelled
Publish to PyPI / notify (push) Has been cancelled
feat: add InfiniBand support and fix multi-node DDP for distributed training
## InfiniBand / RDMA support (Dockerfile + entrypoint)
- Base image switched to registry.d-robotics.cc/.../yolo_distributed:v20260611_fix
- Install IB user-space libs: libibverbs1, librdmacm1, ibverbs-providers,
  rdma-core, infiniband-diags, perftest
- Set NCCL IB env vars at build time (NCCL_IB_DISABLE=0, NCCL_IB_GID_INDEX=3,
  NCCL_IB_HCA=mlx5, NCCL_IB_TC=106, NCCL_IB_SL=5, NCCL_NET_GDR_LEVEL=2)
- entrypoint.sh: print IB device info (ibv_devices) on startup for diagnostics

## Multi-node DDP bug fixes (ultralytics/engine/trainer.py)
Three bugs that only surface with NNODES > 1:

1. Wrong device index in _setup_ddp():
   - Before: torch.cuda.set_device(RANK) and torch.device("cuda", RANK)
   - After:  torch.cuda.set_device(LOCAL_RANK) and torch.device("cuda", LOCAL_RANK)
   - RANK is the global rank (0-15 across 2 nodes); LOCAL_RANK is the per-node
     GPU index (0-7). Using global RANK as a CUDA device index fails on node 1
     where RANK 8-15 don't correspond to real GPU indices.

2. Wrong device_ids in DistributedDataParallel constructor:
   - Before: device_ids=[RANK]
   - After:  device_ids=[LOCAL_RANK], find_unused_parameters=False,
             gradient_as_bucket_view=True
   - Same RANK vs LOCAL_RANK confusion; also adds gradient_as_bucket_view for
     lower memory overhead and disables find_unused_parameters (no unused params
     in this model, the flag was causing a spurious warning).

3. Pod hangs after training completes (final_eval deadlock):
   - Root cause: final_eval() called self.validator(model=best.pt) on ALL ranks
     without a RANK guard. The standalone validator path uses
     torch.device("cuda", RANK) — valid for ranks 0-7 on the master node but
     invalid for ranks 8-15 on the worker node, causing immediate crash. Those
     crashed ranks never reached the torch_distributed_zero_first barrier inside
     the validator, so rank 0 waited at that barrier forever → pod hung for 20+
     minutes until manual deletion.
   - Fix: call dist.destroy_process_group() on all ranks before the validator,
     then guard the validator call with if RANK in {-1, 0}. This lets worker
     ranks exit cleanly and runs final validation only on rank 0 (which already
     has the full best.pt checkpoint).

## DetectionValidator dist guard (docker/distributed/detect_val.py)
- After destroy_process_group(), dist.get_world_size() raises ValueError because
  no default process group exists. DetectionValidator.gather_stats() and
  _gather_image_metrics() call dist.get_world_size() unconditionally.
- Fix: add `if not dist.is_initialized(): return` at the top of both methods.
  When rank 0 runs the standalone validator after destroying the group, the
  stats are already fully accumulated from rank 0's inference on all images —
  there is nothing to gather.

## Build script (build_docker.sh)
- Added REPO_ROOT so the build context is the repo root (needed because COPY
  paths like ultralytics/engine/trainer.py are relative to repo root)
- Added DOCKER_PLATFORM variable (default linux/amd64) for cross-platform builds
- Default tag suffix changed from _fix to _ib

## VCJob manifests
- vcjob-ib.yaml: reference manifest with IB env vars, H20-3e nodeSelector,
  PVC dataset mount, rdma/hca resource, batch=128
- vcjob-ib3.yaml: same manifest pointing to v20260611_ib3 (fully fixed image)

Tested on 2-node × 8-GPU H20-3e cluster. Both master and worker pods exit
with status Completed after 100 epochs; final validation metrics are printed
and results saved to /workspace/runs/detect/train/.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-06-11 16:57:57 +08:00

67 lines
2.5 KiB
Bash
Executable File

#!/bin/bash
# YOLO Distributed Training Entrypoint
#
# Reads env vars at runtime:
# Distributed mode (multi-node/multi-GPU):
# MASTER_ADDR - master node IP (triggers distributed mode)
# MASTER_PORT - master port (default: 29500)
# NNODES - total number of nodes (default: 1)
# NPROC_PER_NODE - GPUs per node (default: 1)
# RANK - this node's rank, 0-indexed (default: 0)
# NCCL_* - NCCL env vars passed through to PyTorch
#
# Single-node mode (MASTER_ADDR not set):
# Runs yolo directly, auto-detecting available GPUs.
set -e
CMD_ARGS=("$@")
[ ${#CMD_ARGS[@]} -eq 0 ] && CMD_ARGS=("train")
# --- Distributed mode ---
if [ -n "${MASTER_ADDR}" ]; then
MASTER_PORT="${MASTER_PORT:-29500}"
NNODES="${NNODES:-1}"
NPROC_PER_NODE="${NPROC_PER_NODE:-1}"
RANK="${RANK:-0}"
# Build per-node GPU list for device=0,1,...,N-1
GPU_LIST=$(seq -s, 0 $((NPROC_PER_NODE - 1)))
echo "============================================"
echo " Distributed Training Mode"
echo "============================================"
echo " MASTER_ADDR = ${MASTER_ADDR}"
echo " MASTER_PORT = ${MASTER_PORT}"
echo " NNODES = ${NNODES}"
echo " NPROC_PER_NODE = ${NPROC_PER_NODE}"
echo " RANK (node) = ${RANK}"
echo " WORLD_SIZE = $((NNODES * NPROC_PER_NODE))"
echo " GPU_LIST = ${GPU_LIST}"
echo " CMD = yolo ${CMD_ARGS[*]}"
echo "--------------------------------------------"
echo " IB / NCCL settings"
echo " NCCL_IB_DISABLE = ${NCCL_IB_DISABLE:-0}"
echo " NCCL_IB_GID_INDEX = ${NCCL_IB_GID_INDEX:-3}"
echo " NCCL_NET_GDR_LEVEL= ${NCCL_NET_GDR_LEVEL:-2}"
echo " NCCL_IB_HCA = ${NCCL_IB_HCA:-(auto)}"
# Show available IB devices if ibv_devices is present
command -v ibv_devices &>/dev/null && ibv_devices || true
echo "============================================"
exec torchrun \
--nnodes="${NNODES}" \
--nproc_per_node="${NPROC_PER_NODE}" \
--master_addr="${MASTER_ADDR}" \
--master_port="${MASTER_PORT}" \
--node_rank="${RANK}" \
/workspace/train_ddp.py device="${GPU_LIST}" "${CMD_ARGS[@]}"
else
echo "============================================"
echo " Single-Node Training Mode"
echo "============================================"
echo " CMD = yolo ${CMD_ARGS[*]}"
echo "============================================"
exec yolo "${CMD_ARGS[@]}"
fi