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
micro_batch_interleave_num: 1

auto_tune: True
filepath_prefix: './autotune'
autotune_per_step: 8

profile: False
profile_start_step: 10
profile_stop_step: 20
profile_memory: True

model:
  model_config:
    type: BloomConfig
    seq_length: 1024
    vocab_size: 250880 
    hidden_size: 4096
    num_layers: 30
    num_heads: 32
    expand_ratio: 4
    hidden_act: "fast_gelu"
    hidden_dropout_rate: 0.1
    attention_dropout_rate: 0.1
    initializer_range: 0.02
    param_init_type: "float16"
    embedding_init_type: "float32"
    layernorm_compute_type: "float32"
    softmax_compute_type: "float16"
    compute_dtype: "float16"
    use_seq_parallel: True
    use_select_recompute: False
    checkpoint_name_or_path: "/home/qianjiahong/ckpt/pretrain/combine.ckpt"
    eos_token_id: 2
    bos_token_id: 1
    repetition_penalty: 1
    max_decode_length: 1024
    top_k: 5
    top_p: 1
  arch:
    type: BloomRewardModel


train_dataset: &train_dataset
  data_loader:
    type: MindDataset
    dataset_dir: ""
    shuffle: True
  input_columns: ["chosen_input_ids", "chosen_attention_mask",
                  "rejected_input_ids", "rejected_attention_mask",
                  "position_id", "loss_mask", "end_ind"]
  output_columns: ["input_ids", "position_id", "attention_mask", "loss_mask", "end_ind"]
  num_parallel_workers: 16
  python_multiprocessing: False
  drop_remainder: True
  batch_size: 4
  repeat: 1
  numa_enable: False
  prefetch_size: 1
  pad_token_id: 2

train_dataset_task:
  type: RewardModelDataset
  dataset_config: *train_dataset

eval_dataset: &eval_dataset
  data_loader:
    type: MindDataset
    dataset_dir: ""
    shuffle: False
  input_columns: ["chosen_input_ids", "chosen_attention_mask",
                  "rejected_input_ids", "rejected_attention_mask",
                  "position_id", "loss_mask", "end_ind"]
  output_columns: ["input_ids", "position_id", "attention_mask", "loss_mask", "end_ind"]
  num_parallel_workers: 8
  python_multiprocessing: False
  drop_remainder: False
  batch_size: 1
  repeat: 1
  numa_enable: False
  prefetch_size: 1

eval_dataset_task:
  type: CausalLanguageModelDataset
  dataset_config: *eval_dataset

processor:
  return_tensors: ms
  tokenizer:
    type: BloomTokenizer
  type: BloomProcessor


context:
  mode: 0 #0--Graph Mode; 1--Pynative Mode
  device_id: 0
  device_target: "Ascend"
  graph_kernel_flags: "--disable_expand_ops=Softmax,Dropout --enable_parallel_fusion=true --reduce_fuse_depth=8 --enable_auto_tensor_inplace=true"
  max_device_memory: "31GB"
  save_graphs: False
  save_graphs_path: "./graph"

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

# parallel
use_parallel: True
parallel:
  parallel_optimizer_config: {"gradient_accumulation_shard": False}
  parallel_mode: 1 # 0-dataset, 1-semi, 2-auto, 3-hybrid
  gradients_mean: False
  loss_repeated_mean: True
  full_batch: True
  search_mode: "sharding_propagation"
  enable_parallel_optimizer: False
  strategy_ckpt_save_file: "./ckpt_strategy.ckpt"

parallel_config:
  data_parallel: 1
  model_parallel: 8
  pipeline_stage: 1
  micro_batch_num: 1
  vocab_emb_dp: False 
  gradient_aggregation_group: 4

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

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

# runner config
runner_config:
  epochs: 1
  batch_size: 4
  sink_mode: True 
  sink_size: 2
  per_epoch_size: 2

runner_wrapper:
  type: MFTrainOneStepCell
  scale_sense:
    type: DynamicLossScaleUpdateCell
    loss_scale_value: 4294967296
    scale_factor: 2
    scale_window: 1000
  use_clip_grad: True

# optimizer
optimizer:
  type: FP32StateAdamWeightDecay
  beta1: 0.9
  beta2: 0.999
  eps: 0.00000001
  weight_decay: 0.0 # 0.1

lr_schedule:
  type: constant_with_warmup
  learning_rate: 0.000005
  warmup_steps: 100
  warmup_lr_init: 0.0

callbacks:
  - type: MFLossMonitor
  - type: CheckpointMointor
    prefix: "mindformers"
    save_checkpoint_steps: 1000
    keep_checkpoint_max: 3
    integrated_save: False
    async_save: False
  - type: ObsMonitor

trainer:
  type: CausalLanguageModelingTrainer
  model_name: 'bloom_7.1b'