modify style

Former-commit-id: 54b713d0c4ffdfc6a7faeb14471b58bb1cd8acf5
This commit is contained in:
BUAADreamer
2024-04-25 21:15:16 +08:00
parent 266fe908e3
commit c425436676
16 changed files with 374 additions and 502 deletions

View File

@@ -15,33 +15,23 @@ class ModelArguments:
)
adapter_name_or_path: Optional[str] = field(
default=None,
metadata={
"help": "Path to the adapter weight or identifier from huggingface.co/models."
},
metadata={"help": "Path to the adapter weight or identifier from huggingface.co/models."},
)
cache_dir: Optional[str] = field(
default=None,
metadata={
"help": "Where to store the pre-trained models downloaded from huggingface.co or modelscope.cn."
},
metadata={"help": "Where to store the pre-trained models downloaded from huggingface.co or modelscope.cn."},
)
use_fast_tokenizer: bool = field(
default=True,
metadata={
"help": "Whether or not to use one of the fast tokenizer (backed by the tokenizers library)."
},
metadata={"help": "Whether or not to use one of the fast tokenizer (backed by the tokenizers library)."},
)
resize_vocab: bool = field(
default=False,
metadata={
"help": "Whether or not to resize the tokenizer vocab and the embedding layers."
},
metadata={"help": "Whether or not to resize the tokenizer vocab and the embedding layers."},
)
split_special_tokens: bool = field(
default=False,
metadata={
"help": "Whether or not the special tokens should be split during the tokenization process."
},
metadata={"help": "Whether or not the special tokens should be split during the tokenization process."},
)
new_special_tokens: Optional[str] = field(
default=None,
@@ -49,9 +39,7 @@ class ModelArguments:
)
model_revision: str = field(
default="main",
metadata={
"help": "The specific model version to use (can be a branch name, tag name or commit id)."
},
metadata={"help": "The specific model version to use (can be a branch name, tag name or commit id)."},
)
low_cpu_mem_usage: bool = field(
default=True,
@@ -59,9 +47,7 @@ class ModelArguments:
)
quantization_bit: Optional[int] = field(
default=None,
metadata={
"help": "The number of bits to quantize the model using bitsandbytes."
},
metadata={"help": "The number of bits to quantize the model using bitsandbytes."},
)
quantization_type: Literal["fp4", "nf4"] = field(
default="nf4",
@@ -69,21 +55,15 @@ class ModelArguments:
)
double_quantization: bool = field(
default=True,
metadata={
"help": "Whether or not to use double quantization in int4 training."
},
metadata={"help": "Whether or not to use double quantization in int4 training."},
)
quantization_device_map: Optional[Literal["auto"]] = field(
default=None,
metadata={
"help": "Device map used to infer the 4-bit quantized model, needs bitsandbytes>=0.43.0."
},
metadata={"help": "Device map used to infer the 4-bit quantized model, needs bitsandbytes>=0.43.0."},
)
rope_scaling: Optional[Literal["linear", "dynamic"]] = field(
default=None,
metadata={
"help": "Which scaling strategy should be adopted for the RoPE embeddings."
},
metadata={"help": "Which scaling strategy should be adopted for the RoPE embeddings."},
)
flash_attn: Literal["off", "sdpa", "fa2", "auto"] = field(
default="auto",
@@ -91,27 +71,19 @@ class ModelArguments:
)
shift_attn: bool = field(
default=False,
metadata={
"help": "Enable shift short attention (S^2-Attn) proposed by LongLoRA."
},
metadata={"help": "Enable shift short attention (S^2-Attn) proposed by LongLoRA."},
)
mixture_of_depths: Optional[Literal["convert", "load"]] = field(
default=None,
metadata={
"help": "Convert the model to mixture-of-depths (MoD) or load the MoD model."
},
metadata={"help": "Convert the model to mixture-of-depths (MoD) or load the MoD model."},
)
use_unsloth: bool = field(
default=False,
metadata={
"help": "Whether or not to use unsloth's optimization for the LoRA training."
},
metadata={"help": "Whether or not to use unsloth's optimization for the LoRA training."},
)
moe_aux_loss_coef: Optional[float] = field(
default=None,
metadata={
"help": "Coefficient of the auxiliary router loss in mixture-of-experts model."
},
metadata={"help": "Coefficient of the auxiliary router loss in mixture-of-experts model."},
)
disable_gradient_checkpointing: bool = field(
default=False,
@@ -135,9 +107,7 @@ class ModelArguments:
)
vllm_gpu_util: float = field(
default=0.9,
metadata={
"help": "The fraction of GPU memory in (0,1) to be used for the vLLM engine."
},
metadata={"help": "The fraction of GPU memory in (0,1) to be used for the vLLM engine."},
)
vllm_enforce_eager: bool = field(
default=False,
@@ -177,9 +147,7 @@ class ModelArguments:
)
export_quantization_dataset: Optional[str] = field(
default=None,
metadata={
"help": "Path to the dataset or dataset name to use in quantizing the exported model."
},
metadata={"help": "Path to the dataset or dataset name to use in quantizing the exported model."},
)
export_quantization_nsamples: int = field(
default=128,
@@ -187,27 +155,19 @@ class ModelArguments:
)
export_quantization_maxlen: int = field(
default=1024,
metadata={
"help": "The maximum length of the model inputs used for quantization."
},
metadata={"help": "The maximum length of the model inputs used for quantization."},
)
export_legacy_format: bool = field(
default=False,
metadata={
"help": "Whether or not to save the `.bin` files instead of `.safetensors`."
},
metadata={"help": "Whether or not to save the `.bin` files instead of `.safetensors`."},
)
export_hub_model_id: Optional[str] = field(
default=None,
metadata={
"help": "The name of the repository if push the model to the Hugging Face hub."
},
metadata={"help": "The name of the repository if push the model to the Hugging Face hub."},
)
print_param_status: bool = field(
default=False,
metadata={
"help": "For debugging purposes, print the status of the parameters in the model."
},
metadata={"help": "For debugging purposes, print the status of the parameters in the model."},
)
use_mllm: bool = field(
default=False,
@@ -220,21 +180,13 @@ class ModelArguments:
self.model_max_length = None
if self.split_special_tokens and self.use_fast_tokenizer:
raise ValueError(
"`split_special_tokens` is only supported for slow tokenizers."
)
raise ValueError("`split_special_tokens` is only supported for slow tokenizers.")
if (
self.adapter_name_or_path is not None
): # support merging multiple lora weights
self.adapter_name_or_path = [
path.strip() for path in self.adapter_name_or_path.split(",")
]
if self.adapter_name_or_path is not None: # support merging multiple lora weights
self.adapter_name_or_path = [path.strip() for path in self.adapter_name_or_path.split(",")]
if self.new_special_tokens is not None: # support multiple special tokens
self.new_special_tokens = [
token.strip() for token in self.new_special_tokens.split(",")
]
self.new_special_tokens = [token.strip() for token in self.new_special_tokens.split(",")]
assert self.quantization_bit in [
None,
@@ -249,10 +201,7 @@ class ModelArguments:
2,
], "We only accept 2/3/4/8-bit quantization."
if (
self.export_quantization_bit is not None
and self.export_quantization_dataset is None
):
if self.export_quantization_bit is not None and self.export_quantization_dataset is None:
raise ValueError("Quantization dataset is necessary for exporting.")
def to_dict(self) -> Dict[str, Any]: