-
Notifications
You must be signed in to change notification settings - Fork 989
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Improve config handling and add a zoo (#3029)
* Improve config handling and add a zoo * Docs * rm comment * Tweak doc
- Loading branch information
Showing
13 changed files
with
157 additions
and
39 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
# Config Zoo | ||
|
||
This folder contains a variety of minimal configurations for `Accelerate` achieving certain goals. You can use these | ||
direct config YAML's, or build off of them for your own YAML's. | ||
|
||
These are highly annoted versions, aiming to teach you what each section does. | ||
|
||
Each config can be run via `accelerate launch --config_file {file} run_me.py` | ||
|
||
`run_me.py` will then print out how the current environment is setup (the contents of the `AcceleratorState`) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
# Similar to FSDP, we set the distributed type as DEEPSPEED | ||
distributed_type: DEEPSPEED | ||
# With DeepSpeed, we utilize a deepspeed config file for the entire configuration | ||
deepspeed_config: | ||
# Can also be any of the config json's in accelerate/examples/deepspeed_config_templates | ||
deepspeed_config_file: ../deepspeed_config_templates/zero_stage1_config.json | ||
# If using ZeRO-3 and wanting to load big models in, this should be set to `true` so | ||
# `transformers` uses the right `init` function | ||
zero3_init_flag: false # true | ||
|
||
# Finally we need to specify the number of GPUs to use | ||
num_processes: 2 | ||
# Optionally we can set the mixed precision now instead of in the deepspeed config file, | ||
# however this requires the `fp16` and `bf16` options to be set to `auto` in the deepspeed config file | ||
# mixed_precision: "bf16" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
# This config template simply setups up the TransformersEngine config (and a config for a single GPU), | ||
# this can interop with the other configs in this folder | ||
distributed_type: "NO" | ||
mixed_precision: "fp8" | ||
# Then we specify the fp8 configuration: | ||
fp8_config: | ||
backend: TE # Can be TE | MS-AMP | ||
# The following are TE specific arguments. | ||
# See https://docs.nvidia.com/deeplearning/transformer-engine/user-guide/api/common.html#common-api for more details | ||
amax_history_length: 1024 | ||
fp8_format: E4M3 | ||
interval: 1 | ||
margin: 0 | ||
override_linear_precision: false | ||
# Generally this should always be set to `false` to have the most realistic fp8 eval performance | ||
use_autocast_during_eval: false | ||
# If using MS-AMP, we ignore all of the prior and set a opt_level | ||
#opt_level: O1 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
# Since we are doing FSDP (even though it's multi-GPU), we need to specify the distributed type as FSDP | ||
distributed_type: FSDP | ||
# Can be one of "no", "fp16", or "bf16" (see `transformer_engine.yaml` for `fp8`, but it works for FSDP as well) | ||
mixed_precision: 'bf16' | ||
# Specify the number of GPUs to use | ||
num_processes: 2 | ||
# Then we can specify the FSDP config | ||
fsdp_config: | ||
fsdp_activation_checkpointing: false | ||
fsdp_auto_wrap_policy: TRANSFORMER_BASED_WRAP | ||
fsdp_backward_prefetch: BACKWARD_PRE | ||
fsdp_cpu_ram_efficient_loading: true | ||
fsdp_forward_prefetch: false | ||
fsdp_offload_params: false | ||
fsdp_sharding_strategy: FULL_SHARD | ||
fsdp_state_dict_type: SHARDED_STATE_DICT | ||
fsdp_sync_module_states: true | ||
fsdp_use_orig_params: true |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
# Specify distributed_type as `MULTI_GPU` for DDP | ||
distributed_type: "MULTI_GPU" | ||
# Can be one of "no", "fp16", or "bf16" (see `transformer_engine.yaml` for `fp8`) | ||
mixed_precision: "bf16" | ||
# Specify the number of GPUs to use | ||
num_processes: 2 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
# This config template is for a multi-node setup. This assumes DDP, but can be interop'd with the other configs in this folder | ||
# Generally it's recommended to look at the SLURM config template for a more robust multi-node setup | ||
distributed_type: MULTI_GPU | ||
# We need to specify the current machine's rank | ||
machine_rank: 0 | ||
# We then need to specify the IP address and port of the main process | ||
main_process_ip: '1234' | ||
main_process_port: 9999 | ||
# We need to specify the number of machines | ||
num_machines: 2 | ||
# We need to specify the *total* number of processes | ||
num_processes: 8 | ||
# And then we need to specify how rdvz comms will be handled | ||
rdzv_backend: static # or c10d | ||
# If the compute nodes are on the same network (cloud will more than likely be false) | ||
same_network: false |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
# Copyright 2024 The HuggingFace Team. All rights reserved. | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
|
||
""" | ||
A base script which outputs the accelerate config for the given environment | ||
""" | ||
from accelerate import Accelerator | ||
|
||
|
||
accelerator = Accelerator() | ||
|
||
accelerator.print(f"Accelerator state from the current environment:\n{accelerator.state}") | ||
if accelerator.fp8_recipe_handler is not None: | ||
accelerator.print(f"FP8 config:\n{accelerator.fp8_recipe_handler}") | ||
accelerator.end_training() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
# Since this is single GPU, we don't need distributed training | ||
distributed_type: "NO" | ||
# Can be one of "no", "fp16", or "bf16" (see `transformer_engine.yaml` for `fp8`) | ||
mixed_precision: "bf16" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters