Skip to content
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

Add VLM PEFT test running with 4bit model weights. #11653

Draft
wants to merge 9 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 10 additions & 2 deletions .github/workflows/cicd-main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3626,6 +3626,15 @@ jobs:
AFTER_SCRIPT: |
rm -rf nemo_experiments

L2_VLM_HF_Transformer_PEFT_4bit:
needs: [ cicd-test-container-setup ]
uses: ./.github/workflows/_test_template.yml
if: contains(fromJSON(needs.cicd-test-container-setup.outputs.test_to_run), 'L2_VLM_HF_Transformer_PEFT_4bit') || needs.cicd-test-container-setup.outputs.all == 'true'
with:
RUNNER: self-hosted-azure-gpus-1
SCRIPT: |
TRANSFORMERS_OFFLINE=1 python tests/collections/vlm/hf/peft.py --model /home/TestData/vlm/qwen2-2b/ --max-steps 3 --disable-ckpt --use-4bit

L2_VLM_HF_Transformer_PEFT_FSDP:
needs: [ cicd-test-container-setup ]
uses: ./.github/workflows/_test_template.yml
Expand All @@ -3634,8 +3643,6 @@ jobs:
RUNNER: self-hosted-azure
SCRIPT: |
TRANSFORMERS_OFFLINE=1 python tests/collections/vlm/hf/peft.py --model /home/TestData/vlm/qwen2-2b/ --max-steps 3 --disable-ckpt --strategy fsdp --devices 2
AFTER_SCRIPT: |
rm -rf nemo_experiments

L2_HF_Transformer_PEFT:
needs: [ cicd-test-container-setup ]
Expand Down Expand Up @@ -4917,6 +4924,7 @@ jobs:
- L2_HF_Transformer_SFT_nemorun
- L2_HF_Transformer_SFT_2gpu
- L2_VLM_HF_Transformer_PEFT
- L2_VLM_HF_Transformer_PEFT_4bit
- L2_VLM_HF_Transformer_PEFT_FSDP
- L2_HF_Transformer_SFT_2gpu_nemorun
- L2_HF_Transformer_SFT_TE_Acceleration
Expand Down
4 changes: 3 additions & 1 deletion examples/vlm/hf/peft.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ def fmt(sample):
parser.add_argument('--accelerator', default='gpu', choices=['gpu'])
parser.add_argument('--max-steps', type=int, default=100)
parser.add_argument('--wandb-project', type=str, default=None)
parser.add_argument('--use-4bit', help="Load model in 4bit", action="store_true")
args = parser.parse_args()

wandb = None
Expand All @@ -103,7 +104,7 @@ def fmt(sample):
processor = vlm.HFAutoModelForImageTextToText.configure_processor(args.model)

llm.api.finetune(
model=vlm.HFAutoModelForImageTextToText(args.model),
model=vlm.HFAutoModelForImageTextToText(args.model, load_in_4bit=args.use_4bit),
data=mk_hf_vlm_dataset(processor, args.mbs, args.gbs),
trainer=nl.Trainer(
devices=args.devices,
Expand All @@ -124,5 +125,6 @@ def fmt(sample):
peft=llm.peft.LoRA(
target_modules=['*_proj'],
dim=16,
lora_dtype=torch.bfloat16 if args.use_4bit else None,
),
)
1 change: 1 addition & 0 deletions requirements/requirements_multimodal.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
addict
bitsandbytes==0.45.0
clip
decord; sys_platform == 'linux'
diffusers>=0.19.3
Expand Down
4 changes: 3 additions & 1 deletion tests/collections/vlm/hf/peft.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ def fmt(sample):
parser.add_argument('--max-steps', type=int, default=100)
parser.add_argument('--wandb-project', type=str, default=None)
parser.add_argument('--disable-ckpt', action='store_false')
parser.add_argument('--use-4bit', help="Load model in 4bit", action="store_true")
args = parser.parse_args()

wandb = None
Expand All @@ -103,7 +104,7 @@ def fmt(sample):
processor = vlm.HFAutoModelForImageTextToText.configure_processor(args.model)

llm.api.finetune(
model=vlm.HFAutoModelForImageTextToText(args.model),
model=vlm.HFAutoModelForImageTextToText(args.model, load_in_4bit=args.use_4bit),
data=mk_hf_vlm_dataset(processor, args.mbs, args.gbs),
trainer=nl.Trainer(
devices=args.devices,
Expand All @@ -125,5 +126,6 @@ def fmt(sample):
peft=llm.peft.LoRA(
target_modules=['*_proj'],
dim=16,
lora_dtype=torch.bfloat16 if args.use_4bit else None,
),
)
Loading