Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion docs/source_en/Instruction/Supported-models-datasets.md
Original file line number Diff line number Diff line change
Expand Up @@ -579,7 +579,7 @@ The table below provides relevant information about the datasets accessed throug
- Tags: Tags of the dataset.


| Dataset ID | Subset name | Dataset Size | Statistic (token) | Tags | HF Dataset ID |
| Dataset ID | Subset Name | Dataset Size | Statistic (token) | Tags | HF Dataset ID |
| ---------- | ----------- | -------------| ------------------| ---- | ------------- |
|[AI-ModelScope/COIG-CQIA](https://modelscope.cn/datasets/AI-ModelScope/COIG-CQIA)|chinese_traditional<br>coig_pc<br>exam<br>finance<br>douban<br>human_value<br>logi_qa<br>ruozhiba<br>segmentfault<br>wiki<br>wikihow<br>xhs<br>zhihu|44694|331.2±693.8, min=34, max=19288|general, 🔥|-|
|[AI-ModelScope/CodeAlpaca-20k](https://modelscope.cn/datasets/AI-ModelScope/CodeAlpaca-20k)|default|20022|99.3±57.6, min=30, max=857|code, en|[HuggingFaceH4/CodeAlpaca_20K](https://huggingface.co/datasets/HuggingFaceH4/CodeAlpaca_20K)|
Expand Down
4 changes: 2 additions & 2 deletions scripts/utils/run_dataset_info.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ def get_cache_mapping(fpath):
continue
items = text.split('|')
key = items[1] if items[1] != '-' else items[6]
key = re.search(r'\[(.+)\]', key).group(1)
key = re.search(r'\[(.+?)\]', key).group(1)
stat = items[3:5]
if stat[0] == '-':
stat = ('huge dataset', '-')
Expand Down Expand Up @@ -78,7 +78,7 @@ def write_dataset_info() -> None:
fpaths = ['docs/source/Instruction/支持的模型和数据集.md', 'docs/source_en/Instruction/Supported-models-datasets.md']
cache_mapping = get_cache_mapping(fpaths[0])
res_text_list = []
res_text_list.append('| Dataset ID | Subset name | Dataset Size | Statistic (token) | Tags | HF Dataset ID |')
res_text_list.append('| Dataset ID | Subset Name | Dataset Size | Statistic (token) | Tags | HF Dataset ID |')
res_text_list.append('| ---------- | ----------- | -------------| ------------------| ---- | ------------- |')

all_keys = list(DATASET_MAPPING.keys())
Expand Down
2 changes: 1 addition & 1 deletion swift/cli/web_ui.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# Copyright (c) Alibaba, Inc. and its affiliates.
from swift.ui.app import webui_main
from swift.ui import webui_main

if __name__ == '__main__':
webui_main()
2 changes: 1 addition & 1 deletion swift/hub/hub.py
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,6 @@ def upload_folder(
token: Union[str, bool, None] = None,
revision: Optional[str] = 'master',
ignore_patterns: Optional[Union[List[str], str]] = None,
run_as_future: bool = False,
**kwargs,
):
cls.push_to_hub(repo_id, folder_path, path_in_repo, commit_message, commit_description, token, True, revision,
Expand Down Expand Up @@ -271,6 +270,7 @@ def push_to_hub(cls,
repo_id,
folder_path,
token or cls.ms_token,
private,
commit_message=commit_message,
ignore_file_pattern=ignore_patterns,
revision=revision,
Expand Down
8 changes: 3 additions & 5 deletions swift/llm/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,11 @@
deploy_main,
LoRARequest,
InferClient,
SwiftInfer,
SwiftDeploy,
run_deploy,
prepare_pt_engine_template,
)
from .export import (export_main, merge_lora, quantize_model, export_to_ollama)
from .eval import eval_main, SwiftEval
from .eval import eval_main
from .train import sft_main, pt_main, rlhf_main
from .argument import (EvalArguments, InferArguments, TrainArguments, ExportArguments, DeployArguments,
RLHFArguments, WebUIArguments, BaseArguments)
Expand All @@ -43,10 +41,10 @@
'rlhf': ['rlhf_main'],
'infer': [
'deploy_main', 'VllmEngine', 'RequestConfig', 'LmdeployEngine', 'PtEngine', 'infer_main', 'LoRARequest',
'InferClient', 'SwiftInfer', 'SwiftDeploy', 'run_deploy', 'prepare_pt_engine_template', 'InferEngine'
'InferClient', 'run_deploy', 'prepare_pt_engine_template', 'InferEngine'
],
'export': ['export_main', 'merge_lora', 'quantize_model', 'export_to_ollama'],
'eval': ['eval_main', 'SwiftEval'],
'eval': ['eval_main'],
'train': ['sft_main', 'pt_main', 'rlhf_main'],
'argument': [
'EvalArguments', 'InferArguments', 'TrainArguments', 'ExportArguments', 'WebUIArguments', 'DeployArguments',
Expand Down
5 changes: 2 additions & 3 deletions swift/llm/argument/base_args/base_args.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,15 +28,15 @@ def get_supported_tuners():
class BaseArguments(GenerationArguments, QuantizeArguments, DataArguments, TemplateArguments, ModelArguments):
"""
BaseArguments class is a dataclass that inherits from multiple argument classes:
ModelArguments, TemplateArguments, and DataArguments.
GenerationArguments, QuantizeArguments, DataArguments, TemplateArguments, ModelArguments.

Args:
tuner_backend(str): Support peft or unsloth.
train_type(str): The training type, support all supported tuners and `full`.
seed (int): Random seed for reproducibility. Default is 42.
model_kwargs (Optional[str]): Additional keyword arguments for the model. Default is None.
use_hf (bool): Flag to determine if Hugging Face should be used. Default is False.
load_dataset_config (bool): Flag to determine if dataset configuration should be loaded. Default is False.
use_hf (bool): Flag to determine if Hugging Face should be used. Default is False.
hub_token (Optional[str]): SDK token for authentication. Default is None.
ignore_args_error (bool): Flag to ignore argument errors for notebook compatibility. Default is False.
use_swift_lora (bool): Use swift lora, a compatible argument
Expand Down Expand Up @@ -143,7 +143,6 @@ def _init_weight_type(self, ckpt_dir):
self.model = ckpt_dir or self.model

def _init_device(self):
"""Prepare ddp of course"""
if is_dist():
if is_torch_npu_available():
torch.npu.set_device(self.local_rank)
Expand Down
6 changes: 3 additions & 3 deletions swift/llm/argument/base_args/data_args.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,17 +17,17 @@ class DataArguments:
DataArguments class is a dataclass that holds various arguments related to dataset handling and processing.

Args:
dataset (List[str]): List of dataset identifiers or paths.
val_dataset (List[str]): List of validation dataset identifiers or paths.
dataset (List[str]): List of dataset_id, dataset_path or dataset_dir
val_dataset (List[str]): List of validation dataset_id, dataset_path or dataset_dir
split_dataset_ratio (float): Ratio to split the dataset for validation if val_dataset is empty. Default is 0.01.
data_seed (Optional[int]): Seed for dataset shuffling. Default is None.
dataset_num_proc (int): Number of processes to use for data loading and preprocessing. Default is 1.
streaming (bool): Flag to enable streaming of datasets. Default is False.
load_from_cache_file (bool): Flag to load dataset from cache file. Default is False.
download_mode (Literal): Mode for downloading datasets. Default is 'reuse_dataset_if_exists'.
model_name (List[str]): List containing Chinese and English names of the model. Default is [None, None].
model_author (List[str]): List containing Chinese and English names of the model author.
Default is [None, None].
streaming (bool): Flag to enable streaming of datasets. Default is False.
custom_register_path (Optional[str]): Path to custom .py file for dataset registration. Default is None.
custom_dataset_info (Optional[str]): Path to custom dataset_info.json file. Default is None.
"""
Expand Down
1 change: 1 addition & 0 deletions swift/llm/argument/base_args/generation_args.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ class GenerationArguments:
top_p (Optional[float]): Top-p (nucleus) sampling parameter. Default is None.
repetition_penalty (Optional[float]): Penalty for repeated tokens. Default is None.
num_beams (int): Number of beams for beam search. Default is 1.
stream (bool): Flag to indicate if streaming output should be enabled. Default is None.
stop_words (List[str]): List of stop words to end generation. Default is an empty list.
"""

Expand Down
8 changes: 4 additions & 4 deletions swift/llm/argument/base_args/model_args.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import math
import os
from dataclasses import dataclass, field
from typing import Any, Dict, List, Literal, Optional, Union
from typing import Any, Dict, Literal, Optional, Union

import json
import torch
Expand All @@ -19,14 +19,14 @@ class ModelArguments:
ModelArguments class is a dataclass that holds various arguments related to model configuration and usage.

Args:
model (Optional[str]): Model identifier or path. Default is None.
model (Optional[str]): model_id or model_path. Default is None.
model_type (Optional[str]): Type of the model group. Default is None.
model_revision (Optional[str]): Revision of the model. Default is None.
torch_dtype (Literal): Model data type. Default is None.
torch_dtype (Literal): Model parameter dtype. Default is None.
attn_impl (Literal): Attention implementation to use. Default is None.
rope_scaling (Literal): Type of rope scaling to use. Default is None.
device_map (Optional[str]): Configuration for device mapping. Default is None.
local_repo_path (Optional[str]): Path to the local repository for model code. Default is None.
local_repo_path (Optional[str]): Path to the local github repository for model. Default is None.
"""
model: Optional[str] = None # model id or model path
model_type: Optional[str] = field(
Expand Down
6 changes: 4 additions & 2 deletions swift/llm/argument/base_args/quant_args.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ class QuantizeArguments:
QuantizeArguments is a dataclass that holds the configuration for model quantization.

Args:
quant_method (Literal['bnb', 'hqq', 'eetq', 'awq', 'gptq']): The quantization method to be used.
quant_bits (Literal[0, 1, 2, 3, 4, 8]): The number of bits to use for quantization.
quant_method (Literal['bnb', 'hqq', 'eetq']): The quantization method to be used.
quant_bits (Literal[1, 2, 3, 4, 8]): The number of bits to use for quantization.
hqq_axis (Optional[int]): The axis for hqq quantization.
bnb_4bit_compute_dtype (Literal['float16', 'bfloat16', 'float32', None]):
The compute dtype for bnb 4-bit quantization.
Expand Down Expand Up @@ -49,6 +49,8 @@ def get_quantization_config(self):
load_in_4bit, load_in_8bit = True, False
elif self.quant_bits == 8:
load_in_4bit, load_in_8bit = False, True
else:
raise ValueError(f'bnb not support quant_bits: {self.quant_bits}')

from transformers import BitsAndBytesConfig
quantization_config = BitsAndBytesConfig(
Expand Down
8 changes: 4 additions & 4 deletions swift/llm/argument/base_args/template_args.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Copyright (c) Alibaba, Inc. and its affiliates.
from dataclasses import dataclass, field
from typing import List, Literal, Optional
from typing import Literal, Optional

from swift.llm import TEMPLATE_MAPPING
from swift.utils import get_logger
Expand All @@ -14,14 +14,14 @@ class TemplateArguments:
TemplateArguments class is a dataclass that holds various arguments related to template configuration and usage.

Args:
template (Optional[str]): Template identifier. Default is None, meaning use the template of the model_type.
template (Optional[str]): Template type. Default is None, meaning use the template of the model_type.
system (Optional[str]): Override the default system in the template. Default is None.
max_length (Optional[int]): Maximum length for the template. Default is None.
truncation_strategy (Literal): Strategy for truncating the template. Default is 'left'.
tools_prompt (str): Override the default tools prompt in the template. Default is 'react_en'.
max_pixels (Optional[int]): Maximum number of pixels for the template. Default is None.
tools_prompt (str): Override the default tools prompt in the template. Default is 'react_en'.
loss_scale (str): Loss scale for training. Default is 'default',
meaning only calculate the loss of the response.
meaning only calculate the loss of the assistant.
sequence_parallel_size (int): Size of sequence parallelism. Default is 1.
use_chat_template (str): Use chat template or default generation template, default True
template_backend (str): Use swift template or jinja
Expand Down
4 changes: 2 additions & 2 deletions swift/llm/argument/deploy_args.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ class DeployArguments(InferArguments):
owned_by (str): The owner of the deployment. Default is 'swift'.
served_model_name (Optional[str]): The name of the model being served. Default is None.
verbose (bool): Whether to log request information. Default is True.
log_interval (int): The interval for printing global statistics. Default is 10.
max_logprobs(int): Max number of tokens' log probs to return
log_interval (int): The interval for printing global statistics. Default is 20.
max_logprobs(int): Max number of logprobs to return
"""
host: str = '0.0.0.0'
port: int = 8000
Expand Down
6 changes: 2 additions & 4 deletions swift/llm/argument/eval_args.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,7 @@
import datetime as dt
import os
from dataclasses import dataclass, field
from typing import List, Literal, Optional

import torch
from typing import List, Optional

from swift.utils import get_logger
from .base_args import to_abspath
Expand All @@ -16,7 +14,7 @@
@dataclass
class EvalArguments(DeployArguments):
"""
EvalArguments is a dataclass that extends InferArguments and is used to define
EvalArguments is a dataclass that extends DeployArguments and is used to define
the arguments required for evaluating a model.

Args:
Expand Down
11 changes: 5 additions & 6 deletions swift/llm/argument/export_args.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,7 @@
from dataclasses import dataclass, field
from typing import Literal, Optional

import torch.distributed as dist

from swift.utils import get_logger, is_dist
from swift.utils import get_logger
from .base_args import BaseArguments, to_abspath
from .merge_args import MergeArguments

Expand All @@ -19,8 +17,6 @@ class ExportArguments(MergeArguments, BaseArguments):

Args:
output_dir (Optional[str]): Directory where the output will be saved.
to_peft_format (bool): Flag to indicate if the output should be in PEFT format.
This argument is useless for now.
quant_n_samples (int): Number of samples for quantization.
max_length (int): Sequence length for quantization.
quant_batch_size (int): Batch size for quantization.
Expand All @@ -30,11 +26,12 @@ class ExportArguments(MergeArguments, BaseArguments):
hub_model_id (Optional[str]): Model ID for the hub.
hub_private_repo (bool): Flag to indicate if the hub repository is private.
commit_message (str): Commit message for pushing to the hub.
to_peft_format (bool): Flag to indicate if the output should be in PEFT format.
This argument is useless for now.
"""
ckpt_dir: Optional[str] = field(default=None, metadata={'help': '/path/to/your/vx-xxx/checkpoint-xxx'})
output_dir: Optional[str] = None

to_peft_format: bool = False
# awq/gptq
quant_method: Literal['awq', 'gptq'] = None
quant_n_samples: int = 256
Expand All @@ -52,6 +49,8 @@ class ExportArguments(MergeArguments, BaseArguments):
hub_model_id: Optional[str] = None
hub_private_repo: bool = False
commit_message: str = 'update files'
# compat
to_peft_format: bool = False

def _init_quant(self):

Expand Down
15 changes: 7 additions & 8 deletions swift/llm/argument/infer_args.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ class LmdeployArguments:
LmdeployArguments is a dataclass that holds the configuration for lmdeploy.

Args:
tp (int): Tensor parallelism degree. Default is 1.
tp (int): Tensor parallelism size. Default is 1.
session_len(Optional[int]): The session length, default None.
cache_max_entry_count (float): Maximum entry count for cache. Default is 0.8.
quant_policy (int): Quantization policy, e.g., 4, 8. Default is 0.
Expand Down Expand Up @@ -56,7 +56,7 @@ class VllmArguments:
pipeline_parallel_size(int): Pipeline parallelism size. Default is 1.
max_num_seqs (int): Maximum number of sequences. Default is 256.
max_model_len (Optional[int]): Maximum model length. Default is None.
disable_custom_all_reduce (bool): Flag to disable custom all-reduce. Default is True.
disable_custom_all_reduce (bool): Flag to disable custom all-reduce. Default is False.
enforce_eager (bool): Flag to enforce eager execution. Default is False.
limit_mm_per_prompt (Optional[str]): Limit multimedia per prompt. Default is None.
vllm_max_lora_rank (int): Maximum LoRA rank. Default is 16.
Expand Down Expand Up @@ -101,26 +101,25 @@ class InferArguments(MergeArguments, VllmArguments, LmdeployArguments, BaseArgum
It is used to define the arguments required for model inference.

Args:
ckpt_dir (Optional[str]): Directory to the checkpoint. Default is None.
infer_backend (Literal): Backend to use for inference. Default is 'pt'.
Allowed values are 'vllm', 'pt', 'lmdeploy'.
ckpt_dir (Optional[str]): Directory to the checkpoint. Default is None.
result_path (Optional[str]): Directory to store inference results. Default is None.
max_batch_size (int): Maximum batch size for the pt engine. Default is 1.
val_dataset_sample (Optional[int]): Sample size for validation dataset. Default is None.
result_dir (Optional[str]): Directory to store inference results. Default is None.
stream (Optional[bool]): Flag to indicate if streaming should be enabled. Default is None.
"""
ckpt_dir: Optional[str] = field(default=None, metadata={'help': '/path/to/your/vx-xxx/checkpoint-xxx'})
infer_backend: Literal['vllm', 'pt', 'lmdeploy'] = 'pt'

result_path: Optional[str] = None
writer_buffer_size: int = 65536 # B
writer_buffer_size: int = 65536
# for pt engine
max_batch_size: int = 1

# only for inference
val_dataset_sample: Optional[int] = None

def get_result_path(self, folder_name, suffix: str = '.jsonl') -> str:
def get_result_path(self, folder_name: str, suffix: str = '.jsonl') -> str:
result_dir = self.ckpt_dir or self.model_dir
result_dir = to_abspath(os.path.join(result_dir, folder_name))
os.makedirs(result_dir, exist_ok=True)
Expand Down Expand Up @@ -181,5 +180,5 @@ def _parse_lora_modules(self) -> None:
lora_request_list = []
for i, lora_module in enumerate(self.lora_modules):
lora_name, lora_path = lora_module.split('=')
lora_request_list.append(LoRARequest(lora_name, i + 1, lora_path))
lora_request_list.append(LoRARequest(lora_name, lora_path))
self.lora_request_list = lora_request_list
1 change: 0 additions & 1 deletion swift/llm/argument/rlhf_args.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ class RLHFArguments(TrainArguments):
ref_model_revision (Optional[str]): Revision of the reference model. Default is None.
beta (Optional[float]): Beta parameter for RLHF. Default is None.
label_smoothing (float): Label smoothing value. Default is 0.
loss_type (Optional[str]): Type of loss function. Default is None.
rpo_alpha (float): Alpha parameter for RPO. Default is 1.
cpo_alpha (float): Alpha parameter for CPO. Default is 1.
simpo_gamma (float): Gamma parameter for SimPO. Default is 1.
Expand Down
Loading