training.py 2.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. # Copyright (c) Meta Platforms, Inc. and affiliates.
  2. # This software may be used and distributed according to the terms of the Llama 2 Community License Agreement.
  3. from dataclasses import dataclass
  4. @dataclass
  5. class train_config:
  6. model_name: str="PATH/to/Model"
  7. tokenizer_name: str=None
  8. enable_fsdp: bool=False # shards model parameters, optimizer states and gradients across DDP ranks
  9. low_cpu_fsdp: bool=False # saves cpu memory by loading pretrained model on rank0 only
  10. run_validation: bool=True
  11. batch_size_training: int=4
  12. batching_strategy: str="packing" #alternative: padding
  13. context_length: int=4096
  14. gradient_accumulation_steps: int=1
  15. gradient_clipping: bool = False
  16. gradient_clipping_threshold: float = 1.0
  17. num_epochs: int=3
  18. max_train_step: int=0
  19. max_eval_step: int=0
  20. num_workers_dataloader: int=1
  21. lr: float=1e-4
  22. weight_decay: float=0.0
  23. gamma: float= 0.85 # multiplicatively decay the learning rate by gamma after each epoch
  24. seed: int=42
  25. use_fp16: bool=False
  26. mixed_precision: bool=True
  27. val_batch_size: int=1
  28. dataset = "samsum_dataset"
  29. peft_method: str = "lora" # None, llama_adapter (Caution: llama_adapter is currently not supported with FSDP)
  30. use_peft: bool=False # use parameter efficient fine tuning
  31. from_peft_checkpoint: str="" # if not empty and use_peft=True, will load the peft checkpoint and resume the fine-tuning on that checkpoint
  32. output_dir: str = "PATH/to/save/PEFT/model"
  33. freeze_layers: bool = False
  34. num_freeze_layers: int = 1
  35. freeze_LLM_only: bool = False # Freeze self-attention layers in the language_model. Vision model, multi_modal_projector, cross-attention will be fine-tuned
  36. quantization: str = None
  37. one_gpu: bool = False
  38. save_model: bool = True
  39. dist_checkpoint_root_folder: str="PATH/to/save/FSDP/model" # will be used if using FSDP
  40. dist_checkpoint_folder: str="fine-tuned" # will be used if using FSDP
  41. save_optimizer: bool=False # will be used if using FSDP
  42. use_fast_kernels: bool = False # Enable using SDPA from PyTroch Accelerated Transformers, make use Flash Attention and Xformer memory-efficient kernels
  43. use_wandb: bool = False # Enable wandb for experient tracking
  44. save_metrics: bool = False # saves training metrics to a json file for later plotting
  45. flop_counter: bool = False # Enable flop counter to measure model throughput, can not be used with pytorch profiler at the same time.
  46. flop_counter_start: int = 3 # The step to start profiling, default is 3, which means after 3 steps of warmup stage, the profiler will start to count flops.
  47. use_profiler: bool = False # Enable pytorch profiler, can not be used with flop counter at the same time.
  48. profiler_dir: str = "PATH/to/save/profiler/results" # will be used if using profiler