Accelerate documentation
Công cụ tiện ích của Megatron-LM
Công cụ tiện ích của Megatron-LM
MegatronLMPlugin
class accelerate.utils.MegatronLMPlugin
< source >( tp_degree: int = Nonepp_degree: int = Noneuse_custom_fsdp: bool = Noneoverlap_cpu_optimizer_d2h_h2d: bool = Noneno_load_optim: bool = Noneeod_mask_loss: bool = Noneno_save_optim: bool = Noneoptimizer_cpu_offload: bool = Noneuse_precision_aware_optimizer: bool = Nonedecoder_last_pipeline_num_layers: int = Nonerecompute_granularity: str = Nonerecompute_method: str = Nonerecompute_num_layers: int = Noneattention_backend: bool = Noneexpert_model_parallel_size: int = Nonecontext_parallel_size: int = Noneattention_dropout: float = Nonehidden_dropout: float = Noneattention_softmax_in_fp32: bool = Noneexpert_tensor_parallel_size: int = Nonecalculate_per_token_loss: bool = Noneuse_rotary_position_embeddings: bool = Nonenum_micro_batches: int = Nonegradient_clipping: float = Nonesequence_parallelism: bool = Nonerecompute_activations: bool = Noneuse_distributed_optimizer: bool = Nonepipeline_model_parallel_split_rank: int = Nonenum_layers_per_virtual_pipeline_stage: int = Noneis_train_batch_min: str = Truetrain_iters: int = Nonetrain_samples: int = Noneweight_decay_incr_style: str = 'constant'start_weight_decay: float = Noneend_weight_decay: float = Nonelr_decay_style: str = 'linear'lr_decay_iters: int = Nonelr_decay_samples: int = Nonelr_warmup_iters: int = Nonelr_warmup_samples: int = Nonelr_warmup_fraction: float = Nonemin_lr: float = 0consumed_samples: list = Noneno_wd_decay_cond: typing.Callable | None = Nonescale_lr_cond: typing.Callable | None = Nonelr_mult: float = 1.0megatron_dataset_flag: bool = Falseseq_length: int = Noneencoder_seq_length: int = Nonedecoder_seq_length: int = Nonetensorboard_dir: str = Noneset_all_logging_options: bool = Falseeval_iters: int = 100eval_interval: int = 1000return_logits: bool = Falsecustom_train_step_class: typing.Any | None = Nonecustom_train_step_kwargs: dict[str, typing.Any] | None = Nonecustom_model_provider_function: typing.Callable | None = Nonecustom_prepare_model_function: typing.Callable | None = Nonecustom_megatron_datasets_provider_function: typing.Callable | None = Nonecustom_get_batch_function: typing.Callable | None = Nonecustom_loss_function: typing.Callable | None = Noneother_megatron_args: dict[str, typing.Any] | None = None )
Tham số
- tp_degree (
int, mặc định làNone) — Độ song song tensor. - pp_degree (
int, mặc định làNone) — Độ song song hóa pipeline. - num_micro_batches (
int, mặc định làNone) — Số lượng micro-batch. - gradient_clipping (
float, mặc định làNone) — Giá trị cắt gradient dựa trên chuẩn L2 toàn cục (0 để tắt). - sequence_parallelism (
bool, mặc định làNone) — Bật song song hóa chuỗi (sequence parallelism). - recompute_activations (
bool, mặc định làNone) — Bật tính toán lại kích hoạt có chọn lọc. - use_distributed_optimizer (
bool, mặc định làNone) — Bật distributed optimizer. - pipeline_model_parallel_split_rank (
int, mặc định làNone) — Rank nơi encoder và decoder nên được tách ra. - num_layers_per_virtual_pipeline_stage (
int, mặc định làNone) — Số lượng lớp cho mỗi giai đoạn pipeline ảo. - is_train_batch_min (
str, mặc định làTrue) — Nếu cả hai dataloader cho train & eval được chỉ định, tham số này sẽ quyết địnhmicro_batch_size. - train_iters (
int, mặc định làNone) — Tổng số mẫu cần huấn luyện trên tất cả các lần chạy huấn luyện. Lưu ý rằng khi sử dụngMegatronLMDummyScheduler, bạn cần cung cấp train-iters hoặc train-samples. - train_samples (
int, mặc định làNone) — Tổng số mẫu để huấn luyện trên tất cả các lần chạy huấn luyện. Lưu ý rằng khi sử dụngMegatronLMDummyScheduler, bạn cần cung cấp train-iters hoặc train-samples. - weight_decay_incr_style (
str, mặc định là'constant') — Hàm tăng dần weight decay. choices=[“constant”, “linear”, “cosine”]. - start_weight_decay (
float, mặc định làNone) — Hệ số suy giảm trọng số ban đầu cho quy tắc hóa L2. - end_weight_decay (
float, mặc định làNone) — Hệ số suy giảm trọng số cuối của quá trình chạy cho quy tắc hóa L2. - lr_decay_style (
str, mặc định là'linear') — Hàm suy giảm tốc độ học. choices=[‘constant’, ‘linear’, ‘cosine’]. - lr_decay_iters (
int, mặc định làNone) — Số lần lặp cho việc suy giảm tốc độ học. Nếu là None, mặc định sẽ làtrain_iters. - lr_decay_samples (
int, mặc định làNone) — Số lượng mẫu cho việc suy giảm tốc độ học. Nếu là None, mặc định sẽ làtrain_samples. - lr_warmup_iters (
int, mặc định làNone) — Số lần lặp để tăng tuyến tính tốc độ học. - lr_warmup_samples (
int, mặc định làNone) — Số lượng mẫu để tăng tuyến tính tốc độ học. - lr_warmup_fraction (
float, mặc định làNone) — Tỷ lệ phần trăm của lr-warmup-(iters/samples) để làm nóng dần (warmup) tuyến tính tốc độ học (learning rate). - min_lr (
float, mặc định là0) — Giá trị tối thiểu cho tốc độ học. Trình lập lịch sẽ cắt các giá trị nằm dưới ngưỡng này. - consumed_samples (
List, mặc định làNone) — Số lượng mẫu đã được sử dụng theo cùng thứ tự với các dataloader trong lời gọiaccelerator.prepare. - no_wd_decay_cond (
Optional, mặc định làNone) — Điều kiện để vô hiệu hóa weight decay. - scale_lr_cond (
Optional, mặc định làNone) — Điều kiện để điều chỉnh tốc độ học. - lr_mult (
float, mặc định là1.0) — Hệ số nhân tốc độ học. - megatron_dataset_flag (
bool, mặc định làFalse) — Xác định xem định dạng của dataset có tuân theo định dạng Indexed/Cached/MemoryMapped của Megatron-LM hay không. - seq_length (
int, mặc định làNone) — Chiều dài tối đa của chuỗi để xử lý. - encoder_seq_length (
int, mặc định làNone) — Chiều dài tối đa của chuỗi để xử lý cho bộ mã hóa. - decoder_seq_length (
int, mặc định làNone) — Chiều dài tối đa của chuỗi để xử lý cho bộ giải mã. - tensorboard_dir (
str, mặc định làNone) — Đường dẫn để lưu các log tensorboard. - set_all_logging_options (
bool, mặc định làFalse) — Có nên thiết lập tất cả các tùy chọn ghi log hay không. - eval_iters (
int, mặc định là100) — Số lần lặp chạy để đánh giá kiểm chứng/kiểm thử. - eval_interval (
int, mặc định là1000) — Khoảng thời gian giữa các lần chạy đánh giá trên tập kiểm tra. - return_logits (
bool, mặc định làFalse) — Có nên trả về logits từ mô hình hay không. - custom_train_step_class (
Optional, mặc định làNone) — Lớp train step tùy chỉnh. - custom_train_step_kwargs (
Optional, mặc định làNone) — Các tham số kwargs tùy chỉnh cho bước huấn luyện. - custom_model_provider_function (
Optional, mặc định làNone) — Hàm cung cấp model tùy chỉnh. - custom_prepare_model_function (
Optional, mặc định làNone) — Hàm chuẩn bị mô hình tùy chỉnh. - custom_megatron_datasets_provider_function (
Optional, mặc định làNone) — Hàm cung cấp bộ dữ liệu train_valid_test megatron tùy chỉnh. - custom_get_batch_function (
Optional, mặc định làNone) — Hàm lấy batch tùy chỉnh. - custom_loss_function (
Optional, mặc định làNone) — Hàm loss tùy chỉnh. - other_megatron_args (
Optional, mặc định làNone) — Các đối số Megatron-LM khác. Vui lòng tham khảo Megatron-LM.
Plugin cho Megatron-LM để kích hoạt song song hóa tensor, pipeline, sequence và dữ liệu. Đồng thời kích hoạt tính toán lại kích hoạt có chọn lọc và các kernel hợp nhất được tối ưu hóa.
MegatronLMDummyScheduler
lớp accelerate.utils.MegatronLMDummyScheduler
< source >( optimizertotal_num_steps = Nonewarmup_num_steps = 0**kwargs )
Dummy scheduler cung cấp các tham số mô hình hoặc các nhóm tham số, chủ yếu được sử dụng để tuân theo vòng lặp huấn luyện thông thường khi cấu hình scheduler được chỉ định trong tệp cấu hình deepspeed.
MegatronLMDummyDataLoader
lớp accelerate.utils.MegatronLMDummyDataLoader
< source >( **dataset_kwargs )
Dataloader giả lập cung cấp các tham số mô hình hoặc các nhóm tham số, chủ yếu được sử dụng để tuân theo quy trình huấn luyện thông thường
AbstractTrainStep
Lớp trừu tượng cho việc nhóm dữ liệu, truyền tiến và xử lý hàm mất mát.
GPTTrainStep
lớp accelerate.utils.GPTTrainStep
< source >( acceleratorargs )
Lớp bước huấn luyện GPT.
BertTrainStep
lớp accelerate.utils.BertTrainStep
< source >( acceleratorargs )
Lớp bước huấn luyện Bert.
T5TrainStep
lớp accelerate.utils.T5TrainStep
< source >( acceleratorargs )
Lớp bước huấn luyện T5.
avg_losses_across_data_parallel_group
accelerate.utils.avg_losses_across_data_parallel_group
< source >( losses )
Mất trung bình trên nhóm song song dữ liệu.