|
| 1 | +from dataclasses import dataclass, field |
| 2 | +from typing import Optional, List |
| 3 | +@dataclass |
| 4 | +class ModelConfig: |
| 5 | + file: str = "examples/contextual_asr/model/slam_model_contextual_asr.py:model_factory" |
| 6 | + llm_name: str = "vicuna-13b-v1.5" |
| 7 | + llm_path: str = "PATH/to/LLAMA/7B" |
| 8 | + llm_type: str = "decoder_only" |
| 9 | + llm_dim: int = 4096 |
| 10 | + encoder_name: Optional[str] = None |
| 11 | + encoder_ds_rate: int = 2 |
| 12 | + encoder_path: Optional[str] = None |
| 13 | + encoder_dim: int = 1280 |
| 14 | + encoder_projector: str = "linear" |
| 15 | + encoder_projector_ds_rate: int = 5 |
| 16 | + modal: str = "audio" |
| 17 | + normalize: Optional[bool] = field(default=False, metadata={ |
| 18 | + "help": "whether input is normalized, used for models such as wavlm" |
| 19 | + }) |
| 20 | + encoder_type: str = field(default="finetune", metadata={ |
| 21 | + "help": "whether model is only pretrained or finetuned, used for models such as hubert" |
| 22 | + }) |
| 23 | + |
| 24 | +@dataclass |
| 25 | +class PeftConfig: |
| 26 | + peft_method: str = "lora" # None , llama_adapter, prefix |
| 27 | + r: int = 8 |
| 28 | + lora_alpha: int = 32 |
| 29 | + # target_modules: List = field(default_factory=lambda: [ "q_proj", "v_proj" ]) |
| 30 | + target_modules: List = field(default_factory=lambda: [ "q_proj", "v_proj","k_proj","o_proj" ]) |
| 31 | + bias: str = "none" |
| 32 | + task_type: str = "CAUSAL_LM" |
| 33 | + lora_dropout: float = 0.05 |
| 34 | + inference_mode: bool = False |
| 35 | + |
| 36 | +@dataclass |
| 37 | +class TrainConfig: |
| 38 | + model_name:str = "PATH/to/LLAMA/7B" |
| 39 | + enable_ddp:bool = False |
| 40 | + enable_deepspeed:bool = False |
| 41 | + enable_fsdp:bool = False |
| 42 | + low_cpu_fsdp:bool = False |
| 43 | + run_validation:bool = True |
| 44 | + batch_size_training:int = 4 |
| 45 | + batching_strategy:str = field(default="packing", metadata={ |
| 46 | + "help":"alternative: padding" |
| 47 | + }) |
| 48 | + context_length:int = 4096 |
| 49 | + gradient_accumulation_steps:int = 1 |
| 50 | + num_epochs:int = 3 |
| 51 | + num_workers_dataloader:int = 1 |
| 52 | + warmup_steps:int = 1000 |
| 53 | + total_steps:int = 100000 |
| 54 | + validation_interval:int = 1000 |
| 55 | + lr:float = 1e-4 |
| 56 | + weight_decay:float = 0.0 |
| 57 | + gamma:float = 0.85 |
| 58 | + seed:int = 42 |
| 59 | + use_fp16:bool = False |
| 60 | + mixed_precision:bool = True |
| 61 | + val_batch_size:int = 1 |
| 62 | + use_peft:bool = False |
| 63 | + peft_config:PeftConfig = field(default_factory=PeftConfig) |
| 64 | + output_dir:str = "PATH/to/save/PEFT/model" |
| 65 | + freeze_layers:bool = False |
| 66 | + num_freeze_layers:int = 1 |
| 67 | + quantization:bool = False |
| 68 | + one_gpu:bool = False |
| 69 | + save_model:bool = True |
| 70 | + dist_checkpoint_root_folder:str = "PATH/to/save/FSDP/model" # will be used if using FSDP |
| 71 | + dist_checkpoint_folder:str = "fine-tuned" # will be used if using FSDP |
| 72 | + save_optimizer:bool = False # will be used if using FSDP |
| 73 | + use_fast_kernels:bool = False # Enable using SDPA from PyTroch Accelerated Transformers, make use Flash Attention and Xformer memory-efficient kernels |
| 74 | + run_test_during_validation:bool = False |
| 75 | + run_test_during_validation_file:str = "test.wav" |
| 76 | + run_test_during_validation_prompt:str = "<|ASR|>" |
| 77 | + freeze_llm:bool = field(default=False, metadata={ |
| 78 | + "help": "whether to freeze llm when finetuning, should be true when use peft finetuning" |
| 79 | + }) |
| 80 | + freeze_encoder:bool = False |
| 81 | + |
| 82 | +@dataclass |
| 83 | +class DataConfig: |
| 84 | + dataset: str = "speech_dataset" |
| 85 | + file: str = "src/slam_llm/datasets/speech_dataset.py:get_speech_dataset" |
| 86 | + train_data_path: Optional[str] = None |
| 87 | + val_data_path: Optional[str] = None |
| 88 | + train_split: str = "train" |
| 89 | + test_split:str = "validation" |
| 90 | + prompt: Optional[str] = None |
| 91 | + data_path: Optional[str] = None |
| 92 | + max_words: Optional[int] = None |
| 93 | + max_mel: Optional[float] = None |
| 94 | + fix_length_audio: int = -1 |
| 95 | + inference_mode:bool = False |
| 96 | + input_type: str = field(default="raw", metadata={ |
| 97 | + "help":"Use raw when input is wav, mel when for whisper" |
| 98 | + }) |
| 99 | + mel_size: int = field(default=80, metadata={ |
| 100 | + "help": "80 for whisper large v1 and v2, 128 for v3" |
| 101 | + }) |
| 102 | + normalize: Optional[bool] = field(default=False, metadata={ |
| 103 | + "help": "whether input is normalized, used for models such as wavlm" |
| 104 | + }) |
| 105 | + infer_type: str = "bias" |
| 106 | + infer_file: str = "/nfs/yangguanrou.ygr/data/fbai-speech/is21_deep_bias/my_ref/test-clean.biasing_100.tsv" |
| 107 | + ctc_file: str = "/nfs/yangguanrou.ygr/data/librispeech_my_infer/wavlm_large_libri_test_other_char.txt" |
| 108 | + common_words_5k_dir: str="/nfs/yangguanrou.ygr/data/fbai-speech/is21_deep_bias/words/common_words_5k.txt" |
| 109 | + probability_threshold: float = 0.9 |
| 110 | + word_num: int = 15 |
| 111 | + filter_infer_sentence: bool = False |
| 112 | + filter_infer_sentence_few: bool = False |
| 113 | + first: int = 1 |
| 114 | + |
| 115 | +@dataclass |
| 116 | +class FSDPConfig: |
| 117 | + mixed_precision: bool = True |
| 118 | + use_fp16: bool = False |
| 119 | + # sharding_strategy = "FULL_SHARD" #ShardingStrategy = ShardingStrategy.FULL_SHARD |
| 120 | + sharding_strategy: str = "NO_SHARD" #ShardingStrategy.NO_SHARD #MZY: set NO_SHARD when use DDP |
| 121 | + checkpoint_type: str = "SHARDED_STATE_DICT" # alternatively can use SHARDED_STATE_DICT save one file per rank, and can resize the world-size. |
| 122 | + fsdp_activation_checkpointing: bool = True |
| 123 | + fsdp_cpu_offload: bool = False |
| 124 | + pure_bf16: bool = False |
| 125 | + optimizer: str = "AdamW" |
| 126 | + |
| 127 | +@dataclass |
| 128 | +class LogConfig: |
| 129 | + use_wandb: bool = False |
| 130 | + wandb_dir: str = "/root/test_wandb" |
| 131 | + wandb_entity_name: str = "project_name" |
| 132 | + wandb_project_name: str = "project_name" |
| 133 | + wandb_exp_name: str = "exp_name" |
| 134 | + log_file: str = "/root/test.log" |
| 135 | + log_interval: int = 5 |
0 commit comments