forked from eosphoros-ai/DB-GPT-Hub
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add API interfaces for train, predict and evaluate
- Loading branch information
Showing
9 changed files
with
205 additions
and
23 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
""" | ||
dbgpt_hub.eval | ||
============== | ||
""" | ||
|
||
from .evaluation_api import start_evaluate | ||
|
||
__all__ = ["start_evaluate"] |
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,32 @@ | ||
from typing import Optional, Dict, Any | ||
|
||
from dbgpt_hub.eval import evaluation | ||
|
||
|
||
def start_evaluate( | ||
args: Optional[Dict[str, Any]] = None, | ||
): | ||
# Arguments for evaluation | ||
if args is None: | ||
args = { | ||
"input": "./dbgpt_hub/output/pred/pred_sql_dev_skeleton.sql", | ||
"gold": "./dbgpt_hub/data/eval_data/gold.txt", | ||
"gold_natsql": "./dbgpt_hub/data/eval_data/gold_natsql2sql.txt", | ||
"db": "./dbgpt_hub/data/spider/database", | ||
"table": "./dbgpt_hub/data/eval_data/tables.json", | ||
"table_natsql": "./dbgpt_hub/data/eval_data/tables_for_natsql2sql.json", | ||
"etype": "exec", | ||
"plug_value": True, | ||
"keep_distict": False, | ||
"progress_bar_for_each_datapoint": False, | ||
"natsql": False, | ||
} | ||
else: | ||
args = args | ||
|
||
# Execute evaluation | ||
evaluation.evaluate_api(args) | ||
|
||
|
||
if __name__ == "__main__": | ||
start_evaluate() |
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,8 @@ | ||
""" | ||
dbgpt_hub.predict | ||
============== | ||
""" | ||
|
||
from .predict_api import start_predict | ||
|
||
__all__ = ["start_predict"] |
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,31 @@ | ||
import os | ||
from dbgpt_hub.predict import predict | ||
from typing import Optional, Dict, Any | ||
|
||
|
||
def start_predict( | ||
args: Optional[Dict[str, Any]] = None, cuda_visible_devices: Optional[str] = "0" | ||
): | ||
# Setting CUDA Device | ||
os.environ["CUDA_VISIBLE_DEVICES"] = cuda_visible_devices | ||
|
||
# Default Arguments | ||
if args is None: | ||
args = { | ||
"model_name_or_path": "codellama/CodeLlama-13b-Instruct-hf", | ||
"template": "llama2", | ||
"finetuning_type": "lora", | ||
"checkpoint_dir": "dbgpt_hub/output/adapter/CodeLlama-13b-sql-lora", | ||
"predict_file_path": "dbgpt_hub/data/eval_data/dev_sql.json", | ||
"predict_out_dir": "dbgpt_hub/output/", | ||
"predicted_out_filename": "pred_sql.sql", | ||
} | ||
else: | ||
args = args | ||
|
||
# Execute prediction | ||
predict.predict(args) | ||
|
||
|
||
if __name__ == "__main__": | ||
start_predict() |
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,8 @@ | ||
""" | ||
dbgpt_hub.train | ||
============== | ||
""" | ||
|
||
from .sft_train_api import start_sft | ||
|
||
__all__ = ["start_sft"] |
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,47 @@ | ||
import os | ||
|
||
from typing import Optional, Dict, Any | ||
from dbgpt_hub.train import sft_train | ||
|
||
|
||
def start_sft( | ||
args: Optional[Dict[str, Any]] = None, cuda_visible_devices: Optional[str] = "0" | ||
): | ||
# Setting CUDA Device | ||
os.environ["CUDA_VISIBLE_DEVICES"] = cuda_visible_devices | ||
|
||
# Default Arguments | ||
if args is None: | ||
args = { | ||
"model_name_or_path": "codellama/CodeLlama-13b-Instruct-hf", | ||
"do_train": True, | ||
"dataset": "example_text2sql_train", | ||
"max_source_length": 2048, | ||
"max_target_length": 512, | ||
"finetuning_type": "lora", | ||
"lora_target": "q_proj,v_proj", | ||
"template": "llama2", | ||
"lora_rank": 64, | ||
"lora_alpha": 32, | ||
"output_dir": "dbgpt_hub/output/adapter/CodeLlama-13b-sql-lora", | ||
"overwrite_cache": True, | ||
"overwrite_output_dir": True, | ||
"per_device_train_batch_size": 1, | ||
"gradient_accumulation_steps": 16, | ||
"lr_scheduler_type": "cosine_with_restarts", | ||
"logging_steps": 50, | ||
"save_steps": 2000, | ||
"learning_rate": 2e-4, | ||
"num_train_epochs": 8, | ||
"plot_loss": True, | ||
"bf16": True, | ||
} | ||
else: | ||
args = args | ||
|
||
# Run SFT | ||
sft_train.train(args) | ||
|
||
|
||
if __name__ == "__main__": | ||
start_sft() |