Views
No views yet
[!IMPORTANT] Theflameproject has been migrated to a new project built on torchtitan.
Please visit the new repository for details and updates.The code here is now archived as legacy, and no future updates will be synchronized here.
flame enables you to train large language models with just a few lines of code:
we use datasets for data processing, transformers for model definitions, and accelerate1 for seamless distributed training.flame to train GLA models.fla and flame have minimal dependencies.
Clone the fla repository and install the necessary packages as follows:1git clone https://github.com/sustcsonglin/flash-linear-attention.git
2pip install .
3pip install accelerate[!CAUTION] The 🤗tokenizershave some memory leak issues when processing very long documents. To address this, please ensure you installtokenizers>=0.20.4.
fineweb-edu dataset, run:1python preprocess.py \
2 --dataset HuggingFaceFW/fineweb-edu \
3 --name sample-10BT \
4 --split train \
5 --context_length 2048python preprocess.py \
--dataset /mnt/jfzn/msj/fineweb100B_hf/datasets--HuggingFaceFW--fineweb-edu/sample/100BT \
--name sample-100BT \
--split train \
--context_length 2048data/HuggingFaceFW/fineweb-edu/sample-10BT/train.git lfs (refer to this issue).1git lfs install
2git clone https://huggingface.co/datasets/cerebras/SlimPajama-627B --depth 1
3python preprocess.py \
4 --dataset SlimPajama-627B \
5 --split train \
6 --context_length 20481bash train.sh \
2 type=gla \
3 lr=3e-4 \
4 scheduler=cosine_with_min_lr \
5 batch=32 \
6 update=1 \
7 warmup=1024 \
8 steps=20480 \
9 context=2048 \
10 gpus=8 \
11 nodes=1 \
12 path=exp/gla-340M-10B \
13 project=fla \
14 model=configs/gla_340M.json \
15 data=HuggingFaceFW/fineweb-edu \
16 name=sample-10BT \
17 cache=data/HuggingFaceFW/fineweb-edu/sample-10BT/train| Description | Default | |
|---|---|---|
| lr | learning_rate | 3e-4 |
| scheduler | lr_scheduler_type | cosine_with_min_lr |
| batch | batch_size | 32 |
| update | gradient_accumulation_steps | 1 |
| context | context_length | 2048 |
| gpus | num_gpus_per_node | 8 |
| nodes | num_nodes | 1 |
| warmup | warmup_steps | 1024 |
| steps | max_steps | 20480 |
3e-4 by default, equipped with a cosine scheduler.
Other scheduler types like WSD (warmup_stable_decay)2 are also supported.global_batch_size, is calculated as
batch_size × gradient_accumulation_steps × context_length × num_gpus_per_node × num_nodes.
For instance, in the 340M model example, the global_batch_size calculates to $32 \times 1 \times 2048 \times 8 \times 1 = 524,288$ (0.5M tokens).warmup_steps parameter indicates the number of steps for the learning rate warmup phase, while max_steps represents the maximum number of training steps.
Each step processes global_batch_size tokens.
Consequently, 512 and 20480 correspond to processing 0.5B and 10B tokens, respectively.global_batch_size, warmup_steps, and max_steps carefully when modifying any of the hyperparameters!!flame also supports resuming interrupted training by specifying the checkpoint path.
Simply use the following command:1bash train.sh \
2 type=gla \
3 lr=3e-4 \
4 steps=20480 \
5 batch=32 \
6 update=1 \
7 warmup=1024 \
8 context=2048 \
9 gpus=8 \
10 nodes=1 \
11 path=exp/gla-340M-10B \
12 project=fla \
13 model=configs/gla_340M.json \
14 data=HuggingFaceFW/fineweb-edu \
15 name=sample-10BT \
16 cache=data/HuggingFaceFW/fineweb-edu/sample-10BT/train \
17 checkpoint=exp/gla-340M-10B/checkpoint-8192wandb to monitor your training process effectively.flame supports continual training from a pretrained checkpoint.
Below, we provide an example of how to finetune Mistral-7B to GLA.
You can follow similar steps to reproduce the results in the GSA paper:1cd ../utils
2python convert_from_llama.py \
3 --model mistralai/Mistral-7B-v0.1 \
4 --config ../training/configs/gla_7B.json \
5 --output ../training/converted/gla-7B
6cd -1bash train.sh \
2 type=gla \
3 lr=3e-5 \
4 steps=10240 \
5 batch=4 \
6 update=8 \
7 warmup=512 \
8 context=2048 \
9 path=exp/gla-7B-20B \
10 project=fla \
11 model=converted/gla-7B \
12 data=SlimPajama-627B \
13 cache=data/SlimPajama-627B/trainaccelerate library supports various distributed frameworks, like deepspeed and megatron for large-scale training. We use deepspeed in our case. ↩