To finetune Llama-3.1 using SkyPilot with 8 H100 GPUs, you can adapt the provided 8B-lora.yaml configuration. This config is designed for multi-device finetuning of Llama3.1. Here's how to modify it and launch your finetuning job:
1. Adapt the Configuration File
Create a new YAML file, for example, llama3_1_8xh100.yaml, and copy the contents of the 8B-lora.yaml into it.
Modify Resources: Change the accelerators field to request 8 H100 GPUs. Also increase the number of nodes to distribute the finetuning process across multiple machines each with H100 GPUs if necessary for your setup:
[Redacted
resources:
accelerators: H100:8
num_nodes: 1 # or more, depending on your multi-node needs
Adjust Batch Size: If using multiple nodes, you may need to adjust the batch_size parameter. It currently is set to 2. This batch size is per-device so you'll need to change it to accommodate your needs. For instance, if you have 8 GPUs and want an effective batch size of 64, the batch size per GPU should be 8.
Gradient Accumulation: The config uses a gradient_accumulation_steps value of 32. If the batch size is changed, you may need to adjust this. The effective batch size is batch_size * gradient_accumulation_steps.
Model Checkpoint: Ensure the checkpointer section points to the correct path where the Llama-3.1 model is located. The example yaml assumes that you have downloaded the model to /tmp/Meta-Llama-3.1-8B-Instruct/.
Other Parameters: Adjust other parameters in the model, optimizer, lr_scheduler, and training sections as necessary for your finetuning task.
Here is an example of the modified yaml:
[Redacted
# Config for multi-device LoRA finetuning in lora_finetune_distributed.py
# using a Llama3.1 8B Instruct model
#
# This config assumes that you've run the following command before launching
# this run:
# tune download meta-llama/Meta-Llama-3.1-8B-Instruct --output-dir /tmp/Meta-Llama-3.1-8B-Instruct --ignore-patterns "original/consolidated.00.pth"
#
# To launch on 2 devices, run the following command from root:
# tune run --nproc_per_node 2 lora_finetune_distributed --config llama3_1/8B_lora
#
# You can add specific overrides through the command line. For example
# to override the checkpointer directory while launching training
# you can run:
# tune run --nproc_per_node 2 lora_finetune_distributed --config llama3_1/8B_lora checkpointer.checkpoint_dir=<YOUR_CHECKPOINT_DIR>
#
# This config works best when the model is being fine-tuned on 2+ GPUs.
# For single device LoRA finetuning please use 8B_lora_single_device.yaml
# or 8B_qlora_single_device.yaml
# Tokenizer
tokenizer:
_component_: torchtune.models.llama3.llama3_tokenizer
path: /tmp/Meta-Llama-3.1-8B-Instruct/original/tokenizer.model
# Model Arguments
model:
_component_: torchtune.models.llama3_1.lora_llama3_1_8b
lora_attn_modules: ['q_proj', 'v_proj']
apply_lora_to_mlp: False
apply_lora_to_output: False
[Redacted Person]_rank: 8
lora_alpha: 16
[Redacted Person]:
_component_: torchtune.utils.FullModelHFCheckpointer
checkpoint_dir: /tmp/Meta-Llama-3.1-8B-Instruct/
checkpoint_files: [
model-00001-of-00004.safetensors,
model-00002-of-00004.safetensors,
model-00003-of-00004.safetensors,
model-00004-of-00004.safetensors
]
recipe_checkpoint: null
output_dir: /tmp/Meta-Llama-3.1-8B-Instruct/
model_type: LLAMA3
resume_from_checkpoint: False
# Dataset and Sampler
dataset:
_component_: torchtune.datasets.alpaca_cleaned_dataset
seed: null
shuffle: True
batch_size: 8 # adjusted batch size
# Optimizer and Scheduler
optimizer:
_component_: torch.optim.[Redacted Person]
weight_decay: 0.01
lr: 3e-4
[Redacted Person]_[Redacted Person]:
_component_: torchtune.modules.get_cosine_schedule_with_warmup
num_warmup_steps: 100
loss:
_component_: torch.nn.CrossEntropyLoss
# Training
epochs: 1
max_steps_per_epoch: null
gradient_accumulation_steps: 8 # adjusted gradient accumulation
# Logging
output_dir: /tmp/lora_finetune_output
metric_logger:
_component_: torchtune.utils.metric_logging.DiskLogger
log_dir: ${output_dir}
log_every_n_steps: 1
log_peak_memory_stats: False
# Environment
device: cuda
dtype: bf16
enable_activation_checkpointing: False
2. Launch the Job
Use the sky launch command to start your finetuning job, specifying your modified YAML file:
bash
sky launch llama3_1_8xh100.yaml
If you need to override any parameters (e.g., checkpoint directory, dataset, output directory), use the command line overrides as mentioned in the comments of the yaml file, for example:
bash
code
tune run --nproc_per_node 8 lora_finetune_distributed --config llama3_1_8xh100 checkpointer.checkpoint_dir=<YOUR_CHECKPOINT_DIR>
code
```
Note that you must use `tune run` if the config uses `torchtune`, like `8B-lora.yaml`. Also, you should set the `--nproc_per_node` option as the number of GPUs requested in the `accelerators` section. If multi-node is used, the total number of processes is `num_nodes * nproc_per_node`.
Explanation
resources.accelerators: H100:8: This specifies that you want to use 8 H100 GPUs for your task.
num_nodes: 1: This sets the number of machines to 1, with all 8 GPUs on the same machine. Change it to a number > 1 if your cluster supports it and you want to distribute the training across multiple nodes.
The rest of the configuration is adapted from the provided example, specifying the model, training parameters, and the dataset. The torchtune library is used for model loading, training and checkpointing.
Important Notes:
Ensure you have the Llama-3.1 model weights downloaded and correctly specified in the config file.
Make sure your cloud provider supports H100 instances. SkyPilot will attempt to find the most cost-effective way to fulfill your resource request.
The lora_finetune_distributed.py script is designed to handle multi-GPU finetuning.
Depending on the size of your dataset and the max_steps_per_epoch paramater, the finetuning process might take a considerable amount of time.
SkyPilot will handle provisioning the resources, setting up the environment, and running your finetuning task, including syncing your code and data to the cloud instance.
By adapting this configuration and using sky launch, you can efficiently finetune Llama-3.1 with 8 H100 GPUs on any cloud supported by SkyPilot.