2023-07-13 22:10:54 +08:00
|
|
|
|
|
2023-05-18 22:54:41 +08:00
|
|
|
|
import argparse
|
|
|
|
|
|
import os
|
2023-05-23 23:10:31 +08:00
|
|
|
|
from configs.model_config import *
|
2023-05-18 22:54:41 +08:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# Additional argparse types
|
|
|
|
|
|
def path(string):
|
|
|
|
|
|
if not string:
|
|
|
|
|
|
return ''
|
|
|
|
|
|
s = os.path.expanduser(string)
|
|
|
|
|
|
if not os.path.exists(s):
|
|
|
|
|
|
raise argparse.ArgumentTypeError(f'No such file or directory: "{string}"')
|
|
|
|
|
|
return s
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def file_path(string):
|
|
|
|
|
|
if not string:
|
|
|
|
|
|
return ''
|
|
|
|
|
|
s = os.path.expanduser(string)
|
|
|
|
|
|
if not os.path.isfile(s):
|
|
|
|
|
|
raise argparse.ArgumentTypeError(f'No such file: "{string}"')
|
|
|
|
|
|
return s
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def dir_path(string):
|
|
|
|
|
|
if not string:
|
|
|
|
|
|
return ''
|
|
|
|
|
|
s = os.path.expanduser(string)
|
|
|
|
|
|
if not os.path.isdir(s):
|
|
|
|
|
|
raise argparse.ArgumentTypeError(f'No such directory: "{string}"')
|
|
|
|
|
|
return s
|
|
|
|
|
|
|
|
|
|
|
|
|
2023-06-12 12:57:41 +08:00
|
|
|
|
parser = argparse.ArgumentParser(prog='langchain-ChatGLM',
|
2023-05-23 23:10:31 +08:00
|
|
|
|
description='About langchain-ChatGLM, local knowledge based ChatGLM with langchain | '
|
|
|
|
|
|
'基于本地知识库的 ChatGLM 问答')
|
|
|
|
|
|
|
2023-06-08 16:51:04 +08:00
|
|
|
|
parser.add_argument('--no-remote-model', action='store_true', help='remote in the model on '
|
|
|
|
|
|
'loader checkpoint, '
|
|
|
|
|
|
'if your load local '
|
|
|
|
|
|
'model to add the ` '
|
|
|
|
|
|
'--no-remote-model`')
|
|
|
|
|
|
parser.add_argument('--model-name', type=str, default=LLM_MODEL, help='Name of the model to load by default.')
|
2023-07-26 17:46:02 +08:00
|
|
|
|
parser.add_argument("--use-lora",type=bool,default=USE_LORA,help="use lora or not")
|
|
|
|
|
|
parser.add_argument('--lora', type=str, default=LORA_NAME,help='Name of the LoRA to apply to the model by default.')
|
2023-05-23 23:10:31 +08:00
|
|
|
|
parser.add_argument("--lora-dir", type=str, default=LORA_DIR, help="Path to directory with all the loras")
|
2023-07-26 17:46:02 +08:00
|
|
|
|
parser.add_argument('--use-ptuning-v2',action=USE_PTUNING_V2,help="whether use ptuning-v2 checkpoint")
|
2023-07-13 22:10:54 +08:00
|
|
|
|
parser.add_argument("--ptuning-dir",type=str,default=PTUNING_DIR,help="the dir of ptuning-v2 checkpoint")
|
2023-05-18 22:54:41 +08:00
|
|
|
|
# Accelerate/transformers
|
2023-05-23 23:10:31 +08:00
|
|
|
|
parser.add_argument('--load-in-8bit', action='store_true', default=LOAD_IN_8BIT,
|
|
|
|
|
|
help='Load the model with 8-bit precision.')
|
|
|
|
|
|
parser.add_argument('--bf16', action='store_true', default=BF16,
|
|
|
|
|
|
help='Load the model with bfloat16 precision. Requires NVIDIA Ampere GPU.')
|
2023-05-18 22:54:41 +08:00
|
|
|
|
|
|
|
|
|
|
args = parser.parse_args([])
|
|
|
|
|
|
# Generares dict with a default value for each argument
|
|
|
|
|
|
DEFAULT_ARGS = vars(args)
|