1e42244b创建于 2025年1月6日历史提交
seed: 0
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
use_parallel: False
run_mode: 'finetune'

# trainer config
trainer:
  type: MultiModalToTextGenerationTrainer
  model_name: 'qwenvl'

# dataset
train_dataset: &train_dataset
  data_loader:
    type: BaseMultiModalDataLoader
    annotation_file: "conversation_file.json"
    shuffle: True
  num_parallel_workers: 1
  python_multiprocessing: False
  drop_remainder: True
  batch_size: 1
  repeat: 1
  numa_enable: False
  prefetch_size: 1
  seed: 2022
  modal_to_text_transform:
    type: BaseXModalToTextTransform
    model_transform_template:
      type: QwenVLContentTransformTemplate
      auto_register: qwenvl_processor.QwenVLContentTransformTemplate
      output_columns: ["input_ids", "images", "image_context_pos", "labels"]
      mode: "train"
      dataset_dir: ""
      modal_content_padding_size: 1
      image_size: 448
      system_message: "You are a helpful assistant."  # 微调时,系统prompt
      user_role_name: user                            # 根据数据集转换实际配置,修改为用户角色名,默认配置为user
      assistant_role_name: assistant                  # 根据数据集转换实际配置,修改为助手角色名,默认配置为assistant
      user_prompt: ""                  # user角色prompt
      assistant_prompt: ""             # assistant角色prompt

    max_length: 2048

  modal_content_input_columns: [ "images" ]
  modal_content_output_columns: [ "images" ]
  modal_content_transforms:
    - type: BatchToTensor
    - type: BatchNormalize
      mean: [ 0.48145466, 0.4578275, 0.40821073 ]
      std: [ 0.26862954, 0.26130258, 0.27577711 ]
      is_hwc: False
  net_input_columns: [ "input_ids", "images", "image_context_pos", "labels" ]
  tokenizer:
    type: QwenVLTokenizer
    auto_register: qwenvl_tokenizer.QwenVLTokenizer
    vocab_file: /path/to/vocab_file

train_dataset_task:
  type: ModalToTextSFTDataset
  dataset_config: *train_dataset
# runner config
runner_config:
  epochs: 3
  batch_size: 4
  sink_mode: True
  sink_size: 1
runner_wrapper:
  type: MFTrainOneStepCell
  scale_sense:
    type: DynamicLossScaleUpdateCell
    loss_scale_value: 64
    scale_factor: 2
    scale_window: 1000
  use_clip_grad: True

# optimizer
optimizer:
  type: FP32StateAdamWeightDecay
  beta1: 0.9
  beta2: 0.95
  eps: 1.e-8
  weight_decay: 0.1

# lr schedule
lr_schedule:
  type: CosineWithWarmUpLR
  learning_rate: 1.e-5
  lr_end: 1.e-6
  warmup_lr_init: 1.e-6
  warmup_steps: 300
  total_steps: -1 # -1 means it will load the total steps of the dataset

# callbacks
callbacks:
  - type: MFLossMonitor
  - type: CheckpointMonitor
    prefix: "qwen-vl_bf16"
    save_checkpoint_steps: 10000
    keep_checkpoint_max: 3
    integrated_save: False
    async_save: False
  - type: ObsMonitor

# default parallel of device num = 8 for Atlas 800T A2
parallel_config:
  data_parallel: 8
  model_parallel: 1
  pipeline_stage: 1
  micro_batch_num: 1
  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: True
  select_recompute: False
  parallel_optimizer_comm_recompute: True
  mp_comm_recompute: False
  recompute_slice_activation: True

model:
  model_config:
    type: QwenVLConfig
    auto_register: qwenvl_config.QwenVLConfig
    freeze_vision: True
    freeze_resampler: False
    freeze_llm: False
    use_past: False
    compute_dtype: "bfloat16"
    param_init_type: "float16"
    softmax_compute_type: "float32"
    is_dynamic: True
    block_size: 32
    num_blocks: 128

    vision_model:
      arch:
        type: QwenVLVisionModel
        auto_register: qwenvl_model.QwenVLVisionModel
      model_config:
        type: QwenVLVisionConfig
        auto_register: qwenvl_config.QwenVLVisionConfig
        hidden_size: 1664
        intermediate_size: 8192
        num_hidden_layers: 48
        num_attention_heads: 16
        image_size: &image_size 448
        patch_size: 14
        gelu_dtype: "float32"
        dropout: 0.0
        attention_dropout: 0.0
        initializer_range: 0.02
        initializer_factor: 1.0

    llm_model:
      arch:
        type: QwenForCausalLM
        auto_register: qwen_model.QwenForCausalLM
      model_config:
        type: QwenConfig
        auto_register: qwenvl_config.QwenConfig
        batch_size: 1
        seq_length: 2048
        hidden_size: 4096
        num_layers: 32
        num_heads: 32
        vocab_size: 151936
        intermediate_size: 11008
        enable_slice_dp: False
        embedding_parallel_optimizer: False
        rms_norm_eps: 1.0e-6
        emb_dropout_prob: 0.0
        eos_token_id: 151643
        pad_token_id: 151643
        ignore_token_id: -100
        layernorm_compute_type: "float32"
        rotary_dtype: "float16"
        use_flash_attention: True
        use_past: False
        is_dynamic: True
        block_size: 32
        num_blocks: 128
        offset: 0
        checkpoint_name_or_path: ""
        repetition_penalty: 1
        max_decode_length: 1024
        top_k: 0
        top_p: 0.8
        do_sample: False
        enable_emb_opt: True
        qkv_concat: False

        # configuration items copied from Qwen
        rotary_pct: 1.0
        rotary_emb_base: 10000
        kv_channels: 128
  arch:
    type: QwenVL
    auto_register: qwenvl_model.QwenVL

# processor
processor:
  type: QwenVLProcessor
  auto_register: qwenvl_processor.QwenVLProcessor
  image_processor:
    type: QwenVLImageProcessor
    auto_register: qwenvl_processor.QwenVLImageProcessor
    image_size: *image_size  # input image size
  tokenizer:
    type: QwenVLTokenizer
    auto_register: qwenvl_tokenizer.QwenVLTokenizer
    max_length: 32
    vocab_file: ""

# mindspore context init config
context:
  mode: 0 #0--Graph Mode; 1--Pynative Mode
  device_target: "Ascend"
  ascend_config:
    precision_mode: "must_keep_origin_dtype"
  max_call_depth: 10000
  max_device_memory: "57GB"
  save_graphs: False
  save_graphs_path: "./graph"
  device_id: 0
  infer_boost: 'off'
  jit_config:
    jit_level: "O1"

# 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_config:
    save_file: "./ckpt_strategy.ckpt"
    only_trainable_params: False
  parallel_optimizer_config:
    gradient_accumulation_shard: False
    parallel_optimizer_threshold: 64

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