diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index 9b816bee..f891f711 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -22,7 +22,7 @@ jobs: - name: Install dependencies run: | python -m pip install --upgrade pip - python -m pip install black ruff + python -m pip install ruff - name: Check quality run: | diff --git a/Makefile b/Makefile index fec4443e..26287cee 100644 --- a/Makefile +++ b/Makefile @@ -3,9 +3,9 @@ check_dirs := src tests quality: - black --check $(check_dirs) ruff $(check_dirs) + ruff format --check $(check_dirs) style: - black $(check_dirs) ruff $(check_dirs) --fix + ruff format $(check_dirs) diff --git a/README.md b/README.md index 358d775a..c8ec1054 100644 --- a/README.md +++ b/README.md @@ -398,6 +398,9 @@ CUDA_VISIBLE_DEVICES=0 python src/train_bash.py \ --fp16 ``` +> [!TIP] +> Use `--adapter_name_or_path path_to_sft_checkpoint,path_to_ppo_checkpoint` to infer the fine-tuned model. + > [!WARNING] > Use `--per_device_train_batch_size=1` for LLaMA-2 models in fp16 PPO training. @@ -426,6 +429,9 @@ CUDA_VISIBLE_DEVICES=0 python src/train_bash.py \ --fp16 ``` +> [!TIP] +> Use `--adapter_name_or_path path_to_sft_checkpoint,path_to_dpo_checkpoint` to infer the fine-tuned model. + ### Distributed Training #### Use Huggingface Accelerate diff --git a/README_zh.md b/README_zh.md index 41299bfb..6b2e3d53 100644 --- a/README_zh.md +++ b/README_zh.md @@ -398,6 +398,9 @@ CUDA_VISIBLE_DEVICES=0 python src/train_bash.py \ --fp16 ``` +> [!TIP] +> 使用 `--adapter_name_or_path path_to_sft_checkpoint,path_to_ppo_checkpoint` 来进行微调模型的推理。 + > [!WARNING] > 如果使用 fp16 精度进行 LLaMA-2 模型的 PPO 训练,请使用 `--per_device_train_batch_size=1`。 @@ -426,6 +429,9 @@ CUDA_VISIBLE_DEVICES=0 python src/train_bash.py \ --fp16 ``` +> [!TIP] +> 使用 `--adapter_name_or_path path_to_sft_checkpoint,path_to_dpo_checkpoint` 来进行微调模型的推理。 + ### 多 GPU 分布式训练 #### 使用 Huggingface Accelerate diff --git a/pyproject.toml b/pyproject.toml index 04afe4cc..555515ea 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -2,11 +2,8 @@ requires = ["setuptools>=61.0"] build-backend = "setuptools.build_meta" -[tool.black] -line-length = 119 -target-version = ["py38"] - [tool.ruff] +target-version = "py38" line-length = 119 indent-width = 4 @@ -17,17 +14,7 @@ select = ["C", "E", "F", "I", "W"] [tool.ruff.lint.isort] lines-after-imports = 2 known-first-party = ["llmtuner"] - -[tool.ruff.format] -quote-style = "double" -indent-style = "space" -skip-magic-trailing-comma = false -line-ending = "auto" - -[isort] -default_section = "FIRSTPARTY" -known_first_party = "llmtuner" -known_third_party = [ +known-third-party = [ "accelerate", "datasets", "gradio", @@ -37,10 +24,9 @@ known_third_party = [ "transformers", "trl" ] -line_length = 119 -lines_after_imports = 2 -multi_line_output = 3 -include_trailing_comma = true -force_grid_wrap = 0 -use_parentheses = true -ensure_newline_before_comments = true + +[tool.ruff.format] +quote-style = "double" +indent-style = "space" +skip-magic-trailing-comma = false +line-ending = "auto" diff --git a/src/llmtuner/data/formatter.py b/src/llmtuner/data/formatter.py index a9632931..82dff8ca 100644 --- a/src/llmtuner/data/formatter.py +++ b/src/llmtuner/data/formatter.py @@ -75,7 +75,8 @@ class Formatter(ABC): tool_format: Literal["default"] = "default" @abstractmethod - def apply(self, **kwargs) -> SLOTS: ... + def apply(self, **kwargs) -> SLOTS: + ... def extract(self, content: str) -> Union[str, Tuple[str, str]]: raise NotImplementedError diff --git a/src/llmtuner/data/template.py b/src/llmtuner/data/template.py index 65d38bfb..07ecf72b 100644 --- a/src/llmtuner/data/template.py +++ b/src/llmtuner/data/template.py @@ -308,6 +308,15 @@ _register_template( ) +_register_template( + name="atom", + format_user=StringFormatter( + slots=[{"bos_token"}, "Human: {{content}}\n", {"eos_token"}, {"bos_token"}, "Assistant:"] + ), + format_assistant=StringFormatter(slots=["{{content}}\n", {"eos_token"}]), +) + + _register_template( name="baichuan", format_user=StringFormatter(slots=[{"token": ""}, "{{content}}", {"token": ""}]), @@ -515,7 +524,7 @@ _register_template( _register_template( name="openchat", format_user=StringFormatter(slots=["GPT4 Correct User: {{content}}", {"eos_token"}, "GPT4 Correct Assistant:"]), - format_assistant=StringFormatter(slots=["{{content}}"]), + format_assistant=StringFormatter(slots=["{{content}}", {"eos_token"}]), format_system=StringFormatter(slots=[{"bos_token"}, "{{content}}"]), force_system=True, ) @@ -644,9 +653,3 @@ _register_template( format_user=StringFormatter(slots=[{"token": ""}, ":{{content}}\n", {"token": ""}, ":"]), format_separator=EmptyFormatter(slots=["\n"]), ) - -_register_template( - name="atom", - format_user=StringFormatter(slots=[{"bos_token"}, "Human: {{content}}\n", {"eos_token"}, {"bos_token"}, "Assistant:"]), - format_assistant=StringFormatter(slots=["{{content}}\n", {"eos_token"}]), -) diff --git a/src/llmtuner/extras/constants.py b/src/llmtuner/extras/constants.py index 5e4a0cbb..e8e991fe 100644 --- a/src/llmtuner/extras/constants.py +++ b/src/llmtuner/extras/constants.py @@ -884,6 +884,7 @@ register_model_group( template="zephyr", ) + register_model_group( models={ "Atom-7B": { diff --git a/src/llmtuner/webui/components/top.py b/src/llmtuner/webui/components/top.py index d7b7501f..5c0d4f39 100644 --- a/src/llmtuner/webui/components/top.py +++ b/src/llmtuner/webui/components/top.py @@ -34,9 +34,7 @@ def create_top() -> Dict[str, "Component"]: model_name.change(list_adapters, [model_name, finetuning_type], [adapter_path], queue=False).then( get_model_path, [model_name], [model_path], queue=False - ).then( - get_template, [model_name], [template], queue=False - ) # do not save config since the below line will save + ).then(get_template, [model_name], [template], queue=False) # do not save config since the below line will save model_path.change(save_config, inputs=[lang, model_name, model_path], queue=False)