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

# Full-FT English ASR of Qwen/Qwen2.5-Omni-3B on the AMI meeting corpus.

recipe: FinetuneRecipeForVLM

step_scheduler:
  global_batch_size: 64
  local_batch_size: 8
  ckpt_every_steps: 200
  num_epochs: 1
  max_steps: 2000             # safety cap; epoch typically exhausts first

dist_env:
  backend: nccl
  timeout_minutes: 10

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

model:
  _target_: nemo_automodel.NeMoAutoModelForMultimodalLM.from_pretrained
  pretrained_model_name_or_path: Qwen/Qwen2.5-Omni-3B
  backend:
    _target_: nemo_automodel.components.models.common.BackendConfig
    attn: sdpa
    linear: te
    rms_norm: torch_fp32
    rope_fusion: false
    enable_hf_state_dict_adapter: true

checkpoint:
  enabled: true
  checkpoint_dir: result/checkpoints/qwen2_5_omni_asr_ami
  model_save_format: safetensors
  save_consolidated: true

distributed:
  strategy: fsdp2
  tp_size: 1
  cp_size: 1
  pp_size: 1
  sequence_parallel: false

# Full fine-tune: audio tower + language model trainable; vision tower frozen
# (we never feed images on AMI).
freeze_config:
  freeze_embeddings: false
  freeze_vision_tower: true
  freeze_audio_tower: false
  freeze_language_model: false

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

# Conversation shape (per sample):
#   user(  text=user_prompt + audio=<waveform>  )
#   assistant(  text=<transcript>  )
dataset:
  _target_: nemo_automodel.components.datasets.vlm.datasets.make_hf_audio_asr_dataset
  path_or_dataset: edinburghcstr/ami
  name: ihm
  split: train
  audio_column: audio
  text_column: text
  sampling_rate: 16000
  system_prompt: null
  user_prompt: >-
    Transcribe the following English meeting audio verbatim. Output only the
    raw transcript text with no leading or trailing commentary.
  # Qwen-Omni's Whisper feature extractor has a known off-by-one between
  # ``input_features`` and ``feature_attention_mask`` on sub-second clips.
  # Filtering at 1.0 s costs only the header-only sf.info probe per sample.
  min_audio_duration_seconds: 1.0

dataloader:
  _target_: torchdata.stateful_dataloader.StatefulDataLoader
  num_workers: 2
  collate_fn:
    _target_: nemo_automodel.components.datasets.vlm.collate_fns.qwen2_5_omni_asr_collate_fn

optimizer:
  _target_: torch.optim.AdamW
  betas: [0.9, 0.95]
  eps: 1e-8
  lr: 2.0e-5
  weight_decay: 0.0

wandb:
  project: ${oc.env:WANDB_PROJECT,qwen2_5-omni-asr-ami}
  name: ${oc.env:WANDB_NAME,qwen2_5_omni_3b_asr_ami_fullft}
  dir: ${oc.env:WANDB_DIR,result/wandb}

ci:
  recipe_owner: yuekaizhang
  time: "00:30:00"
