seed: 42
output_dir: './output'
load_checkpoint: ''
auto_trans_ckpt: False  # If true, auto transform load_checkpoint to load in distributed model
only_save_strategy: False
resume_training: False
run_mode: 'finetune'
load_ckpt_format: 'ckpt' # recommend use 'safetensors'

# trainer config
trainer:
  type: CausalLanguageModelingTrainer
  model_name: 'qwen2_5_72B'

# runner config
runner_config:
  epochs: 1
  batch_size: 1
  sink_mode: True
  sink_size: 1

# wrapper cell config
runner_wrapper:
  type: MFTrainOneStepCell
  scale_sense:
    type: DynamicLossScaleUpdateCell
    loss_scale_value: 4096
    scale_factor: 2
    scale_window: 1000
  use_clip_grad: True

# optimizer
optimizer:
  type: AdamW
  betas: [0.9, 0.95]
  eps: 1.e-8
  learning_rate: 1.e-6
  weight_decay: 0.01

# lr sechdule
lr_schedule:
  type: CosineWithWarmUpLR
  learning_rate: 1.e-6
  warmup_ratio: 0.01
  total_steps: -1 # -1 means it will load the total steps of the dataset

# dataset
train_dataset: &train_dataset
  data_loader:
    type: MindDataset
    dataset_dir: ""
    shuffle: False
  input_columns: ["input_ids", "target_ids", "attention_mask"]
  construct_args_key: ["input_ids", "labels"]
  num_parallel_workers: 8
  python_multiprocessing: False
  drop_remainder: True
  numa_enable: False
  prefetch_size: 1
train_dataset_task:
  type: CausalLanguageModelDataset
  dataset_config: *train_dataset

use_parallel: True
# parallel context config
parallel:
  parallel_mode: 1 # 0-data parallel, 1-semi-auto parallel, 2-auto parallel, 3-hybrid parallel
  gradients_mean: False
  enable_alltoall: False
  full_batch: True
  search_mode: "sharding_propagation"
  enable_parallel_optimizer: True
  strategy_ckpt_save_file: "./ckpt_strategy.ckpt"
  parallel_optimizer_config:
    gradient_accumulation_shard: False
    parallel_optimizer_threshold: 64
  pipeline_config:
    pipeline_interleave: True
    pipeline_scheduler: seqpipe

# default parallel of device num = 32 910B
parallel_config:
  data_parallel: 1
  model_parallel: 8
  pipeline_stage: 8
  context_parallel: 1
  use_seq_parallel: True
  micro_batch_num: 32
  seq_split_num: 8
  vocab_emb_dp: False
  gradient_aggregation_group: 4
# when model parallel is greater than 1, we can set micro_batch_interleave_num=2, that may accelerate the train process.
micro_batch_interleave_num: 1

# recompute config
recompute_config:
  recompute: False
  select_recompute:
    'feed_forward\.mul': True
    'feed_forward\.activate\.silu': True
    'feed_forward\.reshape': True
    'feed_forward\.w2\.reshape': True
  select_comm_recompute:
    '.*\.norm': [ 6, 2, 1, 0, 0, 0, 0, 0 ]
    '.*\.w_qkv\.reshape': [ 6, 2, 1, 0, 0, 0, 0, 0 ]
    '.*\.w_gate_hidden\.reshape': [ 6, 2, 1, 0, 0, 0, 0, 0 ]
  parallel_optimizer_comm_recompute: False
  mp_comm_recompute: False
  recompute_slice_activation: False

# callbacks
callbacks:
  - type: MFLossMonitor
  - type: CheckpointMonitor
    prefix: "qwen2_5_72B"
    checkpoint_format: "ckpt" # recommend use 'safetensors'
    save_checkpoint_steps: 400
    keep_checkpoint_max: 1
    integrated_save: False

# mindspore context init config
context:
  jit_config:
    jit_level: "O1"
  memory_optimize_level: "O1"
  mode: 0 #0--Graph Mode; 1--Pynative Mode
  device_target: "Ascend"
  max_call_depth: 10000
  max_device_memory: "56GB"
  mempool_block_size: "56GB"
  save_graphs: False
  save_graphs_path: "./graph"
  device_id: 0
  ascend_config:
    precision_mode: "must_keep_origin_dtype"
    parallel_speed_up_json_path: "./research/qwen2_5/parallel_speed_up_72B_32K.json"  # Replace with a real path when needed

# model config
model:
  model_config:
    use_attn_mask_compression: True
    type: LlamaConfig
    batch_size: 1
    seq_length: 32768
    hidden_size: 8192
    num_layers: 80
    num_heads: 64
    n_kv_heads: 8
    vocab_size: 152064
    initializer_range: 0.02
    intermediate_size: 29568
    qkv_has_bias: True
    rms_norm_eps: 1.0e-5
    theta: 1000000.0
    emb_dropout_prob: 0.0
    eos_token_id: 151643
    pad_token_id: 151643
    bos_token_id: 151643
    compute_dtype: "bfloat16"
    layernorm_compute_type: "bfloat16" # "float32"
    softmax_compute_type: "float32"
    rotary_dtype: "float16" # for stable training, suggest configuring float32
    param_init_type: "float32"
    use_past: False
    use_flash_attention: True
    use_past_shard: False
    offset: [0, 0, 0, 0, 0, 0, 0, 0]
    checkpoint_name_or_path: ""
    repetition_penalty: 1.05
    max_decode_length: 1024
    top_k: 0
    top_p: 0.8
    do_sample: False
    extend_method: "None" # support "None", "PI", "NTK"
    fine_grain_interleave: 1
    qkv_concat: True
    # configuration items copied from Qwen
    rotary_pct: 1.0
    rotary_emb_base: 1000000

  arch:
    type: LlamaForCausalLM

profile: False
profiler_level: 1
profile_start_step: 2
profile_stop_step: 3
init_start_profile: False
profile_communication: False
profile_memory: False
layer_scale: False
layer_decay: 0.65
lr_scale_factor: 256