mirror of
https://github.com/hiyouga/LLaMA-Factory.git
synced 2025-09-20 03:52:49 +08:00
Compare commits
2 Commits
c5976f9b53
...
514d6d74fa
Author | SHA1 | Date | |
---|---|---|---|
|
514d6d74fa | ||
|
652e6e92da |
@ -5,7 +5,7 @@
|
|||||||
[](https://github.com/hiyouga/LLaMA-Factory/graphs/contributors)
|
[](https://github.com/hiyouga/LLaMA-Factory/graphs/contributors)
|
||||||
[](https://github.com/hiyouga/LLaMA-Factory/actions/workflows/tests.yml)
|
[](https://github.com/hiyouga/LLaMA-Factory/actions/workflows/tests.yml)
|
||||||
[](https://pypi.org/project/llamafactory/)
|
[](https://pypi.org/project/llamafactory/)
|
||||||
[](https://scholar.google.com/scholar?cites=12620864006390196564)
|
[](https://scholar.google.com/scholar?cites=12620864006390196564)
|
||||||
[](https://hub.docker.com/r/hiyouga/llamafactory/tags)
|
[](https://hub.docker.com/r/hiyouga/llamafactory/tags)
|
||||||
|
|
||||||
[](https://twitter.com/llamafactory_ai)
|
[](https://twitter.com/llamafactory_ai)
|
||||||
@ -124,12 +124,12 @@ Choose your path:
|
|||||||
|
|
||||||
[25/08/06] We supported fine-tuning the **[GPT-OSS](https://github.com/openai/gpt-oss)** models. See [PR #8826](https://github.com/hiyouga/LLaMA-Factory/pull/8826) to get started.
|
[25/08/06] We supported fine-tuning the **[GPT-OSS](https://github.com/openai/gpt-oss)** models. See [PR #8826](https://github.com/hiyouga/LLaMA-Factory/pull/8826) to get started.
|
||||||
|
|
||||||
|
<details><summary>Full Changelog</summary>
|
||||||
|
|
||||||
[25/07/02] We supported fine-tuning the **[GLM-4.1V-9B-Thinking](https://github.com/THUDM/GLM-4.1V-Thinking)** model.
|
[25/07/02] We supported fine-tuning the **[GLM-4.1V-9B-Thinking](https://github.com/THUDM/GLM-4.1V-Thinking)** model.
|
||||||
|
|
||||||
[25/04/28] We supported fine-tuning the **[Qwen3](https://qwenlm.github.io/blog/qwen3/)** model family.
|
[25/04/28] We supported fine-tuning the **[Qwen3](https://qwenlm.github.io/blog/qwen3/)** model family.
|
||||||
|
|
||||||
<details><summary>Full Changelog</summary>
|
|
||||||
|
|
||||||
[25/04/21] We supported the **[Muon](https://github.com/KellerJordan/Muon)** optimizer. See [examples](examples/README.md) for usage. Thank [@tianshijing](https://github.com/tianshijing)'s PR.
|
[25/04/21] We supported the **[Muon](https://github.com/KellerJordan/Muon)** optimizer. See [examples](examples/README.md) for usage. Thank [@tianshijing](https://github.com/tianshijing)'s PR.
|
||||||
|
|
||||||
[25/04/16] We supported fine-tuning the **[InternVL3](https://huggingface.co/OpenGVLab/InternVL3-8B)** model. See [PR #7258](https://github.com/hiyouga/LLaMA-Factory/pull/7258) to get started.
|
[25/04/16] We supported fine-tuning the **[InternVL3](https://huggingface.co/OpenGVLab/InternVL3-8B)** model. See [PR #7258](https://github.com/hiyouga/LLaMA-Factory/pull/7258) to get started.
|
||||||
|
@ -5,7 +5,7 @@
|
|||||||
[](https://github.com/hiyouga/LLaMA-Factory/graphs/contributors)
|
[](https://github.com/hiyouga/LLaMA-Factory/graphs/contributors)
|
||||||
[](https://github.com/hiyouga/LLaMA-Factory/actions/workflows/tests.yml)
|
[](https://github.com/hiyouga/LLaMA-Factory/actions/workflows/tests.yml)
|
||||||
[](https://pypi.org/project/llamafactory/)
|
[](https://pypi.org/project/llamafactory/)
|
||||||
[](https://scholar.google.com/scholar?cites=12620864006390196564)
|
[](https://scholar.google.com/scholar?cites=12620864006390196564)
|
||||||
[](https://hub.docker.com/r/hiyouga/llamafactory/tags)
|
[](https://hub.docker.com/r/hiyouga/llamafactory/tags)
|
||||||
|
|
||||||
[](https://twitter.com/llamafactory_ai)
|
[](https://twitter.com/llamafactory_ai)
|
||||||
@ -87,7 +87,7 @@ https://github.com/user-attachments/assets/43b700c6-a178-41db-b1f8-8190a5d3fcfc
|
|||||||
- **多种模型**:LLaMA、LLaVA、Mistral、Mixtral-MoE、Qwen、Qwen2-VL、DeepSeek、Yi、Gemma、ChatGLM、Phi 等等。
|
- **多种模型**:LLaMA、LLaVA、Mistral、Mixtral-MoE、Qwen、Qwen2-VL、DeepSeek、Yi、Gemma、ChatGLM、Phi 等等。
|
||||||
- **集成方法**:(增量)预训练、(多模态)指令监督微调、奖励模型训练、PPO 训练、DPO 训练、KTO 训练、ORPO 训练等等。
|
- **集成方法**:(增量)预训练、(多模态)指令监督微调、奖励模型训练、PPO 训练、DPO 训练、KTO 训练、ORPO 训练等等。
|
||||||
- **多种精度**:16 比特全参数微调、冻结微调、LoRA 微调和基于 AQLM/AWQ/GPTQ/LLM.int8/HQQ/EETQ 的 2/3/4/5/6/8 比特 QLoRA 微调。
|
- **多种精度**:16 比特全参数微调、冻结微调、LoRA 微调和基于 AQLM/AWQ/GPTQ/LLM.int8/HQQ/EETQ 的 2/3/4/5/6/8 比特 QLoRA 微调。
|
||||||
- **先进算法**:[GaLore](https://github.com/jiaweizzhao/GaLore)、[BAdam](https://github.com/Ledzy/BAdam)、[APOLLO](https://github.com/zhuhanqing/APOLLO)、[Adam-mini](https://github.com/zyushun/Adam-mini)、[Muon](https://github.com/KellerJordan/Muon)、 [OFT](https://github.com/huggingface/peft/tree/main/src/peft/tuners/oft)、DoRA、LongLoRA、LLaMA Pro、Mixture-of-Depths、LoRA+、LoftQ 和 PiSSA。
|
- **先进算法**:[GaLore](https://github.com/jiaweizzhao/GaLore)、[BAdam](https://github.com/Ledzy/BAdam)、[APOLLO](https://github.com/zhuhanqing/APOLLO)、[Adam-mini](https://github.com/zyushun/Adam-mini)、[Muon](https://github.com/KellerJordan/Muon)、[OFT](https://github.com/huggingface/peft/tree/main/src/peft/tuners/oft)、DoRA、LongLoRA、LLaMA Pro、Mixture-of-Depths、LoRA+、LoftQ 和 PiSSA。
|
||||||
- **实用技巧**:[FlashAttention-2](https://github.com/Dao-AILab/flash-attention)、[Unsloth](https://github.com/unslothai/unsloth)、[Liger Kernel](https://github.com/linkedin/Liger-Kernel)、RoPE scaling、NEFTune 和 rsLoRA。
|
- **实用技巧**:[FlashAttention-2](https://github.com/Dao-AILab/flash-attention)、[Unsloth](https://github.com/unslothai/unsloth)、[Liger Kernel](https://github.com/linkedin/Liger-Kernel)、RoPE scaling、NEFTune 和 rsLoRA。
|
||||||
- **广泛任务**:多轮对话、工具调用、图像理解、视觉定位、视频识别和语音理解等等。
|
- **广泛任务**:多轮对话、工具调用、图像理解、视觉定位、视频识别和语音理解等等。
|
||||||
- **实验监控**:LlamaBoard、TensorBoard、Wandb、MLflow、[SwanLab](https://github.com/SwanHubX/SwanLab) 等等。
|
- **实验监控**:LlamaBoard、TensorBoard、Wandb、MLflow、[SwanLab](https://github.com/SwanHubX/SwanLab) 等等。
|
||||||
@ -126,12 +126,12 @@ https://github.com/user-attachments/assets/43b700c6-a178-41db-b1f8-8190a5d3fcfc
|
|||||||
|
|
||||||
[25/08/06] 我们支持了 **[GPT-OSS](https://github.com/openai/gpt-oss)** 模型的微调。查看 [PR #8826](https://github.com/hiyouga/LLaMA-Factory/pull/8826) 以使用。
|
[25/08/06] 我们支持了 **[GPT-OSS](https://github.com/openai/gpt-oss)** 模型的微调。查看 [PR #8826](https://github.com/hiyouga/LLaMA-Factory/pull/8826) 以使用。
|
||||||
|
|
||||||
|
<details><summary>展开日志</summary>
|
||||||
|
|
||||||
[25/07/02] 我们支持了 **[GLM-4.1V-9B-Thinking](https://github.com/THUDM/GLM-4.1V-Thinking)** 模型的微调。
|
[25/07/02] 我们支持了 **[GLM-4.1V-9B-Thinking](https://github.com/THUDM/GLM-4.1V-Thinking)** 模型的微调。
|
||||||
|
|
||||||
[25/04/28] 我们支持了 **[Qwen3](https://qwenlm.github.io/blog/qwen3/)** 系列模型的微调。
|
[25/04/28] 我们支持了 **[Qwen3](https://qwenlm.github.io/blog/qwen3/)** 系列模型的微调。
|
||||||
|
|
||||||
<details><summary>展开日志</summary>
|
|
||||||
|
|
||||||
[25/04/21] 我们支持了 **[Muon](https://github.com/KellerJordan/Muon)** 优化器。详细用法请参照 [examples](examples/README_zh.md)。感谢 [@tianshijing](https://github.com/tianshijing) 的 PR。
|
[25/04/21] 我们支持了 **[Muon](https://github.com/KellerJordan/Muon)** 优化器。详细用法请参照 [examples](examples/README_zh.md)。感谢 [@tianshijing](https://github.com/tianshijing) 的 PR。
|
||||||
|
|
||||||
[25/04/16] 我们支持了 **[InternVL3](https://huggingface.co/OpenGVLab/InternVL3-8B)** 模型的微调。查看 [PR #7258](https://github.com/hiyouga/LLaMA-Factory/pull/7258) 以使用。
|
[25/04/16] 我们支持了 **[InternVL3](https://huggingface.co/OpenGVLab/InternVL3-8B)** 模型的微调。查看 [PR #7258](https://github.com/hiyouga/LLaMA-Factory/pull/7258) 以使用。
|
||||||
|
Binary file not shown.
Before Width: | Height: | Size: 164 KiB After Width: | Height: | Size: 167 KiB |
Binary file not shown.
Before Width: | Height: | Size: 169 KiB After Width: | Height: | Size: 168 KiB |
@ -97,8 +97,11 @@ class FunctionFormatter(StringFormatter):
|
|||||||
@override
|
@override
|
||||||
def apply(self, **kwargs) -> SLOTS:
|
def apply(self, **kwargs) -> SLOTS:
|
||||||
content: str = kwargs.pop("content")
|
content: str = kwargs.pop("content")
|
||||||
regex = re.compile(r"<think>(.*)</think>", re.DOTALL)
|
thought_words, thought = kwargs.pop("thought_words", None), None
|
||||||
|
if thought_words and len(thought_words) == 2:
|
||||||
|
regex = re.compile(rf"{re.escape(thought_words[0])}(.*?){re.escape(thought_words[1])}", re.DOTALL)
|
||||||
thought = re.search(regex, content)
|
thought = re.search(regex, content)
|
||||||
|
|
||||||
if thought:
|
if thought:
|
||||||
content = content.replace(thought.group(0), "")
|
content = content.replace(thought.group(0), "")
|
||||||
|
|
||||||
|
@ -156,7 +156,7 @@ class Template:
|
|||||||
elif message["role"] == Role.OBSERVATION:
|
elif message["role"] == Role.OBSERVATION:
|
||||||
elements += self.format_observation.apply(content=message["content"])
|
elements += self.format_observation.apply(content=message["content"])
|
||||||
elif message["role"] == Role.FUNCTION:
|
elif message["role"] == Role.FUNCTION:
|
||||||
elements += self.format_function.apply(content=message["content"])
|
elements += self.format_function.apply(content=message["content"], thought_words=self.thought_words)
|
||||||
else:
|
else:
|
||||||
raise NotImplementedError("Unexpected role: {}".format(message["role"]))
|
raise NotImplementedError("Unexpected role: {}".format(message["role"]))
|
||||||
|
|
||||||
@ -1855,6 +1855,20 @@ register_template(
|
|||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
# copied from seed_coder
|
||||||
|
register_template(
|
||||||
|
name="seed_oss",
|
||||||
|
format_user=StringFormatter(
|
||||||
|
slots=[{"bos_token"}, "user\n{{content}}", {"eos_token"}, {"bos_token"}, "assistant\n"]
|
||||||
|
),
|
||||||
|
format_system=StringFormatter(slots=[{"bos_token"}, "system\n{{content}}", {"eos_token"}]),
|
||||||
|
format_function=FunctionFormatter(slots=[{"bos_token"}, "\n{{content}}", {"eos_token"}], tool_format="seed_oss"),
|
||||||
|
format_tools=ToolFormatter(tool_format="seed_oss"),
|
||||||
|
template_class=ReasoningTemplate,
|
||||||
|
thought_words=("<seed:think>", "</seed:think>"),
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
# copied from llama3 template
|
# copied from llama3 template
|
||||||
register_template(
|
register_template(
|
||||||
name="skywork_o1",
|
name="skywork_o1",
|
||||||
|
@ -69,6 +69,15 @@ QWEN_TOOL_PROMPT = (
|
|||||||
""""arguments": <args-json-object>}}\n</tool_call>"""
|
""""arguments": <args-json-object>}}\n</tool_call>"""
|
||||||
)
|
)
|
||||||
|
|
||||||
|
SEED_TOOL_PROMPT = (
|
||||||
|
"system\nYou are Doubao, a helpful AI assistant. You may call one or more functions to assist with the user query."
|
||||||
|
"Tool List:\nYou are authorized to use the following tools (described in JSON Schema format). Before performing "
|
||||||
|
"any task, you must decide how to call them based on the descriptions and parameters of these tools.{tool_text}\n"
|
||||||
|
"工具调用请遵循如下格式:\n<seed:tool_call>\n<function=example_function_name>\n<parameter=example_parameter_1>value_1"
|
||||||
|
"</parameter>\n<parameter=example_parameter_2>This is the value for the second parameter\nthat can span\nmultiple "
|
||||||
|
"lines</parameter>\n</function>\n</seed:tool_call>\n"
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
@dataclass
|
@dataclass
|
||||||
class ToolUtils(ABC):
|
class ToolUtils(ABC):
|
||||||
@ -347,6 +356,56 @@ class GLM4MOEToolUtils(QwenToolUtils):
|
|||||||
return "\n".join(function_texts)
|
return "\n".join(function_texts)
|
||||||
|
|
||||||
|
|
||||||
|
class SeedToolUtils(ToolUtils):
|
||||||
|
r"""Seed tool using template."""
|
||||||
|
|
||||||
|
@override
|
||||||
|
@staticmethod
|
||||||
|
def tool_formatter(tools: list[dict[str, Any]]) -> str:
|
||||||
|
return SEED_TOOL_PROMPT.format(tool_text="\n" + json.dumps(tools, ensure_ascii=False))
|
||||||
|
|
||||||
|
@override
|
||||||
|
@staticmethod
|
||||||
|
def function_formatter(functions: list["FunctionCall"]) -> str:
|
||||||
|
function_json = [
|
||||||
|
{"func_name": name, "func_key_values": json.loads(arguments)} for name, arguments in functions
|
||||||
|
]
|
||||||
|
function_texts = []
|
||||||
|
for func in function_json:
|
||||||
|
prompt = "\n<seed:tool_call>\n<function=" + func["func_name"]
|
||||||
|
for key, value in func["func_key_values"].items():
|
||||||
|
prompt += "\n<parameter=" + key + ">"
|
||||||
|
if not isinstance(value, str):
|
||||||
|
value = json.dumps(value, ensure_ascii=False)
|
||||||
|
prompt += value + "</parameter>"
|
||||||
|
prompt += "\n</function>\n</seed:tool_call>"
|
||||||
|
function_texts.append(prompt)
|
||||||
|
|
||||||
|
return "\n".join(function_texts)
|
||||||
|
|
||||||
|
@override
|
||||||
|
@staticmethod
|
||||||
|
def tool_extractor(content: str) -> Union[str, list["FunctionCall"]]:
|
||||||
|
results = []
|
||||||
|
regex = re.compile(
|
||||||
|
r"<seed:tool_call>\s*<function=\s*([^\s<]+)\s*(.*?)\s*</function>\s*</seed:tool_call>", re.DOTALL
|
||||||
|
)
|
||||||
|
for func_name, params_block in re.findall(regex, content):
|
||||||
|
args_dict = {}
|
||||||
|
param_pattern = re.compile(r"<parameter=(.*?)>(.*?)</parameter>", re.DOTALL)
|
||||||
|
for key, raw_value in re.findall(param_pattern, params_block.strip()):
|
||||||
|
value = raw_value.strip()
|
||||||
|
try:
|
||||||
|
parsed_value = json.loads(value)
|
||||||
|
except json.JSONDecodeError:
|
||||||
|
parsed_value = raw_value
|
||||||
|
args_dict[key] = parsed_value
|
||||||
|
|
||||||
|
results.append(FunctionCall(func_name.strip(), json.dumps(args_dict, ensure_ascii=False)))
|
||||||
|
|
||||||
|
return results
|
||||||
|
|
||||||
|
|
||||||
TOOLS = {
|
TOOLS = {
|
||||||
"default": DefaultToolUtils(),
|
"default": DefaultToolUtils(),
|
||||||
"glm4": GLM4ToolUtils(),
|
"glm4": GLM4ToolUtils(),
|
||||||
@ -354,6 +413,7 @@ TOOLS = {
|
|||||||
"mistral": MistralToolUtils(),
|
"mistral": MistralToolUtils(),
|
||||||
"qwen": QwenToolUtils(),
|
"qwen": QwenToolUtils(),
|
||||||
"glm4_moe": GLM4MOEToolUtils(),
|
"glm4_moe": GLM4MOEToolUtils(),
|
||||||
|
"seed_oss": SeedToolUtils(),
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -645,6 +645,7 @@ register_model_group(
|
|||||||
template="falcon",
|
template="falcon",
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
register_model_group(
|
register_model_group(
|
||||||
models={
|
models={
|
||||||
"Falcon-H1-0.5B-Base": {
|
"Falcon-H1-0.5B-Base": {
|
||||||
@ -1264,6 +1265,7 @@ register_model_group(
|
|||||||
multimodal=True,
|
multimodal=True,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
register_model_group(
|
register_model_group(
|
||||||
models={
|
models={
|
||||||
"Intern-S1-mini": {
|
"Intern-S1-mini": {
|
||||||
@ -1275,6 +1277,7 @@ register_model_group(
|
|||||||
multimodal=True,
|
multimodal=True,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
register_model_group(
|
register_model_group(
|
||||||
models={
|
models={
|
||||||
"Jamba-v0.1": {
|
"Jamba-v0.1": {
|
||||||
@ -3039,18 +3042,40 @@ register_model_group(
|
|||||||
models={
|
models={
|
||||||
"Seed-Coder-8B-Base": {
|
"Seed-Coder-8B-Base": {
|
||||||
DownloadSource.DEFAULT: "ByteDance-Seed/Seed-Coder-8B-Base",
|
DownloadSource.DEFAULT: "ByteDance-Seed/Seed-Coder-8B-Base",
|
||||||
|
DownloadSource.MODELSCOPE: "ByteDance-Seed/Seed-Coder-8B-Base",
|
||||||
},
|
},
|
||||||
"Seed-Coder-8B-Instruct": {
|
"Seed-Coder-8B-Instruct": {
|
||||||
DownloadSource.DEFAULT: "ByteDance-Seed/Seed-Coder-8B-Instruct",
|
DownloadSource.DEFAULT: "ByteDance-Seed/Seed-Coder-8B-Instruct",
|
||||||
|
DownloadSource.MODELSCOPE: "ByteDance-Seed/Seed-Coder-8B-Instruct",
|
||||||
},
|
},
|
||||||
"Seed-Coder-8B-Instruct-Reasoning": {
|
"Seed-Coder-8B-Thinking": {
|
||||||
DownloadSource.DEFAULT: "ByteDance-Seed/Seed-Coder-8B-Reasoning-bf16",
|
DownloadSource.DEFAULT: "ByteDance-Seed/Seed-Coder-8B-Reasoning-bf16",
|
||||||
|
DownloadSource.MODELSCOPE: "ByteDance-Seed/Seed-Coder-8B-Reasoning-bf16",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
template="seed_coder",
|
template="seed_coder",
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
register_model_group(
|
||||||
|
models={
|
||||||
|
"Seed-OSS-36B-Base": {
|
||||||
|
DownloadSource.DEFAULT: "ByteDance-Seed/Seed-OSS-36B-Base",
|
||||||
|
DownloadSource.MODELSCOPE: "ByteDance-Seed/Seed-OSS-36B-Base",
|
||||||
|
},
|
||||||
|
"Seed-OSS-36B-Base-woSyn": {
|
||||||
|
DownloadSource.DEFAULT: "ByteDance-Seed/Seed-OSS-36B-Base-woSyn",
|
||||||
|
DownloadSource.MODELSCOPE: "ByteDance-Seed/Seed-OSS-36B-Base-woSyn",
|
||||||
|
},
|
||||||
|
"Seed-OSS-36B-Instruct": {
|
||||||
|
DownloadSource.DEFAULT: "ByteDance-Seed/Seed-OSS-36B-Instruct",
|
||||||
|
DownloadSource.MODELSCOPE: "ByteDance-Seed/Seed-OSS-36B-Instruct",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
template="seed_oss",
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
register_model_group(
|
register_model_group(
|
||||||
models={
|
models={
|
||||||
"Skywork-13B-Base": {
|
"Skywork-13B-Base": {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user