-
Notifications
You must be signed in to change notification settings - Fork 833
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
35347d4
commit 1715212
Showing
8 changed files
with
204 additions
and
54 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
compute_environment: LOCAL_MACHINE | ||
debug: false | ||
deepspeed_config: | ||
deepspeed_multinode_launcher: standard | ||
offload_optimizer_device: none | ||
offload_param_device: none | ||
zero3_init_flag: true | ||
zero3_save_16bit_model: true | ||
zero_stage: 3 | ||
distributed_type: DEEPSPEED | ||
downcast_bf16: 'no' | ||
machine_rank: 0 | ||
main_training_function: main | ||
mixed_precision: bf16 | ||
num_machines: 1 | ||
num_processes: 4 | ||
gpu_ids: 4,5,6,7 | ||
rdzv_backend: static | ||
same_network: true | ||
tpu_env: [] | ||
tpu_use_cluster: false | ||
tpu_use_sudo: false | ||
use_cpu: 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,78 @@ | ||
#!/usr/bin/env python | ||
# coding=utf-8 | ||
# Copyright 2024 Statistics and Machine Learning Research Group. All rights reserved. | ||
import logging | ||
import os | ||
import sys | ||
import copy | ||
|
||
from transformers import ( | ||
HfArgumentParser | ||
) | ||
|
||
from lmflow.datasets import Dataset | ||
from lmflow.models.auto_model import AutoModel | ||
from lmflow.pipeline.auto_pipeline import AutoPipeline | ||
from lmflow.args import ( | ||
ModelArguments, | ||
DatasetArguments, | ||
AutoArguments, | ||
) | ||
from lmflow.utils.common import remove_dataclass_attr_prefix, create_copied_dataclass | ||
|
||
|
||
logger = logging.getLogger(__name__) | ||
|
||
|
||
ReferenceModelArguments = create_copied_dataclass( | ||
original_dataclass=ModelArguments, | ||
field_prefix="reference_", | ||
class_prefix="Reference" | ||
) | ||
|
||
|
||
def main(): | ||
# Parses arguments | ||
pipeline_name = "dpov2_aligner" | ||
PipelineArguments = AutoArguments.get_pipeline_args_class(pipeline_name) | ||
|
||
parser = HfArgumentParser(( | ||
ModelArguments, | ||
ReferenceModelArguments, | ||
DatasetArguments, | ||
PipelineArguments | ||
)) | ||
if len(sys.argv) == 2 and sys.argv[1].endswith(".json"): | ||
# If we pass only one argument to the script and it's the path to a json file, | ||
# let's parse it to get our arguments. | ||
model_args, ref_model_args, data_args, pipeline_args = parser.parse_json_file(json_file=os.path.abspath(sys.argv[1])) | ||
else: | ||
model_args, ref_model_args, data_args, pipeline_args = parser.parse_args_into_dataclasses() | ||
|
||
ref_model_args_dict = remove_dataclass_attr_prefix(ref_model_args, "reference_") | ||
ref_model_args = ModelArguments(**ref_model_args_dict) | ||
|
||
train_dataset = Dataset(data_args) | ||
eval_data_args = copy.deepcopy(data_args) | ||
eval_data_args.dataset_path = pipeline_args.eval_dataset_path | ||
eval_dataset = Dataset(eval_data_args) | ||
model = AutoModel.get_model(model_args) | ||
ref_model = AutoModel.get_model(ref_model_args) | ||
aligner = AutoPipeline.get_pipeline( | ||
pipeline_name=pipeline_name, | ||
model_args=model_args, | ||
data_args=data_args, | ||
pipeline_args=pipeline_args, | ||
ref_model_args=ref_model_args, | ||
) | ||
|
||
res = aligner.align( | ||
model=model, | ||
ref_model=ref_model, | ||
train_dataset=train_dataset, | ||
eval_dataset=eval_dataset, | ||
) | ||
|
||
|
||
if __name__ == "__main__": | ||
main() |
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,86 @@ | ||
#!/bin/bash | ||
|
||
# Parses arguments | ||
run_name=dpov2_align | ||
model_name_or_path=meta-llama/Meta-Llama-3-8B-Instruct | ||
reference_model_name_or_path=meta-llama/Meta-Llama-3-8B-Instruct | ||
dataset_path=data/iterative-prompt/train | ||
eval_dataset_path=data/iterative-prompt/eval | ||
output_dir=output_models/${run_name} | ||
deepspeed_args="--master_port=11000 --include localhost:4,5,6,7" | ||
|
||
while [[ $# -ge 1 ]]; do | ||
key="$1" | ||
case ${key} in | ||
-r|--run_name) | ||
run_name="$2" | ||
shift | ||
;; | ||
--model_name_or_path) | ||
model_name_or_path="$2" | ||
shift | ||
;; | ||
--reference_model_name_or_path) | ||
reference_model_name_or_path="$2" | ||
shift | ||
;; | ||
--dataset_path) | ||
dataset_path="$2" | ||
shift | ||
;; | ||
--eval_dataset_path) | ||
eval_dataset_path="$2" | ||
shift | ||
;; | ||
-o|--output_dir) | ||
output_dir="$2" | ||
shift | ||
;; | ||
--deepspeed_args) | ||
deepspeed_args="$2" | ||
shift | ||
;; | ||
*) | ||
echo "error: unknown option \"${key}\"" 1>&2 | ||
exit 1 | ||
esac | ||
shift | ||
done | ||
|
||
project_dir=$(cd "$(dirname $0)"/..; pwd) | ||
log_dir=${project_dir}/log/${run_name} | ||
mkdir -p ${output_dir} ${log_dir} | ||
|
||
accelerate launch --config_file configs/accelerate_dsz3_config.yaml \ | ||
examples/dpov2_train.py \ | ||
--model_name_or_path ${model_name_or_path} \ | ||
--reference_model_name_or_path ${reference_model_name_or_path} \ | ||
--do_train True \ | ||
--dataset_path ${dataset_path} \ | ||
--eval_dataset_path ${eval_dataset_path} \ | ||
--bf16 True \ | ||
--learning_rate 5e-7 \ | ||
--lr_scheduler_type cosine \ | ||
--warmup_steps 100 \ | ||
--optim paged_adamw_32bit \ | ||
--per_device_train_batch_size 1 \ | ||
--per_device_eval_batch_size 1 \ | ||
--gradient_accumulation_steps 16 \ | ||
--gradient_checkpointing True \ | ||
--margin_scale 1.0 \ | ||
--max_prompt_length 1000 \ | ||
--num_train_epochs 2 \ | ||
--logging_steps 2 \ | ||
--save_strategy epoch \ | ||
--save_steps 5000 \ | ||
--evaluation_strategy steps \ | ||
--eval_steps 100 \ | ||
--loss_type sigmoid \ | ||
--output_dir ${output_dir} \ | ||
--run_name ${run_name} \ | ||
--sampling_paired_method max_min \ | ||
--report_to wandb \ | ||
--mask_prompt True \ | ||
--length_penalty 0 \ | ||
| tee ${log_dir}/train.log \ | ||
2> ${log_dir}/train.err |
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