-
Notifications
You must be signed in to change notification settings - Fork 4.4k
Enable GTP for heterogeneous MIMO training #6249
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
Changes from all commits
4e87571
2c47a2e
a6fffab
7d26dc7
c43272e
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -48,14 +48,19 @@ def _parse_and_validate() -> argparse.Namespace: | |
| args = parse_args(extra_args_provider) | ||
| validate_hetero_grid_args(args, args.world_size) | ||
| physical_world_size = args.world_size | ||
| # Stock validate_args sets data_parallel_size = world_size // (tp*pp*cp); feed the | ||
| # language module's world (llm_dp; stock tp/pp/cp stay 1, MIMO parallelism is in --llm-*) | ||
| # so it yields llm_dp. The physical world incl. encoder ranks is restored below. | ||
| # Stock validation owns the derived training arguments. Give it the language module's | ||
| # parallel degrees and logical world so its DP/GTP accounting matches the explicit MIMO grid. | ||
| args.tensor_model_parallel_size = args.llm_tp | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. why did we newly introduce this args.tensor_model_parallel_size = args.llm_tp |
||
| args.pipeline_model_parallel_size = args.llm_pp | ||
| args.context_parallel_size = args.llm_cp | ||
| args.expert_model_parallel_size = args.llm_ep | ||
| args.expert_tensor_parallel_size = args.llm_expt_tp or 1 | ||
| args.world_size = ( | ||
| args.llm_dp | ||
| * args.tensor_model_parallel_size | ||
| * args.pipeline_model_parallel_size | ||
| * args.context_parallel_size | ||
| * args.llm_tp | ||
| * args.gtp_weight_remat_size | ||
| * args.llm_pp | ||
| * args.llm_cp | ||
| ) | ||
| try: | ||
| validate_args(args, {"dataloader_type": "external"}) | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,26 +1,78 @@ | ||
| #!/bin/bash | ||
|
|
||
| # Run an eight-rank heterogeneous mock training loop with Nemotron6-MoE VLM 20L. | ||
| # Run heterogeneous mock training with the Nemotron6-MoE VLM 20L recipe. | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. no need to change this comment, avoid unnecessary edits |
||
|
|
||
| set -euo pipefail | ||
|
|
||
| export CUDA_DEVICE_MAX_CONNECTIONS=${CUDA_DEVICE_MAX_CONNECTIONS:-1} | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. why did we add this back ? not needed ? |
||
|
|
||
| TRAIN_ITERS=${TRAIN_ITERS:-20} | ||
| NUM_MICROBATCHES=${NUM_MICROBATCHES:-4} | ||
| EVAL_INTERVAL=${EVAL_INTERVAL:-1} | ||
| EVAL_ITERS=${EVAL_ITERS:-0} | ||
| MICRO_BATCH_SIZE=1 | ||
| LLM_DP=2 | ||
| GLOBAL_BATCH_SIZE=$((MICRO_BATCH_SIZE * NUM_MICROBATCHES * LLM_DP)) | ||
| MICRO_BATCH_SIZE=${MICRO_BATCH_SIZE:-1} | ||
| NNODES=${NNODES:-1} | ||
| NPROC_PER_NODE=${NPROC_PER_NODE:-8} | ||
| ENCODER_TP=${ENCODER_TP:-2} | ||
| ENCODER_DP=${ENCODER_DP:-2} | ||
| LLM_OFFSET=${LLM_OFFSET:-$((ENCODER_TP * ENCODER_DP))} | ||
| LLM_TP=${LLM_TP:-2} | ||
| LLM_CP=${LLM_CP:-1} | ||
| LLM_PP=${LLM_PP:-1} | ||
| LLM_DP=${LLM_DP:-2} | ||
| LLM_EP=${LLM_EP:-4} | ||
| LLM_EXPT_TP=${LLM_EXPT_TP:-1} | ||
| TENSOR_PARALLEL_NUM_WEIGHT_SHARDS=${TENSOR_PARALLEL_NUM_WEIGHT_SHARDS:-${LLM_TP}} | ||
| EXPERT_TENSOR_PARALLEL_NUM_WEIGHT_SHARDS=${EXPERT_TENSOR_PARALLEL_NUM_WEIGHT_SHARDS:-${LLM_EXPT_TP}} | ||
|
|
||
| if ((TENSOR_PARALLEL_NUM_WEIGHT_SHARDS % LLM_TP != 0)); then | ||
| echo "TENSOR_PARALLEL_NUM_WEIGHT_SHARDS must be divisible by LLM_TP" >&2 | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. avoid these verbose checks in the sbatch script, also dont introduce new env variables if not necessary |
||
| exit 2 | ||
| fi | ||
| if ((EXPERT_TENSOR_PARALLEL_NUM_WEIGHT_SHARDS % LLM_EXPT_TP != 0)); then | ||
| echo "EXPERT_TENSOR_PARALLEL_NUM_WEIGHT_SHARDS must be divisible by LLM_EXPT_TP" >&2 | ||
| exit 2 | ||
| fi | ||
|
|
||
| GTP=$((TENSOR_PARALLEL_NUM_WEIGHT_SHARDS / LLM_TP)) | ||
| LLM_SIZE=$((LLM_TP * GTP * LLM_CP * LLM_PP * LLM_DP)) | ||
| EXPECTED_WORLD_SIZE=$((ENCODER_TP * ENCODER_DP + LLM_SIZE)) | ||
| WORLD_SIZE=$((NNODES * NPROC_PER_NODE)) | ||
| if ((WORLD_SIZE != EXPECTED_WORLD_SIZE)); then | ||
| echo "NNODES*NPROC_PER_NODE=${WORLD_SIZE}, but encoder+LLM grids require ${EXPECTED_WORLD_SIZE}" >&2 | ||
| exit 2 | ||
| fi | ||
|
|
||
| GLOBAL_BATCH_SIZE=${GLOBAL_BATCH_SIZE:-$((MICRO_BATCH_SIZE * NUM_MICROBATCHES * LLM_DP * GTP))} | ||
| TORCHRUN_LOG_DIR=${TORCHRUN_LOG_DIR:-"${PWD}/logs/torchrun-$(date +%Y%m%d_%H%M%S)-$$"} | ||
| mkdir -p "${TORCHRUN_LOG_DIR}" | ||
|
|
||
| TORCHRUN_ARGS=( | ||
| --standalone | ||
| --nproc-per-node 8 | ||
| --nproc-per-node "${NPROC_PER_NODE}" | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. the diff should be minimal dont change unnecessary things |
||
| --log-dir "${TORCHRUN_LOG_DIR}" | ||
| --redirects 3 | ||
| --tee 3 | ||
| --tee 0:3 | ||
| ) | ||
| if ((NNODES == 1)); then | ||
| TORCHRUN_ARGS+=(--standalone) | ||
| else | ||
| NODE_RANK=${NODE_RANK:-${SLURM_NODEID:-0}} | ||
| if [[ -z "${MASTER_ADDR:-}" ]]; then | ||
| if [[ -z "${SLURM_JOB_NODELIST:-}" ]]; then | ||
| echo "MASTER_ADDR or SLURM_JOB_NODELIST is required for a multi-node run" >&2 | ||
| exit 2 | ||
| fi | ||
| mapfile -t slurm_nodes < <(scontrol show hostnames "${SLURM_JOB_NODELIST}") | ||
| MASTER_ADDR=${slurm_nodes[0]} | ||
| fi | ||
| MASTER_PORT=${MASTER_PORT:-$((10000 + ${SLURM_JOB_ID:-0} % 50000))} | ||
| TORCHRUN_ARGS+=( | ||
| --nnodes "${NNODES}" | ||
| --node-rank "${NODE_RANK}" | ||
| --master-addr "${MASTER_ADDR}" | ||
| --master-port "${MASTER_PORT}" | ||
| ) | ||
| fi | ||
|
|
||
| uv run --extra ssm python -m torch.distributed.run \ | ||
| "${TORCHRUN_ARGS[@]}" \ | ||
|
|
@@ -71,15 +123,17 @@ uv run --extra ssm python -m torch.distributed.run \ | |
| --seq-length 8192 \ | ||
| --max-position-embeddings 8192 \ | ||
| --bf16 \ | ||
| --encoder-tp 2 \ | ||
| --encoder-dp 2 \ | ||
| --llm-offset 4 \ | ||
| --llm-tp 2 \ | ||
| --llm-cp 1 \ | ||
| --llm-pp 1 \ | ||
| --encoder-tp "${ENCODER_TP}" \ | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. we dont need env variables for this |
||
| --encoder-dp "${ENCODER_DP}" \ | ||
| --llm-offset "${LLM_OFFSET}" \ | ||
| --llm-tp "${LLM_TP}" \ | ||
| --llm-cp "${LLM_CP}" \ | ||
| --llm-pp "${LLM_PP}" \ | ||
| --llm-dp "${LLM_DP}" \ | ||
| --llm-ep 4 \ | ||
| --llm-expt-tp 1 \ | ||
| --llm-ep "${LLM_EP}" \ | ||
| --llm-expt-tp "${LLM_EXPT_TP}" \ | ||
| --tensor-parallel-num-weight-shards "${TENSOR_PARALLEL_NUM_WEIGHT_SHARDS}" \ | ||
| --expert-tensor-parallel-num-weight-shards "${EXPERT_TENSOR_PARALLEL_NUM_WEIGHT_SHARDS}" \ | ||
| --vocab-size 131072 \ | ||
| --micro-batch-size "${MICRO_BATCH_SIZE}" \ | ||
| --global-batch-size "${GLOBAL_BATCH_SIZE}" \ | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
remove