# 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.

# Configuration for fine-tuning Gemma 3 VL 4B with CORD-V2 dataset for image description


step_scheduler:
  global_batch_size: 8
  local_batch_size: 8
  ckpt_every_steps: 100
  val_every_steps: 10000  # will run every x number of gradient steps
  max_steps: 10000

dist_env:
  backend: nccl
  timeout_minutes: 10

rng:
  _target_: nemo_automodel.components.training.rng.StatefulRNG
  seed: 42
  ranked: true

model:
  _target_: nemo_automodel.NeMoAutoModelForCausalLM.from_pretrained
  pretrained_model_name_or_path: microsoft/Phi-4-multimodal-instruct
  torch_dtype: torch.bfloat16
  trust_remote_code: true

processor:
  _target_: transformers.AutoProcessor.from_pretrained
  pretrained_model_name_or_path: microsoft/Phi-4-multimodal-instruct
  trust_remote_code: true

checkpoint:
  enabled: true
  checkpoint_dir: phi_4_mm_checkpoints/
  model_save_format: torch_save
  save_consolidated: false

# distributed:
#   _target_: nemo_automodel.components.distributed.megatron_fsdp.MegatronFSDPManager
#   dp_size: none
#   tp_size: 1
#   cp_size: 1

loss_fn:
  _target_: nemo_automodel.components.loss.masked_ce.MaskedCrossEntropy

dataset:
  _target_: nemo_automodel.components.datasets.vlm.datasets.make_cv17_dataset
  path_or_dataset: ysdede/commonvoice_17_tr_fixed
  split: train

dataloader:
  _target_: torchdata.stateful_dataloader.StatefulDataLoader
  num_workers: 0
  pin_memory: true
  collate_fn:
    _target_: nemo_automodel.components.datasets.vlm.collate_fns.phi4_mm_collate_fn

validation_dataset:
  _target_: nemo_automodel.components.datasets.vlm.datasets.make_cv17_dataset
  path_or_dataset: ysdede/commonvoice_17_tr_fixed
  split: validation

validation_dataloader:
  _target_: torchdata.stateful_dataloader.StatefulDataLoader
  collate_fn:
    _target_: nemo_automodel.components.datasets.vlm.collate_fns.phi4_mm_collate_fn
  
optimizer:
  _target_: torch.optim.AdamW
  lr: 1e-5
  weight_decay: 0.01
  betas: [0.9, 0.95]

freeze_config:
  freeze_embeddings: false
  freeze_vision_tower: true
  freeze_language_model: false
  
# Uncomment and configure for W&B logging
# wandb:
#   wandb_project:
#   wandb_entity:
#   wandb_exp_name:
#   wandb_save_dir: