seed: 1234
output_dir: './output' # path to save checkpoint and strategy
load_checkpoint: ''
load_ckpt_format: 'safetensors'  # format of checkpoint files to load
src_strategy_path_or_dir: ''
auto_trans_ckpt: False  # If True, auto transform `load_checkpoint` to load in distributed model
only_save_strategy: False
resume_training: False
use_parallel: True
run_mode: 'train'
print_separate_loss: True

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

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

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

# lr schedule
lr_schedule:
  type: ConstantWarmUpLR
  learning_rate: 1.e-6
  warmup_steps: 0
  total_steps: -1 # -1 means it will load the total steps of the dataset

# Dataset configuration
train_dataset: &train_dataset
  data_loader:
    type: BlendedMegatronDatasetDataLoader
    datasets_type: "GPTDataset"
    sizes:
      - 16000 # Number of training set data samples.
      - 0    # Number of test set data samples. Currently, configuration is not supported.
      - 0    # Number of eval set data samples. Currently, configuration is not supported.
    config:  # GPTDataset Configs
      seed: 1234                         # Data sampling random seed
      split: "1, 0, 0"                   # The usage ratio of training, testing and evaluation sets. Currently, configuration is not supported.
      seq_length: 4096                   # The sequence length of the data set returned.
      eod_mask_loss: False               # Whether to calculate loss at eod.
      reset_position_ids: False          # Whether to reset position_ids at eod.
      create_attention_mask: False       # Whether to return `attention_mask`.
      reset_attention_mask: False        # Whether to reset the `attention_mask` at eod and return a stepped `attention_mask`.
      create_compressed_eod_mask: False  # Whether to return the compressed `attention_mask`.
      eod_pad_length: 128                # Set the length of the compressed `attention_mask`.
      eod: 1                             # The token id of `eod` in the dataset.
      pad: -1                            # The token id of `pad` in the dataset.
      data_path:  # Megatron dataset sampling ratio and path.
        - '1'
        - "/path/megatraon_dataset/wiki103-megatron_text_document"

  num_parallel_workers: 8
  python_multiprocessing: False
  drop_remainder: True
  numa_enable: False
  prefetch_size: 1
  seed: 1234
train_dataset_task:
  type: CausalLanguageModelDataset
  dataset_config: *train_dataset

# mindspore context init config
context:
  mode: 0 # 0--Graph Mode; 1--Pynative Mode
  device_target: "Ascend"
  max_call_depth: 10000
  max_device_memory: "58GB"
  save_graphs: False
  save_graphs_path: "./graph"
  jit_config:
    jit_level: "O0"

# parallel config
parallel_config:
  data_parallel: 1
  model_parallel: 1
  pipeline_stage: 16
  expert_parallel: 1
  micro_batch_num: 16
  use_seq_parallel: 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

# 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: True
  search_mode: "sharding_propagation"
  enable_parallel_optimizer: False
  strategy_ckpt_config:
    save_file: "./ckpt_strategy.ckpt"
    only_trainable_params: False
  parallel_optimizer_config:
    gradient_accumulation_shard: False
    parallel_optimizer_threshold: 8

# recompute config
recompute_config:
  recompute: True
  select_recompute: False
  mp_comm_recompute: False

# model config
use_legacy: False
model:
  model_config:
    model_type: deepseek_v3
    architectures: DeepseekV3ForCausalLM
    offset: 0
    vocab_size: 129280
    seq_length: 4096
    hidden_size: 1792
    intermediate_size: 3072
    num_hidden_layers: 16
    max_position_embeddings: 163840
    hidden_act: 'silu'
    num_attention_heads: 8
    rms_norm_eps: 1.e-6
    add_bias_linear: False
    use_flash_attention: True
    multi_latent_attention: True
    mla_qkv_concat: False
    kv_lora_rank: 512
    q_lora_rank: 1536
    qk_rope_head_dim: 64
    v_head_dim: 192
    qk_nope_head_dim: 128
    qk_layernorm: True
    attention_dropout: 0.0
    hidden_dropout: 0.0
    params_dtype: "float32"
    compute_dtype: "bfloat16"
    layernorm_compute_dtype: "float32"
    softmax_compute_dtype: "float32"
    rotary_dtype: "float32"
    initializer_range: 0.01
    num_nextn_predict_layers: 1
    mtp_loss_scaling_factor: 0.3
    position_embedding_type: "yarn"
    scaling_factor: 40
    beta_fast: 32
    beta_slow: 1
    mscale: 1
    mscale_all_dim: 1
    rope_theta: 10000
    # moe config
    router_dense_type: "float32"
    gated_linear_unit: True
    moe_intermediate_size: 2048
    routed_scaling_factor: 1.5
    first_k_dense_replace: 1
    n_routed_experts: 64
    num_experts_per_tok: 8
    n_shared_experts: 1
    moe_shared_expert_intermediate_size: 2048
    moe_grouped_gemm: True
    moe_router_load_balancing_type: 'seq_aux_loss'
    moe_aux_loss_coeff: 0.001
    scoring_func: 'sigmoid'
    norm_topk_prob: True
    moe_token_drop_policy: probs
    moe_router_enable_expert_bias: True
    moe_router_bias_update_rate: 0.001

# callbacks
callbacks:
  - type: MFLossMonitor
  # balance topk bias with callback
  - type: TopkBiasBalanceCallback
  - type: CheckpointMonitor
    prefix: "deepseekv3"
    save_checkpoint_steps: 100
    keep_checkpoint_max: 1
    integrated_save: False
    async_save: False
    checkpoint_format: "safetensors"  # format of checkpoint files to save

# wrapper cell config
runner_wrapper:
  type: MFTrainOneStepCell
  scale_sense: 1.0
  use_clip_grad: True

profile: False
profile_start_step: 5
profile_stop_step: 7
init_start_profile: False
profile_communication: False
profile_memory: True