# SFT Algorithm Configuration
sft:
  ## total number of steps to train will equal
  ## min((max_num_epochs * len(train_dataloader)), max_num_steps)
  max_num_epochs: 1
  max_num_steps: 60

  val_period: 10
  val_batches: 8
  val_global_batch_size: 32
  val_micro_batch_size: 1
  val_at_start: true
  seed: 42

checkpointing:
  enabled: true
  checkpoint_dir: "results/sft"
  metric_name: "val_loss"
  higher_is_better: false
  keep_top_k: 3
  save_period: 10

policy:
  model_name: "meta-llama/Llama-3.2-1B"
  tokenizer:
    name: ${policy.model_name} ## specify if you'd like to use a tokenizer different from the model's default
    chat_template: "{% for message in messages %}{%- if message['role'] == 'system'  %}{{'Context: ' + message['content'].strip()}}{%- elif message['role'] == 'user'  %}{{' Question: ' + message['content'].strip() + ' Answer:'}}{%- elif message['role'] == 'assistant'  %}{{' ' + message['content'].strip()}}{%- endif %}{% endfor %}"
  train_global_batch_size: 32
  train_micro_batch_size: 1
  max_total_sequence_length: 1024
  precision: "bfloat16"
  fsdp_offload_enabled: false
  activation_checkpointing_enabled: false

  dtensor_cfg:
    enabled: true
    cpu_offload: False
    sequence_parallel: false
    activation_checkpointing: false
    tensor_parallel_size: 1
  
  dynamic_batching:
    enabled: false

  # makes the training sequence length divisible by the tensor parallel size
  # this is useful for sequence parallel training
  make_sequence_length_divisible_by: ${policy.dtensor_cfg.tensor_parallel_size}
  max_grad_norm: 1.0

  optimizer:
    name: "torch.optim.AdamW"
    kwargs:
      lr: 5.0e-6
      weight_decay: 0.1
      betas: [0.9, 0.98]
      eps: 1e-5
      # when using Dtensor, we need to set foreach
      # and fused to False
      foreach: False
      fused: False
    
data:
  max_input_seq_length: ${policy.max_total_sequence_length}
  dataset_name: "squad"
  add_bos: true
  add_eos: true
  add_generation_prompt: false

logger:
  log_dir: "logs"  # Base directory for all logs
  wandb_enabled: true # Make sure you do a ``wandb login [Your API key]'' before running
  tensorboard_enabled: true
  monitor_gpus: false  # If true, will monitor GPU usage and log to wandb and/or tensorboard
  wandb:
    project: "sft-dev"
    name: "sft-dev-${data.dataset_name}"
  tensorboard:
    log_dir: "tb_logs-sft-dev-${data.dataset_name}"
  gpu_monitoring:
    collection_interval: 10  # How often to collect GPU usage metrics (in seconds)
    flush_interval: 10  # How often to flush GPU usage metrics to the loggers (in seconds)

cluster:
  gpus_per_node: 1
  num_nodes: 1
