-
Notifications
You must be signed in to change notification settings - Fork 241
Qwen3-VL Sequence Packing Example scripts #2380
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
Merged
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
afe227a
init commit
kamran-nvidia d45ca41
Fix linting issue
kamran-nvidia b864656
Merge branch 'main' into kamran/qwen3_vl_seq_packing
kamran-nvidia cd1aaf9
Merge branch 'main' into kamran/qwen3_vl_seq_packing
kamran-nvidia 782f179
Merge branch 'main' into kamran/qwen3_vl_seq_packing
kamran-nvidia 0b169ae
Update src/megatron/bridge/models/qwen_vl/qwen3_vl_step.py
kamran-nvidia 92c8442
Add new scripts for sequence-packing and unpacking fine-tuning config…
kamran-nvidia 717769b
Merge branch 'kamran/qwen3_vl_seq_packing' of github.com:NVIDIA-NeMo/…
kamran-nvidia 1059538
rename scripts
kamran-nvidia e36e86b
Merge branch 'main' into kamran/qwen3_vl_seq_packing
kamran-nvidia 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,130 @@ | ||
| #!/usr/bin/env bash | ||
| # Copyright (c) 2025, NVIDIA CORPORATION. All rights reserved. | ||
| # | ||
| # 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. | ||
|
|
||
| # Workspace directory for checkpoints and results | ||
| WORKSPACE=${WORKSPACE:-/workspace} | ||
|
|
||
| # Before training, make sure to set WANDB_API_KEY or disable wandb logging | ||
| # export WANDB_API_KEY=<your_wandb_api_key> | ||
| # export WANDB_MODE=disabled | ||
|
|
||
| # Test Seq Packing configurations for LoRA finetuning on the dense model | ||
| PRETRAINED_CHECKPOINT=${WORKSPACE}/models/Qwen3-VL-8B-Instruct | ||
| MODEL_NAME=qwen3_vl_8b | ||
| DATASET_NAME=cord_v2 | ||
| SEQ_LENGTH=4096 | ||
| TRAIN_ITERS=50 | ||
| GLOBAL_BATCH_SIZE=32 | ||
| MICRO_BATCH_SIZE=2 | ||
| EVAL_ITERS=10 | ||
| LR=0.00005 | ||
| MIN_LR=0.000005 | ||
| LR_WARMUP_ITERS=10 | ||
| LOG_INTERVAL=1 | ||
| WANDB_PROJECT=megatron-bridge-${DATASET_NAME} | ||
|
|
||
| SEQ_PACKING_CONFIGS=(True False) | ||
|
|
||
| # EP/TP/PP/CP combinations: "EP,TP,PP,CP" configurations | ||
| PARALLELISM_CONFIGS=("1,1,1,1" "1,1,1,2" "1,1,1,4") | ||
|
|
||
| for pack_config in "${SEQ_PACKING_CONFIGS[@]}"; do | ||
| for par_config in "${PARALLELISM_CONFIGS[@]}"; do | ||
| IFS=',' read -r EP TP PP CP <<< "$par_config" | ||
| echo "Running LoRA finetuning pack_sequences_in_batch=$pack_config with EP=$EP TP=$TP PP=$PP CP=$CP" | ||
| uv run python -m torch.distributed.run --nproc_per_node=8 scripts/training/run_recipe.py \ | ||
| --recipe ${MODEL_NAME}_finetune_config \ | ||
| --step_func qwen3_vl_step \ | ||
| --peft_scheme lora \ | ||
| checkpoint.pretrained_checkpoint=$PRETRAINED_CHECKPOINT \ | ||
| model.seq_length=$SEQ_LENGTH \ | ||
| train.train_iters=$TRAIN_ITERS \ | ||
| train.global_batch_size=$GLOBAL_BATCH_SIZE \ | ||
| train.micro_batch_size=$MICRO_BATCH_SIZE \ | ||
| train.eval_iters=$EVAL_ITERS \ | ||
| optimizer.lr=$LR \ | ||
| optimizer.min_lr=$MIN_LR \ | ||
| scheduler.lr_warmup_iters=$LR_WARMUP_ITERS \ | ||
| checkpoint.save=${WORKSPACE}/results/${MODEL_NAME}_lora_seq_pack_${pack_config}_cp${CP} \ | ||
| logger.log_interval=$LOG_INTERVAL \ | ||
| logger.wandb_project=$WANDB_PROJECT \ | ||
| logger.wandb_exp_name=${MODEL_NAME}_${DATASET_NAME}_lora_seq_pack_${pack_config}_cp${CP} \ | ||
| dataset.maker_name=make_${DATASET_NAME}_dataset \ | ||
| dataset.seq_length=$SEQ_LENGTH \ | ||
| dataset.pack_sequences_in_batch=$pack_config \ | ||
| model.expert_model_parallel_size=$EP \ | ||
| model.tensor_model_parallel_size=$TP \ | ||
| model.pipeline_model_parallel_size=$PP \ | ||
| model.context_parallel_size=$CP \ | ||
| model.calculate_per_token_loss=True \ | ||
| ddp.average_in_collective=False \ | ||
| ddp.grad_reduce_in_fp32=True | ||
| done | ||
| done | ||
|
|
||
|
|
||
| # Test Seq Packing configurations for LoRA finetuning on the MoE model | ||
| PRETRAINED_CHECKPOINT=${WORKSPACE}/models/Qwen3-VL-30B-A3B-Instruct | ||
| MODEL_NAME=qwen3_vl_30b_a3b | ||
| DATASET_NAME=cord_v2 | ||
| SEQ_LENGTH=4096 | ||
| TRAIN_ITERS=50 | ||
| GLOBAL_BATCH_SIZE=32 | ||
| MICRO_BATCH_SIZE=2 | ||
| EVAL_ITERS=10 | ||
| LR=0.00005 | ||
| MIN_LR=0.000005 | ||
| LR_WARMUP_ITERS=10 | ||
| LOG_INTERVAL=1 | ||
| WANDB_PROJECT=megatron-bridge-${DATASET_NAME} | ||
|
|
||
| SEQ_PACKING_CONFIGS=(True False) | ||
|
|
||
| # EP/TP/PP/CP combinations: "EP,TP,PP,CP" configurations | ||
| PARALLELISM_CONFIGS=("8,1,1,1" "4,1,1,2" "2,1,1,4") | ||
|
|
||
| for pack_config in "${SEQ_PACKING_CONFIGS[@]}"; do | ||
| for par_config in "${PARALLELISM_CONFIGS[@]}"; do | ||
| IFS=',' read -r EP TP PP CP <<< "$par_config" | ||
| echo "Running LoRA finetuning pack_sequences_in_batch=$pack_config with EP=$EP TP=$TP PP=$PP CP=$CP" | ||
| uv run python -m torch.distributed.run --nproc_per_node=8 scripts/training/run_recipe.py \ | ||
| --recipe ${MODEL_NAME}_finetune_config \ | ||
| --step_func qwen3_vl_step \ | ||
| --peft_scheme lora \ | ||
| checkpoint.pretrained_checkpoint=$PRETRAINED_CHECKPOINT \ | ||
| model.seq_length=$SEQ_LENGTH \ | ||
| train.train_iters=$TRAIN_ITERS \ | ||
| train.global_batch_size=$GLOBAL_BATCH_SIZE \ | ||
| train.micro_batch_size=$MICRO_BATCH_SIZE \ | ||
| train.eval_iters=$EVAL_ITERS \ | ||
| optimizer.lr=$LR \ | ||
| optimizer.min_lr=$MIN_LR \ | ||
| scheduler.lr_warmup_iters=$LR_WARMUP_ITERS \ | ||
| checkpoint.save=${WORKSPACE}/results/${MODEL_NAME}_lora_seq_pack_${pack_config}_ep${EP}_cp${CP} \ | ||
| logger.log_interval=$LOG_INTERVAL \ | ||
| logger.wandb_project=$WANDB_PROJECT \ | ||
| logger.wandb_exp_name=${MODEL_NAME}_${DATASET_NAME}_lora_seq_pack_${pack_config}_ep${EP}_cp${CP} \ | ||
| dataset.maker_name=make_${DATASET_NAME}_dataset \ | ||
| dataset.seq_length=$SEQ_LENGTH \ | ||
| dataset.pack_sequences_in_batch=$pack_config \ | ||
| model.expert_model_parallel_size=$EP \ | ||
| model.tensor_model_parallel_size=$TP \ | ||
| model.pipeline_model_parallel_size=$PP \ | ||
| model.context_parallel_size=$CP \ | ||
| model.calculate_per_token_loss=True \ | ||
| ddp.average_in_collective=False \ | ||
| ddp.grad_reduce_in_fp32=True | ||
| done | ||
| done |
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,128 @@ | ||
| #!/usr/bin/env bash | ||
| # Copyright (c) 2025, NVIDIA CORPORATION. All rights reserved. | ||
| # | ||
| # 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. | ||
|
|
||
| # Workspace directory for checkpoints and results | ||
| WORKSPACE=${WORKSPACE:-/workspace} | ||
|
|
||
| # Before training, make sure to set WANDB_API_KEY or disable wandb logging | ||
| # export WANDB_API_KEY=<your_wandb_api_key> | ||
| # export WANDB_MODE=disabled | ||
|
|
||
| # Test Seq Packing configurations for full finetuning on the dense model | ||
| PRETRAINED_CHECKPOINT=${WORKSPACE}/models/Qwen3-VL-8B-Instruct | ||
| MODEL_NAME=qwen3_vl_8b | ||
| DATASET_NAME=cord_v2 | ||
| SEQ_LENGTH=4096 | ||
| TRAIN_ITERS=50 | ||
| GLOBAL_BATCH_SIZE=32 | ||
| MICRO_BATCH_SIZE=2 | ||
| EVAL_ITERS=10 | ||
| LR=0.00005 | ||
| MIN_LR=0.000005 | ||
| LR_WARMUP_ITERS=10 | ||
| LOG_INTERVAL=1 | ||
| WANDB_PROJECT=megatron-bridge-${DATASET_NAME} | ||
|
|
||
| SEQ_PACKING_CONFIGS=(True False) | ||
|
|
||
| # EP/TP/PP/CP combinations: "EP,TP,PP,CP" configurations | ||
| PARALLELISM_CONFIGS=("1,1,1,1" "1,1,1,2" "1,1,1,4") | ||
|
|
||
| for pack_config in "${SEQ_PACKING_CONFIGS[@]}"; do | ||
| for par_config in "${PARALLELISM_CONFIGS[@]}"; do | ||
| IFS=',' read -r EP TP PP CP <<< "$par_config" | ||
| echo "Running full finetuning pack_sequences_in_batch=$pack_config with EP=$EP TP=$TP PP=$PP CP=$CP" | ||
| uv run python -m torch.distributed.run --nproc_per_node=8 scripts/training/run_recipe.py \ | ||
| --recipe ${MODEL_NAME}_finetune_config \ | ||
| --step_func qwen3_vl_step \ | ||
| checkpoint.pretrained_checkpoint=$PRETRAINED_CHECKPOINT \ | ||
| model.seq_length=$SEQ_LENGTH \ | ||
| train.train_iters=$TRAIN_ITERS \ | ||
| train.global_batch_size=$GLOBAL_BATCH_SIZE \ | ||
| train.micro_batch_size=$MICRO_BATCH_SIZE \ | ||
| train.eval_iters=$EVAL_ITERS \ | ||
| optimizer.lr=$LR \ | ||
| optimizer.min_lr=$MIN_LR \ | ||
| scheduler.lr_warmup_iters=$LR_WARMUP_ITERS \ | ||
| checkpoint.save=${WORKSPACE}/results/${MODEL_NAME}_sft_seq_pack_${pack_config}_cp${CP} \ | ||
| logger.log_interval=$LOG_INTERVAL \ | ||
| logger.wandb_project=$WANDB_PROJECT \ | ||
| logger.wandb_exp_name=${MODEL_NAME}_${DATASET_NAME}_sft_seq_pack_${pack_config}_cp${CP} \ | ||
| dataset.maker_name=make_${DATASET_NAME}_dataset \ | ||
| dataset.seq_length=$SEQ_LENGTH \ | ||
| dataset.pack_sequences_in_batch=$pack_config \ | ||
| model.expert_model_parallel_size=$EP \ | ||
| model.tensor_model_parallel_size=$TP \ | ||
| model.pipeline_model_parallel_size=$PP \ | ||
| model.context_parallel_size=$CP \ | ||
| model.calculate_per_token_loss=True \ | ||
| ddp.average_in_collective=False \ | ||
| ddp.grad_reduce_in_fp32=True | ||
| done | ||
| done | ||
|
|
||
|
|
||
| # Test Seq Packing configurations for full finetuning on the MoE model | ||
| PRETRAINED_CHECKPOINT=${WORKSPACE}/models/Qwen3-VL-30B-A3B-Instruct | ||
| MODEL_NAME=qwen3_vl_30b_a3b | ||
| DATASET_NAME=cord_v2 | ||
| SEQ_LENGTH=4096 | ||
| TRAIN_ITERS=50 | ||
| GLOBAL_BATCH_SIZE=32 | ||
| MICRO_BATCH_SIZE=2 | ||
| EVAL_ITERS=10 | ||
| LR=0.00005 | ||
| MIN_LR=0.000005 | ||
| LR_WARMUP_ITERS=10 | ||
| LOG_INTERVAL=1 | ||
| WANDB_PROJECT=megatron-bridge-${DATASET_NAME} | ||
|
|
||
| SEQ_PACKING_CONFIGS=(True False) | ||
|
|
||
| # EP/TP/PP/CP combinations: "EP,TP,PP,CP" configurations | ||
| PARALLELISM_CONFIGS=("8,1,1,1" "4,1,1,2" "2,1,1,4") | ||
|
|
||
| for pack_config in "${SEQ_PACKING_CONFIGS[@]}"; do | ||
| for par_config in "${PARALLELISM_CONFIGS[@]}"; do | ||
| IFS=',' read -r EP TP PP CP <<< "$par_config" | ||
| echo "Running full finetuning pack_sequences_in_batch=$pack_config with EP=$EP TP=$TP PP=$PP CP=$CP" | ||
| uv run python -m torch.distributed.run --nproc_per_node=8 scripts/training/run_recipe.py \ | ||
| --recipe ${MODEL_NAME}_finetune_config \ | ||
| --step_func qwen3_vl_step \ | ||
| checkpoint.pretrained_checkpoint=$PRETRAINED_CHECKPOINT \ | ||
| model.seq_length=$SEQ_LENGTH \ | ||
| train.train_iters=$TRAIN_ITERS \ | ||
| train.global_batch_size=$GLOBAL_BATCH_SIZE \ | ||
| train.micro_batch_size=$MICRO_BATCH_SIZE \ | ||
| train.eval_iters=$EVAL_ITERS \ | ||
| optimizer.lr=$LR \ | ||
| optimizer.min_lr=$MIN_LR \ | ||
| scheduler.lr_warmup_iters=$LR_WARMUP_ITERS \ | ||
| checkpoint.save=${WORKSPACE}/results/${MODEL_NAME}_sft_seq_pack_${pack_config}_ep${EP}_cp${CP} \ | ||
| logger.log_interval=$LOG_INTERVAL \ | ||
| logger.wandb_project=$WANDB_PROJECT \ | ||
| logger.wandb_exp_name=${MODEL_NAME}_${DATASET_NAME}_sft_seq_pack_${pack_config}_ep${EP}_cp${CP} \ | ||
| dataset.maker_name=make_${DATASET_NAME}_dataset \ | ||
| dataset.seq_length=$SEQ_LENGTH \ | ||
| dataset.pack_sequences_in_batch=$pack_config \ | ||
| model.expert_model_parallel_size=$EP \ | ||
| model.tensor_model_parallel_size=$TP \ | ||
| model.pipeline_model_parallel_size=$PP \ | ||
| model.context_parallel_size=$CP \ | ||
| model.calculate_per_token_loss=True \ | ||
| ddp.average_in_collective=False \ | ||
| ddp.grad_reduce_in_fp32=True | ||
| done | ||
| done |
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
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.