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

step_scheduler:
  global_batch_size: 16
  local_batch_size: 2
  ckpt_every_steps: 100
  val_every_steps: 100
  max_steps: 50

dist_env:
  backend: nccl
  timeout_minutes: 10

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

distributed:
  strategy: fsdp2
  tp_size: 1
  cp_size: 1
  pp_size: 1
  ep_size: 8

  sequence_parallel: false

  pipeline:
    pp_schedule: interleaved1f1b
    pp_microbatch_size: 2
    round_virtual_stages_to_pp_multiple: down
    scale_grads_in_schedule: false
    layers_per_stage: 7
    patch_inner_model: false
    patch_causal_lm_model: false

model:
  _target_: nemo_automodel.NeMoAutoModelForImageTextToText.from_pretrained
  pretrained_model_name_or_path: moonshotai/Kimi-VL-A3B-Instruct
  backend:
    _target_: nemo_automodel.components.models.common.BackendConfig
    attn: te
    linear: te
    rms_norm: te
    rope_fusion: true
    enable_deepep: true
    fake_balanced_gate: false
    enable_hf_state_dict_adapter: true
    enable_fsdp_optimizations: true

processor:
  _target_: transformers.AutoProcessor.from_pretrained
  pretrained_model_name_or_path: moonshotai/Kimi-VL-A3B-Instruct
  trust_remote_code: true

checkpoint:
  enabled: true
  checkpoint_dir: vlm_checkpoints/kimi2vl/
  model_save_format: safetensors
  save_consolidated: true

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

dataset:
  _target_: nemo_automodel.components.datasets.vlm.datasets.make_cord_v2_dataset
  path_or_dataset: naver-clova-ix/cord-v2
  split: train

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

validation_dataset:
  _target_: nemo_automodel.components.datasets.vlm.datasets.make_cord_v2_dataset
  path_or_dataset: naver-clova-ix/cord-v2
  split: validation

validation_dataloader:
  _target_: torchdata.stateful_dataloader.StatefulDataLoader

optimizer:
  _target_: torch.optim.AdamW
  lr: 1.0e-05
  weight_decay: 0.01
  betas:
  - 0.9
  - 0.95

freeze_config:
  freeze_embeddings: true
  freeze_vision_tower: true
  freeze_language_model: false

# wandb:
#   project: <your_project_name>
#   entity: <your_entity_name>
#   name: kimi2vl_finetune
