1b457c7b创建于 2024年1月11日历史提交
seed: 0
run_mode: 'finetune'
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
  max_device_memory: "59GB"

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

# runner
runner_config:
  epochs: 1
  batch_size: &batch_size 4
  sink_mode: False
  sink_size: 2
runner_wrapper:
  type: MFTrainOneStepCell
  scale_sense:
    type: DynamicLossScaleUpdateCell
    loss_scale_value: 65536
    scale_factor: 2
    scale_window: 400
  use_clip_grad: True
  max_grad_norm: 0.1

# 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
  loss_repeated_mean: True
  full_batch: False
parallel_config:
  data_parallel: 1
  model_parallel: 1
  pipeline_stage: 1
  optimizer_shard: True
  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
  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: 'visualglm_6b'
# 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
  tokenizer:
    type: ChatGLMTokenizer
    max_length: 2048
    vocab_file: "/path_to_vocab/ice_text.model"
  data_loader:
    type: VisualGLMDataLoader
    dataset_dir: "/path_to_dataset/dataset.json"
    shuffle: False
    column_names: ["img", "prompt", "label"]
    file_format: json
    random_mapping: True # if true enlarge original dataset "scale" times
    scale: 4
    tokenizer:
      type: ChatGLMTokenizer
      max_length: 2048
      vocab_file: "/path_to_vocab/ice_text.model"
  seed: 0
  do_eval: False
  input_columns: ["image", "input_ids", "labels", "position_id", "attention_mask"]
  max_source_length: 64
  max_target_length: 256
  num_parallel_workers: 8
  python_multiprocessing: False
  drop_remainder: True
  batch_size: 4
  repeat: 1
  numa_enable: False
  prefetch_size: 1
train_dataset_task:
  type: VisualGLMDataset
  dataset_config: *train_dataset

# eval dataset
eval_dataset: &eval_dataset
  data_loader:
    type: MindDataset
    dataset_dir: "/path_to_dataset/dataset.json"
    shuffle: False
  tokenizer:
    type: ChatGLMTokenizer
    max_length: 1024
    vocab_file: "/path_to_vocab/ice_text.model"
  input_columns: ["img", "prompt", "label"]
  num_parallel_workers: 8
  python_multiprocessing: False
  drop_remainder: True
  repeat: 1
  numa_enable: False
  prefetch_size: 1
eval_dataset_task:
  type: VisualGLMDataset
  dataset_config: *eval_dataset

# model
model:
  model_config:
    type: VisualGLMConfig
    batch_size: *batch_size
    freeze_vision: True
    freeze_text: True
    max_txt_len: 32
    checkpoint_name_or_path: "/path_to_qformer/visualglm_qformer.ckpt"  # visualglm qformer weight
    dtype: "float32"
    compute_dtype: "float16"
    layernorm_dtype: "float32"
    softmax_dtype: "float32"

    qformer_config:
      type: QFormerConfig
      num_hidden_layers: 12 #12
      num_heads: 12
      seq_length: 1
      layer_norm_eps: 1.e-12
      encoder_width: 1408
      query_length: 32
      dtype: "float32"
      compute_dtype: "float16"
      layernorm_dtype: "float32"
      softmax_dtype: "float32"
      hidden_dropout_prob: 0.0
      attention_probs_dropout_prob: 0.0

    vision_config:
      type: ViTConfig
      image_size: 224
      patch_size: 14
      num_channels: 3
      initializer_range: 0.001
      hidden_size: 1408
      num_hidden_layers: 39 # 39
      num_attention_heads: 16
      intermediate_size: 6144
      qkv_bias: True
      hidden_act: gelu
      post_layernorm_residual: false
      layer_norm_eps: 1.0e-6
      attention_probs_dropout_prob: 0.0
      hidden_dropout_prob: 0.0
      drop_path_rate: 0.0
      use_mean_pooling: false
      encoder_stride: 16
      checkpoint_name_or_path: "/path_to_vit/visualglm_vit.ckpt"  # visualglm vit weight

    text_config:
      type: GLMConfig
      vocab_size: 130528
      hidden_size: 4096
      num_layers: 28 # 28
      num_heads: 32
      inner_hidden_size: 16384
      seq_length: 512  # 推理时, 输入pad到的长度, model里的最大句长
      embedding_dropout_prob: 0.0
      attention_dropout_rate: 0.0
      hidden_dropout_rate: 0.0
      hidden_size_per_attention_head: # default "None" means hidden-size/num-attention-heads.
      layernorm_order: "post"
      layernorm_epsilon: 1.0e-5
      use_final_layernorm: True
      use_past: False
      activation_func: 'GELU'
      position_encoding_2d: True
      param_init_type: "float32"
      layernorm_compute_type: "float32"
      softmax_compute_type: "float32"
      compute_dtype: "float16"
      bos_token_id: 130004
      eos_token_id: 130005
      mask_token_id: 130000
      gmask_token_id: 130001
      pad_token_id: 3
      max_decode_length: 2048  # The maximum length of the generated words.
      is_enhanced_encoder: True
      is_sample_acceleration: False
      checkpoint_name_or_path: "/path_to_glm/glm_6b.ckpt"
      top_k: 1
      top_p: 1
      repetition_penalty: 1
      do_sample: True
      pet_config:
        pet_type: lora
        lora_rank: 10
        lora_alpha: 128
        lora_dropout: 0.0
        exclude_layers: [ 'mixins', 'mlp' ]
        pre_seq_len: 4
        target_modules: ''
        layer_range: [ 0, 14 ] # int or list to specify layers to add lora
  arch:
    type: CausalLanguageModelDatasetVisualGLM # Blip2ImageToTextGeneration
# processor
processor:
  type: VisualGLMProcessor
  image_processor:
    type: VisualGLMImageProcessor
    image_size: 224  # input image size
  tokenizer:
    type: ChatGLMTokenizer
    max_length: 2048
    vocab_file: "/path_to_vocab/ice_text.model"

# lr sechdule
lr_schedule:
  type: AnnealingLR
  learning_rate: 0.00001
  warmup_steps: 100
  num_iters: 1500
  total_steps: -1 # -1 means it will load the total steps of the dataset
layer_scale: False
layer_decay: 0.65

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

# callbacks
callbacks:
  - type: MFLossMonitor
  - type: CheckpointMointor
    prefix: "visualglm"
    save_checkpoint_steps: 1500
    integrated_save: True
    save_network_params: False
    save_trainable_params: True
    async_save: False
  - type: ObsMonitor
eval_callbacks:
  - type: ObsMonitor

# metric
metric:
  type: PerplexityMetric