seed: 0
run_mode: 'train'
output_dir: './output' # path to save checkpoint/strategy
load_checkpoint: ""
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

# context
context:
  mode: 0 # 0--Graph Mode; 1--Pynative Mode
  device_target: "Ascend"
  device_id: 0

# aicc
remote_save_url: "Please input obs url on AICC platform."

# runner
runner_config:
  epochs: 3
  batch_size: 4
  sink_mode: True
  sink_size: 2
runner_wrapper:
  type: MFTrainOneStepCell
  scale_sense:
    type: DynamicLossScaleUpdateCell
    loss_scale_value: 4294967296
    scale_factor: 2
    scale_window: 1000
  use_clip_grad: True

# parallel
use_parallel: False
parallel:
  parallel_mode: 0 # 0-data parallel, 1-semi-auto parallel, 2-auto parallel, 3-hybrid parallel
  gradients_mean: True
  search_mode: "sharding_propagation"
  enable_parallel_optimizer: False
parallel_config:
  data_parallel: 1
  model_parallel: 1
  pipeline_stage: 1
  use_seq_parallel: False
  micro_batch_num: 1
  vocab_emb_dp: True
  gradient_aggregation_group: 4
micro_batch_interleave_num: 1

# moe
moe_config:
  expert_num: 1
  capacity_factor: 1.05
  aux_loss_factor: 0.05
  num_experts_chosen: 1

# recompute
recompute_config:
  recompute: False
  select_recompute: False
  parallel_optimizer_comm_recompute: False
  mp_comm_recompute: True
  recompute_slice_activation: False

# autotune
auto_tune: False
filepath_prefix: './autotune'
autotune_per_step: 10

# profile
profile: False
profile_start_step: 1
profile_stop_step: 10
init_start_profile: False
profile_communication: False
profile_memory: True

# Trainer
trainer:
  type: CausalLanguageModelingTrainer
  model_name: 'gpt2'
# if True, do evaluate during the training process. if false, do nothing.
# note that the task trainer should support _evaluate_in_training function.
do_eval: False

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

# eval dataset
eval_dataset: &eval_dataset
  data_loader:
    type: MindDataset
    dataset_dir: ""
    shuffle: False
  input_columns: ["input_ids", "attention_mask"]
  num_parallel_workers: 8
  python_multiprocessing: False
  drop_remainder: False
  repeat: 1
  numa_enable: False
  prefetch_size: 1
eval_dataset_task:
  type: CausalLanguageModelDataset
  dataset_config: *eval_dataset

# model
model:
  model_config:
    type: GPT2Config
    seq_length: 1024
    vocab_size: 50257
    hidden_size: 768
    num_layers: 12
    num_heads: 12
    expand_ratio: 4
    hidden_act: "gelu"
    use_flash_attention: False
    use_prompt_flash_attention: False
    hidden_dropout_rate: 0.1
    attention_dropout_rate: 0.1
    param_init_type: "float32"
    layernorm_compute_type: "float32"
    softmax_compute_type: "float32"
    compute_dtype: "float16"
    checkpoint_name_or_path: "gpt2"
    eos_token_id: 50256
    repetition_penalty: 1
    max_decode_length: 1024
    top_k: 5
    top_p: 1
    do_sample: True
    use_past: False
  arch:
    type: GPT2LMHeadModel

# lr schedule
lr_schedule:
  type: polynomial
  learning_rate: 0.0001
  lr_end: 0.00001
  warmup_steps: 0
  total_steps: -1 # -1 means it will load the total steps of the dataset
layer_scale: False
layer_decay: 0.65

# optimizer
optimizer:
  type: FusedAdamWeightDecay
  beta1: 0.9
  beta2: 0.95
  eps: 0.00000001 # 1e-8
  weight_decay: 0.1
lr_scale: False
lr_scale_factor: 256

# callbacks
callbacks:
  - type: MFLossMonitor
  - type: CheckpointMonitor
    prefix: "gpt"
    save_checkpoint_steps: 1
    integrated_save: True
    save_network_params: True
    save_trainable_params: False
    async_save: False
  - type: ObsMonitor
eval_callbacks:
  - type: ObsMonitor

# metric
metric:
  type: PerplexityMetric

# processor
processor:
  return_tensors: ms
  tokenizer:
    unk_token: '<|endoftext|>'
    bos_token: '<|endoftext|>'
    eos_token: '<|endoftext|>'
    pad_token: '<|endoftext|>'
    type: GPT2Tokenizer
  type: GPT2Processor