File size: 7,475 Bytes
0647375 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 | root@1ef1af939ad2:/opt/Megatron-Bridge# history
1 nvidia-smi
2 pwd
3 ls
4 export HF_MODEL_PATH=nvidia/NVIDIA-Nemotron-Nano-12B-v2-VL-BF16
5 export MEGATRON_MODEL_PATH=/models/NVIDIA-Nemotron-Nano-12B-v2-VL-BF16
6 ./scripts/conversion/convert.sh import --hf-model $HF_MODEL_PATH --megatron-path $MEGATRON_MODEL_PATH --trust-remote-code
7 ls
8 cd scripts
9 ls
10 cd..
11 cd ..
12 python examples/conversion/convert_checkpoints.py import --hf-model $HF_MODEL_PATH --megatron-path $MEGATRON_MODEL_PATH --trust-remote-code
13 python examples/conversion/hf_to_megatron_generate_vlm.py --hf_model_path $HF_MODEL_PATH --megatron_model_path $MEGATRON_MODEL_PATH --image_path /data/test.jpg --prompt "Describe this image." --max_new_tokens 100 --use_llava_model
14 torchrun --nproc_per_node=1 examples/conversion/hf_to_megatron_generate_vlm.py --hf_model_path $HF_MODEL_PATH --megatron_model_path $MEGATRON_MODEL_PATH --image_path /data/test.jpg --prompt "Describe this image." --max_new_tokens 100 --use_llava_model
15 nvidia-smi
16 export PYTORCH_CUDA_ALLOC_CONF=expandable_segments:True
17 torchrun --nproc_per_node=1 examples/conversion/hf_to_megatron_generate_vlm.py --hf_model_path $HF_MODEL_PATH --megatron_model_path $MEGATRON_MODEL_PATH --image_path /data/test.jpg --prompt "Describe this image." --max_new_tokens 100 --use_llava_model
18 Command 'torchrun' not found, but can be installed with:
19 sudo apt install python3-torch
20 find . -iname "*nemotron*vl*" -name "*.py"
21 find . -path "*recipes*" -iname "*nemotron*"
22 python examples/recipes/nemotron_vl/finetune_nemotron_nano_v2_vl.py --help
23 cat examples/recipes/nemotron_vl/conf/nemotron_nano_v2_vl_override_example.yaml
24 ls /data/ai_enhanced_photos | head
25 grep -rn "def make_raven_dataset" src/
26 F=src/megatron/bridge/data/vlm_datasets/hf_dataset_makers.py
27 sed -n '1,40p' $F
28 sed -n '117,180p' $F
29 grep -rn "maker_name\|make_raven_dataset" src/ examples/ | grep -v "def make_raven"
30 F=src/megatron/bridge/data/vlm_datasets/hf_dataset_makers.py
31 P=src/megatron/bridge/data/vlm_datasets/hf_provider.py
32 cp $F ${F}.bak; cp $P ${P}.bak
33 cat >> $F <<'EOF'
34 F=src/megatron/bridge/data/vlm_datasets/hf_dataset_makers.py
35 P=src/megatron/bridge/data/vlm_datasets/hf_provider.py
36 cp $F ${F}.bak; cp $P ${P}.bak
37 cat >> $F <<'EOF'
38 sed -i '0,/^\(\s*\)make_raven_dataset,$/s//&\n\1make_house_condition_dataset,/' $P
39 sed -i 's/^\(\s*\)"make_raven_dataset": make_raven_dataset,/&\n\1"make_house_condition_dataset": make_house_condition_dataset,/' $P
40 grep -n "make_house_condition_dataset" $P
41 python -c "
from megatron.bridge.data.vlm_datasets.hf_dataset_makers import make_house_condition_dataset as m
from megatron.bridge.data.vlm_datasets import hf_provider
d = m()
print('examples:', len(d))
print('image type:', type(d[0]['conversation'][0]['content'][0]['image']))
print('answer:', d[0]['conversation'][1]['content'][0]['text'])
"
42 cat > /data/my_ft.yaml <<'EOF'
model:
seq_length: 4096
freeze_language_model: False
freeze_vision_model: False
freeze_vision_projection: False
tensor_model_parallel_size: 1
train:
train_iters: 20
global_batch_size: 8
micro_batch_size: 1
eval_iters: 0
optimizer:
lr: 2e-5
min_lr: 2e-6
scheduler:
lr_warmup_iters: 5
checkpoint:
save: /models/house_condition_lora
save_interval: 20
dist:
use_megatron_fsdp: false
use_torch_fsdp2: false
logger:
log_interval: 1
wandb_project: null
wandb_exp_name: house_condition_test
wandb_entity: null
wandb_save_dir: /models/wandb
dataset:
sequence_length: 4096
maker_name: make_house_condition_dataset
rng:
seed: 42
ddp:
grad_reduce_in_fp32: true
EOF
43 export HF_MODEL_PATH=nvidia/NVIDIA-Nemotron-Nano-12B-v2-VL-BF16
44 export MEGATRON_MODEL_PATH=/models/NVIDIA-Nemotron-Nano-12B-v2-VL-BF16
45 xport PYTORCH_CUDA_ALLOC_CONF=expandable_segments:True WANDB_MODE=disabled
46 export PYTORCH_CUDA_ALLOC_CONF=expandable_segments:True WANDB_MODE=disabled
47 torchrun --nproc_per_node=1 examples/recipes/nemotron_vl/finetune_nemotron_nano_v2_vl.py --config-file /data/my_ft.yaml --hf-model-path $HF_MODEL_PATH --pretrained-checkpoint $MEGATRON_MODEL_PATH --lora-on-language-model --lora-on-vision-model
48 sed -i 's/^\(\s*train_iters:\).*/\1 95/' /data/my_ft.yaml
49 sed -i 's#^\(\s*save:\).*#\1 /models/house_condition_lora_full#' /data/my_ft.yaml
50 sed -i 's/^\(\s*save_interval:\).*/\1 19/' /data/my_ft.yaml
51 grep -E "train_iters|global_batch_size|lr_warmup_iters|save:|save_interval" /data/my_ft.yaml
52 export PYTORCH_CUDA_ALLOC_CONF=expandable_segments:True WANDB_MODE=disabled
53 export HF_MODEL_PATH=nvidia/NVIDIA-Nemotron-Nano-12B-v2-VL-BF16
54 export MEGATRON_MODEL_PATH=/models/NVIDIA-Nemotron-Nano-12B-v2-VL-BF16
55 torchrun --nproc_per_node=1 examples/recipes/nemotron_vl/finetune_nemotron_nano_v2_vl.py --config-file /data/my_ft.yaml --hf-model-path $HF_MODEL_PATH --pretrained-checkpoint $MEGATRON_MODEL_PATH --lora-on-language-model --lora-on-vision-model 2>&1 | tee /models/train_full.log
56 grep -o "iteration *[0-9]*/.*lm loss: [0-9.E+-]*" /models/train_full.log | awk '{print $2, $NF}'
57 find . -iname "*merge*" -name "*.py" | grep -v -e __pycache__ -e tests
58 python examples/peft/merge_lora.py --help
59 export HF_MODEL_PATH=nvidia/NVIDIA-Nemotron-Nano-12B-v2-VL-BF16
60 export MEGATRON_MODEL_PATH=/models/NVIDIA-Nemotron-Nano-12B-v2-VL-BF16
61 export PYTORCH_CUDA_ALLOC_CONF=expandable_segments:True
62 torchrun --nproc_per_node=1 examples/peft/merge_lora.py --lora-checkpoint /models/house_condition_lora_full --pretrained $MEGATRON_MODEL_PATH --hf-model-path $HF_MODEL_PATH --output /models/house_condition_merged --dtype bf16
63 ls -R /models/house_condition_merged | head
64 export HF_MODEL_PATH=nvidia/NVIDIA-Nemotron-Nano-12B-v2-VL-BF16
65 export MEGATRON_MODEL_PATH=/models/NVIDIA-Nemotron-Nano-12B-v2-VL-BF16
66 export LORA_ITER=/models/house_condition_lora_full/iter_0000095
67 export MERGED=/models/house_condition_merged
68 export PYTORCH_CUDA_ALLOC_CONF=expandable_segments:True
69 export PROMPT="Analyze the condition of the room or area of the house shown in this image. List any visible defects, cleanliness issues, and signs of wear-and-tear."
70 ls $LORA_ITER # should list .metadata, *.distcp and possibly run_config.yaml
71 nvidia-smi # check the GPU is free
72 torchrun --nproc_per_node=1 examples/peft/merge_lora.py --lora-checkpoint $LORA_ITER --pretrained $MEGATRON_MODEL_PATH --hf-model-path $HF_MODEL_PATH --output $MERGED --dtype bf16
73 torchrun --nproc_per_node=1 examples/conversion/hf_to_megatron_generate_vlm.py --hf_model_path $HF_MODEL_PATH --megatron_model_path $MERGED --image_path /data/ai_enhanced_photos/house_01_balcony_backyard_enhanced-1.jpg --prompt "$PROMPT" --max_new_tokens 200 --use_llava_model
74 du -sh $MEGATRON_MODEL_PATH /models/house_condition_merged
75 ls -la /models/house_condition_merged/*/ | head
76 history |