-
Notifications
You must be signed in to change notification settings - Fork 4.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #5922 from hpcaitech/kto
[Chat] Add KTO
- Loading branch information
Showing
49 changed files
with
1,549 additions
and
966 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,51 @@ | ||
#!/bin/bash | ||
set_n_least_used_CUDA_VISIBLE_DEVICES() { | ||
local n=${1:-"9999"} | ||
echo "GPU Memory Usage:" | ||
local FIRST_N_GPU_IDS=$(nvidia-smi --query-gpu=memory.used --format=csv | | ||
tail -n +2 | | ||
nl -v 0 | | ||
tee /dev/tty | | ||
sort -g -k 2 | | ||
awk '{print $1}' | | ||
head -n $n) | ||
export CUDA_VISIBLE_DEVICES=$(echo $FIRST_N_GPU_IDS | sed 's/ /,/g') | ||
echo "Now CUDA_VISIBLE_DEVICES is set to:" | ||
echo "CUDA_VISIBLE_DEVICES=$CUDA_VISIBLE_DEVICES" | ||
} | ||
set_n_least_used_CUDA_VISIBLE_DEVICES 4 | ||
|
||
PROJECT_NAME="kto" | ||
PARENT_CONFIG_FILE="./benchmark_config" # Path to a folder to save training config logs | ||
PRETRAINED_MODEL_PATH="" # huggingface or local model path | ||
PRETRAINED_TOKENIZER_PATH="" # huggingface or local tokenizer path | ||
BENCHMARK_DATA_DIR="./temp/kto" # Path to benchmark data | ||
DATASET_SIZE=80 | ||
|
||
TIMESTAMP=$(date +%Y-%m-%d-%H-%M-%S) | ||
FULL_PROJECT_NAME="${PROJECT_NAME}-${TIMESTAMP}" | ||
declare -a dataset=( | ||
$BENCHMARK_DATA_DIR/arrow/part-0 | ||
) | ||
|
||
# Generate dummy test data | ||
python prepare_dummy_test_dataset.py --data_dir $BENCHMARK_DATA_DIR --dataset_size $DATASET_SIZE --max_length 2048 --data_type kto | ||
|
||
|
||
colossalai run --nproc_per_node 2 --master_port 31313 ../examples/training_scripts/train_kto.py \ | ||
--pretrain $PRETRAINED_MODEL_PATH \ | ||
--tokenizer_dir $PRETRAINED_TOKENIZER_PATH \ | ||
--dataset ${dataset[@]} \ | ||
--plugin "zero2_cpu" \ | ||
--max_epochs 1 \ | ||
--accumulation_steps 1 \ | ||
--batch_size 2 \ | ||
--lr 1e-5 \ | ||
--beta 0.1 \ | ||
--mixed_precision "bf16" \ | ||
--grad_clip 1.0 \ | ||
--max_length 2048 \ | ||
--weight_decay 0.01 \ | ||
--warmup_steps 60 \ | ||
--grad_checkpoint \ | ||
--use_flash_attn |
Oops, something went wrong.