infixspeed-cli 0.0.16__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- infix_cli/__init__.py +5 -0
- infix_cli/__main__.py +6 -0
- infix_cli/agent-guide.txt +71 -0
- infix_cli/cli_framework.py +96 -0
- infix_cli/command_contract.py +157 -0
- infix_cli/commands/__init__.py +1 -0
- infix_cli/commands/_artifacts.py +142 -0
- infix_cli/commands/_comparison.py +443 -0
- infix_cli/commands/_confirm.py +26 -0
- infix_cli/commands/_control.py +290 -0
- infix_cli/commands/_create.py +351 -0
- infix_cli/commands/_create_output.py +139 -0
- infix_cli/commands/_delete.py +288 -0
- infix_cli/commands/_download.py +459 -0
- infix_cli/commands/_fusion_common.py +191 -0
- infix_cli/commands/_fusion_config.py +394 -0
- infix_cli/commands/_fusion_feedback.py +319 -0
- infix_cli/commands/_fusion_tasks.py +507 -0
- infix_cli/commands/_fusion_tensorboard.py +132 -0
- infix_cli/commands/_jobs.py +312 -0
- infix_cli/commands/_logs.py +210 -0
- infix_cli/commands/_publish.py +123 -0
- infix_cli/commands/_register.py +600 -0
- infix_cli/commands/_register_output.py +231 -0
- infix_cli/commands/_storage_tree.py +62 -0
- infix_cli/commands/admin.py +668 -0
- infix_cli/commands/asset.py +2012 -0
- infix_cli/commands/auth.py +246 -0
- infix_cli/commands/deploy.py +850 -0
- infix_cli/commands/evaluation.py +360 -0
- infix_cli/commands/examples.py +138 -0
- infix_cli/commands/fusion.py +1842 -0
- infix_cli/commands/merge.py +709 -0
- infix_cli/commands/resource.py +127 -0
- infix_cli/commands/spark.py +347 -0
- infix_cli/commands/storage.py +329 -0
- infix_cli/commands/training.py +748 -0
- infix_cli/config.py +311 -0
- infix_cli/config_input.py +217 -0
- infix_cli/context.py +84 -0
- infix_cli/discovery.py +459 -0
- infix_cli/domain/__init__.py +1 -0
- infix_cli/domain/dto/__init__.py +6 -0
- infix_cli/domain/dto/admin.py +413 -0
- infix_cli/domain/dto/asset.py +390 -0
- infix_cli/domain/dto/common.py +136 -0
- infix_cli/domain/dto/evaluation.py +296 -0
- infix_cli/domain/dto/logs.py +98 -0
- infix_cli/domain/dto/resource.py +108 -0
- infix_cli/domain/dto/serving.py +156 -0
- infix_cli/domain/dto/spark.py +241 -0
- infix_cli/domain/dto/storage.py +75 -0
- infix_cli/domain/dto/training.py +272 -0
- infix_cli/domain/enums.py +359 -0
- infix_cli/domain/hyperparams.py +190 -0
- infix_cli/domain/refs.py +108 -0
- infix_cli/domain/resolve.py +619 -0
- infix_cli/errors.py +158 -0
- infix_cli/example_data/__init__.py +1 -0
- infix_cli/example_data/fusion/README.md +128 -0
- infix_cli/example_data/fusion/fusion.json +149 -0
- infix_cli/example_data/fusion/prompts/code.jsonl +16 -0
- infix_cli/example_data/fusion/prompts/math.jsonl +16 -0
- infix_cli/example_data/fusion.zip +0 -0
- infix_cli/example_data/merge/README.md +89 -0
- infix_cli/example_data/merge/merge.json +26 -0
- infix_cli/example_data/merge.zip +0 -0
- infix_cli/http/__init__.py +1 -0
- infix_cli/http/browser_auth.py +160 -0
- infix_cli/http/client.py +575 -0
- infix_cli/http/pagination.py +84 -0
- infix_cli/http/upload.py +254 -0
- infix_cli/main.py +432 -0
- infix_cli/pipeline_config_schema.py +122 -0
- infix_cli/render/__init__.py +79 -0
- infix_cli/render/json_out.py +123 -0
- infix_cli/render/progress.py +62 -0
- infix_cli/render/text.py +233 -0
- infix_cli/update_check.py +177 -0
- infix_cli/waiter.py +93 -0
- infix_cli/workspace.py +158 -0
- infixspeed_cli-0.0.16.dist-info/METADATA +58 -0
- infixspeed_cli-0.0.16.dist-info/RECORD +85 -0
- infixspeed_cli-0.0.16.dist-info/WHEEL +4 -0
- infixspeed_cli-0.0.16.dist-info/entry_points.txt +2 -0
infix_cli/errors.py
ADDED
|
@@ -0,0 +1,158 @@
|
|
|
1
|
+
"""Exit codes and the exception hierarchy that produces them.
|
|
2
|
+
|
|
3
|
+
This module is contract #1: every non-zero exit the CLI can produce is
|
|
4
|
+
defined here and nowhere else. Commands raise a ``CliError`` subclass;
|
|
5
|
+
``main.py`` is the single place that turns one into a process exit.
|
|
6
|
+
|
|
7
|
+
查询成功返回 0;等待命令按任务结果返回退出码。
|
|
8
|
+
"""
|
|
9
|
+
|
|
10
|
+
from __future__ import annotations
|
|
11
|
+
|
|
12
|
+
from enum import IntEnum
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
class ExitCode(IntEnum):
|
|
16
|
+
"""Process exit codes. Must stay within 1-125 (see below)."""
|
|
17
|
+
|
|
18
|
+
OK = 0
|
|
19
|
+
GENERAL = 1
|
|
20
|
+
USAGE = 2
|
|
21
|
+
AUTH = 3
|
|
22
|
+
NOT_FOUND = 4
|
|
23
|
+
FORBIDDEN = 5
|
|
24
|
+
TIMEOUT = 6
|
|
25
|
+
JOB_FAILED = 7
|
|
26
|
+
JOB_RUNNING = 8
|
|
27
|
+
PAUSED = 9
|
|
28
|
+
PARTIAL_FAILED = 10
|
|
29
|
+
|
|
30
|
+
|
|
31
|
+
# 126/127/128+N are reserved by the shell (not executable / not found /
|
|
32
|
+
# killed by signal, Ctrl-C -> 130), and exit() truncates to 8 unsigned bits,
|
|
33
|
+
# so -1 would surface as 255 and 256 as 0. Custom codes therefore live in 1-125.
|
|
34
|
+
|
|
35
|
+
|
|
36
|
+
class CliError(Exception):
|
|
37
|
+
"""Base for every error the CLI reports to the user.
|
|
38
|
+
|
|
39
|
+
``message`` is the one-line reason; ``hint`` is an optional next step
|
|
40
|
+
rendered as an indented second line. Both go to stderr — stdout carries
|
|
41
|
+
results only, so ``-o json`` stays machine-parseable on failure.
|
|
42
|
+
|
|
43
|
+
Rendering and the exit status are applied in one place — the command
|
|
44
|
+
group in ``main.py`` — so the installed binary and the test runner take
|
|
45
|
+
the same path.
|
|
46
|
+
"""
|
|
47
|
+
|
|
48
|
+
exit_code: int = int(ExitCode.GENERAL)
|
|
49
|
+
code = "INTERNAL_ERROR"
|
|
50
|
+
retryable = False
|
|
51
|
+
|
|
52
|
+
def __init__(
|
|
53
|
+
self, message: str, hint: str | None = None, *,
|
|
54
|
+
details: object = None, retryable: bool | None = None,
|
|
55
|
+
) -> None:
|
|
56
|
+
super().__init__(message)
|
|
57
|
+
self.message = message
|
|
58
|
+
self.hint = hint
|
|
59
|
+
self.details = details
|
|
60
|
+
self.http: dict[str, str | int] | None = None
|
|
61
|
+
if retryable is not None:
|
|
62
|
+
self.retryable = retryable
|
|
63
|
+
|
|
64
|
+
def show(self, no_color: bool = False, output: str = "json") -> None:
|
|
65
|
+
if output == "json":
|
|
66
|
+
import json
|
|
67
|
+
import sys
|
|
68
|
+
|
|
69
|
+
error = {
|
|
70
|
+
"code": self.code, "message": self.message,
|
|
71
|
+
"retryable": self.retryable, "exit_code": int(self.exit_code),
|
|
72
|
+
}
|
|
73
|
+
if self.hint:
|
|
74
|
+
error["hint"] = self.hint
|
|
75
|
+
if self.details is not None:
|
|
76
|
+
error["details"] = self.details
|
|
77
|
+
if self.http is not None:
|
|
78
|
+
error["http"] = self.http
|
|
79
|
+
print(json.dumps({"contract_version": "1", "error": error}, ensure_ascii=False), file=sys.stderr)
|
|
80
|
+
return
|
|
81
|
+
from infix_cli.render import text
|
|
82
|
+
|
|
83
|
+
message, hint = self.message, self.hint
|
|
84
|
+
if self.http is not None:
|
|
85
|
+
request = f"{self.http['method']} {self.http['path']}"
|
|
86
|
+
message += f" (HTTP {self.http['status']} {request})"
|
|
87
|
+
if hint == f"Failed request: {request}":
|
|
88
|
+
hint = None
|
|
89
|
+
text.print_error(message, hint, no_color=no_color)
|
|
90
|
+
|
|
91
|
+
|
|
92
|
+
class UsageError(CliError):
|
|
93
|
+
code = "INVALID_ARGUMENT"
|
|
94
|
+
exit_code = int(ExitCode.USAGE)
|
|
95
|
+
|
|
96
|
+
|
|
97
|
+
class AuthError(CliError):
|
|
98
|
+
code = "UNAUTHENTICATED"
|
|
99
|
+
exit_code = int(ExitCode.AUTH)
|
|
100
|
+
|
|
101
|
+
|
|
102
|
+
class NotFoundError(CliError):
|
|
103
|
+
code = "NOT_FOUND"
|
|
104
|
+
exit_code = int(ExitCode.NOT_FOUND)
|
|
105
|
+
|
|
106
|
+
|
|
107
|
+
class ForbiddenError(CliError):
|
|
108
|
+
code = "FORBIDDEN"
|
|
109
|
+
exit_code = int(ExitCode.FORBIDDEN)
|
|
110
|
+
|
|
111
|
+
|
|
112
|
+
class ConflictError(CliError):
|
|
113
|
+
code = "CONFLICT"
|
|
114
|
+
exit_code = int(ExitCode.GENERAL)
|
|
115
|
+
|
|
116
|
+
|
|
117
|
+
class ApiError(CliError):
|
|
118
|
+
"""Unclassified backend failure (5xx, transport errors)."""
|
|
119
|
+
|
|
120
|
+
exit_code = int(ExitCode.GENERAL)
|
|
121
|
+
code = "API_ERROR"
|
|
122
|
+
|
|
123
|
+
|
|
124
|
+
class SubmissionUnknown(ApiError):
|
|
125
|
+
"""写请求响应丢失,不能据此确定服务端是否执行成功。"""
|
|
126
|
+
|
|
127
|
+
code = "SUBMISSION_UNKNOWN"
|
|
128
|
+
|
|
129
|
+
|
|
130
|
+
class WaitTimeout(CliError):
|
|
131
|
+
code = "WAIT_TIMEOUT"
|
|
132
|
+
exit_code = int(ExitCode.TIMEOUT)
|
|
133
|
+
|
|
134
|
+
|
|
135
|
+
class JobFailed(CliError):
|
|
136
|
+
code = "JOB_FAILED"
|
|
137
|
+
exit_code = int(ExitCode.JOB_FAILED)
|
|
138
|
+
|
|
139
|
+
|
|
140
|
+
class Aborted(CliError):
|
|
141
|
+
"""The user answered no at a confirmation prompt."""
|
|
142
|
+
|
|
143
|
+
exit_code = int(ExitCode.GENERAL)
|
|
144
|
+
code = "ABORTED"
|
|
145
|
+
|
|
146
|
+
|
|
147
|
+
class ConfirmationRequired(UsageError):
|
|
148
|
+
code = "CONFIRMATION_REQUIRED"
|
|
149
|
+
|
|
150
|
+
|
|
151
|
+
class JobPaused(CliError):
|
|
152
|
+
code = "JOB_PAUSED"
|
|
153
|
+
exit_code = int(ExitCode.PAUSED)
|
|
154
|
+
|
|
155
|
+
|
|
156
|
+
class PartialFailure(CliError):
|
|
157
|
+
code = "PARTIAL_FAILED"
|
|
158
|
+
exit_code = int(ExitCode.PARTIAL_FAILED)
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"""安装包内的示例材料;通过 importlib.resources 读取,无需仓库目录。"""
|
|
@@ -0,0 +1,128 @@
|
|
|
1
|
+
# Model Fusion:双 Teacher 分阶段示例
|
|
2
|
+
|
|
3
|
+
Fusion 让 Student 学习 Teacher 的回答和输出分布。数学、代码两个领域分别绑定 Teacher 和问题集,先生成训练答案,再进行 Warmup 和 OPD。
|
|
4
|
+
|
|
5
|
+
本目录随 CLI 安装。用 `infix examples show fusion -o text` 离线阅读,或用 `infix examples export fusion --dir ./fusion-demo` 导出全部材料。后续命令在导出目录执行。
|
|
6
|
+
|
|
7
|
+
## 1. 准备模型、数据和资源
|
|
8
|
+
|
|
9
|
+
目录内容:
|
|
10
|
+
|
|
11
|
+
- `fusion.json`:完整五阶段配置,默认只执行 Split。
|
|
12
|
+
- `prompts/math.jsonl`、`prompts/code.jsonl`:每领域 16 条演示问题,用于验证数据格式和流程。Warmup、OPD 各一步,不代表能力提升。
|
|
13
|
+
|
|
14
|
+
首次使用时运行 `infix auth login`,在浏览器里确认比对码、选择工作空间并授权。Docker 沙箱或远程终端可加 `--no-browser`,用本机浏览器打开终端打印的链接。登录其他部署时加 `--api-url` 指定平台地址。已登录时可以直接用 `infix doctor` 检查连接。
|
|
15
|
+
|
|
16
|
+
```bash
|
|
17
|
+
infix auth login
|
|
18
|
+
infix doctor
|
|
19
|
+
infix asset model list --scope workspace
|
|
20
|
+
infix resource list --task training
|
|
21
|
+
infix fusion teachers
|
|
22
|
+
infix fusion check --show-format
|
|
23
|
+
```
|
|
24
|
+
|
|
25
|
+
编辑 `fusion.json`,替换所有 `REPLACE_WITH_*`:
|
|
26
|
+
|
|
27
|
+
| 字段 | 填写内容 |
|
|
28
|
+
| --- | --- |
|
|
29
|
+
| `student` | 已注册的 Student 模型版本 |
|
|
30
|
+
| `teachers.math.model` | 数学 Teacher 模型版本 |
|
|
31
|
+
| `teachers.code.model` | 代码 Teacher 模型版本 |
|
|
32
|
+
| 各阶段 `resources` | 当前环境的 CPU、内存、GPU 型号和数量 |
|
|
33
|
+
| `stages.opd.params.teacher_resources` | 每个 Teacher 的服务资源 |
|
|
34
|
+
|
|
35
|
+
引用格式为 `workspace/模型名:版本`,例如 `workspace/my-student:v1.0.0`;也可使用平台可见的 `official/模型名`。不要依靠模型名字判断兼容性:Student、Teacher 的 tokenizer、词表、模板和运行时能力需要通过平台预检。
|
|
36
|
+
|
|
37
|
+
配置按小模型、H800 和 BF16/native Warmup 编写。Distill 设置 `max_parallel_teachers=1`,逐个 Teacher 生成;OPD 同时需要 Student 和两个 Teacher 的资源。本例每个模型配置 1 张 GPU,OPD 计划需 3 张 GPU,实际需求以预检为准。调整硬件时同步修改 Student 和 Teacher 配置。
|
|
38
|
+
|
|
39
|
+
注册随附问题集(会上传本地文件并创建数据资产):
|
|
40
|
+
|
|
41
|
+
```bash
|
|
42
|
+
infix asset dataset register --name fusion-demo-math-prompts --source local --path ./prompts/math.jsonl --usage training --task sft --version v1.0.0 --wait
|
|
43
|
+
infix asset dataset register --name fusion-demo-code-prompts --source local --path ./prompts/code.jsonl --usage training --task sft --version v1.0.0 --wait
|
|
44
|
+
```
|
|
45
|
+
|
|
46
|
+
若已有同名资产,使用新的资产名/版本,并修改 `teachers.<领域>.prompt` 引用。问题行示例:
|
|
47
|
+
|
|
48
|
+
```json
|
|
49
|
+
{"id":"math-0001","messages":[{"role":"user","content":"3x + 7 = 22,求 x。"}],"metadata":{"teacher":"math","domain":"math"}}
|
|
50
|
+
```
|
|
51
|
+
|
|
52
|
+
`metadata.teacher` 和 `metadata.domain` 必须与配置中的领域 key 对应。本例使用 `math`、`code`。输入是问题;Distill 负责生成答案。更换自己的数据时保持 ID 唯一、去除重复题,并将独立评测集与训练问题隔离。
|
|
53
|
+
|
|
54
|
+
## 2. 预检并创建 Split 任务
|
|
55
|
+
|
|
56
|
+
```bash
|
|
57
|
+
export FUSION_TASK="fusion-demo-$(date +%Y%m%d-%H%M%S)-$RANDOM"
|
|
58
|
+
|
|
59
|
+
infix fusion run --config fusion.json --name "$FUSION_TASK" --to split --dry-run
|
|
60
|
+
infix fusion run --config fusion.json --name "$FUSION_TASK" --to split --wait --timeout 30m
|
|
61
|
+
infix fusion artifacts "$FUSION_TASK" --stage split
|
|
62
|
+
```
|
|
63
|
+
|
|
64
|
+
`--dry-run` 连接平台解析资产并检查参数和资源,提交后 Split 将每个领域的问题分为 Warmup 用的 A 组与 OPD 用的 B 组。`execution.stop_reason` 为 `awaiting_next_stage` 时表示已到达阶段边界。用 `infix fusion get "$FUSION_TASK"` 查询,`stages` 会显示 Split 是否已开始或完成。
|
|
65
|
+
|
|
66
|
+
## 3. 按阶段继续
|
|
67
|
+
|
|
68
|
+
| CLI 阶段 | JSON 阶段 key | 作用 |
|
|
69
|
+
| --- | --- | --- |
|
|
70
|
+
| `split` | `split` | 拆分 A/B 组问题 |
|
|
71
|
+
| `distill` | `generate` | Teacher 回答 A 组问题 |
|
|
72
|
+
| `clean` | `filter` | 清洗答案,转换为训练数据 |
|
|
73
|
+
| `warmup` | `sft` | Student 进行监督训练 |
|
|
74
|
+
| `opd` | `opd` | Student 在 B 组上采样并接受 Teacher 分布监督 |
|
|
75
|
+
|
|
76
|
+
计划执行训练时,可用 `infix fusion run --config fusion.json --to opd --dry-run` 预检完整计划。模型需要有平台支持的训练 profile,后续阶段产出的输入会在运行时继续验证。依次执行,每一步成功后检查产物再继续:
|
|
77
|
+
|
|
78
|
+
```bash
|
|
79
|
+
infix fusion resume "$FUSION_TASK" --to distill --wait --timeout 2h
|
|
80
|
+
infix fusion artifacts "$FUSION_TASK" --stage distill
|
|
81
|
+
|
|
82
|
+
infix fusion resume "$FUSION_TASK" --to clean --wait --timeout 30m
|
|
83
|
+
infix fusion artifacts "$FUSION_TASK" --stage clean
|
|
84
|
+
|
|
85
|
+
infix fusion resume "$FUSION_TASK" --to warmup --wait --timeout 2h
|
|
86
|
+
infix fusion artifacts "$FUSION_TASK" --stage warmup
|
|
87
|
+
|
|
88
|
+
infix fusion resume "$FUSION_TASK" --to opd --dry-run
|
|
89
|
+
infix fusion resume "$FUSION_TASK" --to opd --wait --timeout 2h
|
|
90
|
+
infix fusion artifacts "$FUSION_TASK" --stage opd
|
|
91
|
+
```
|
|
92
|
+
|
|
93
|
+
如果清洗或生成因质量比例暂停,先检查失败样本和保留数据量,再决定是否使用 `resume --accept-data`。硬性格式错误需要修复输入。查询状态及日志:
|
|
94
|
+
|
|
95
|
+
```bash
|
|
96
|
+
infix fusion get "$FUSION_TASK"
|
|
97
|
+
infix fusion logs "$FUSION_TASK" --stage opd
|
|
98
|
+
```
|
|
99
|
+
|
|
100
|
+
`--timeout` 和 Ctrl-C 只停止本地等待,远端任务继续。新终端中把 `FUSION_TASK` 重新设为已创建任务的名称,避免重复创建。
|
|
101
|
+
|
|
102
|
+
## 4. 评测并注册
|
|
103
|
+
|
|
104
|
+
以下示例使用有原生聊天模板的模型和平台提供的 IFEval。把基线替换为 `fusion.json` 中的初始 Student;评测集需在当前平台可用。IFEval 只衡量指令遵循,数学和代码能力还应使用独立的领域评测集。
|
|
105
|
+
|
|
106
|
+
```bash
|
|
107
|
+
export COMPARE_TASK="cmp-fusion-$(date +%Y%m%d-%H%M%S)-$RANDOM"
|
|
108
|
+
|
|
109
|
+
infix evaluation compare \
|
|
110
|
+
--name "$COMPARE_TASK" \
|
|
111
|
+
--baseline workspace/REPLACE_WITH_STUDENT:v1.0.0 \
|
|
112
|
+
--candidate-from-fusion "$FUSION_TASK" --last 1 \
|
|
113
|
+
--dataset official/IFEval --eval-type official \
|
|
114
|
+
--chat-template model --max-parallel 1 --gpu-count 1 \
|
|
115
|
+
--wait --timeout 6h
|
|
116
|
+
|
|
117
|
+
infix evaluation compare-get "$COMPARE_TASK"
|
|
118
|
+
```
|
|
119
|
+
|
|
120
|
+
基线和候选需要使用相同的评测数据和模板协议。没有原生聊天模板的模型,可在平台支持时统一使用 `--chat-template plain`,同时说明结果采用纯文本协议。`BackoffLimitExceeded` 只表示作业重试耗尽,具体原因用 `infix evaluation logs 子评测任务ID` 查看。
|
|
121
|
+
|
|
122
|
+
确认评测结果后,将完整 OPD checkpoint 注册为独立模型资产:
|
|
123
|
+
|
|
124
|
+
```bash
|
|
125
|
+
infix fusion register "$FUSION_TASK" --checkpoint latest --name "student-fused-$(date +%Y%m%d-%H%M%S)" --version v1.0.0 --wait
|
|
126
|
+
```
|
|
127
|
+
|
|
128
|
+
正式效果实验需要增加问题数量和训练步数,调整学习率、领域采样比例和上下文长度,并比较初始、Warmup、OPD 的结果。本示例中的参数是流程演示起点,不能保证提高分数。
|
|
@@ -0,0 +1,149 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "fusion-demo",
|
|
3
|
+
"from": "split",
|
|
4
|
+
"to": "split",
|
|
5
|
+
"student": "workspace/REPLACE_WITH_STUDENT:v1.0.0",
|
|
6
|
+
"teachers": {
|
|
7
|
+
"math": {
|
|
8
|
+
"model": "workspace/REPLACE_WITH_MATH_TEACHER:v1.0.0",
|
|
9
|
+
"prompt": "workspace/fusion-demo-math-prompts:v1.0.0"
|
|
10
|
+
},
|
|
11
|
+
"code": {
|
|
12
|
+
"model": "workspace/REPLACE_WITH_CODE_TEACHER:v1.0.0",
|
|
13
|
+
"prompt": "workspace/fusion-demo-code-prompts:v1.0.0"
|
|
14
|
+
}
|
|
15
|
+
},
|
|
16
|
+
"stages": {
|
|
17
|
+
"split": {
|
|
18
|
+
"params": {
|
|
19
|
+
"sft_ratio": 0.5,
|
|
20
|
+
"seed": 42
|
|
21
|
+
},
|
|
22
|
+
"resources": {
|
|
23
|
+
"cpu": "1",
|
|
24
|
+
"memory": "2Gi",
|
|
25
|
+
"gpu_count": 0
|
|
26
|
+
}
|
|
27
|
+
},
|
|
28
|
+
"generate": {
|
|
29
|
+
"params": {
|
|
30
|
+
"enable_thinking": false,
|
|
31
|
+
"context_length": 1024,
|
|
32
|
+
"max_new_tokens": 256,
|
|
33
|
+
"max_attempts": 3,
|
|
34
|
+
"concurrency": 1,
|
|
35
|
+
"seed": 42,
|
|
36
|
+
"temperature": 0.0,
|
|
37
|
+
"teacher_service": {
|
|
38
|
+
"context_length": 2048,
|
|
39
|
+
"mem_fraction": 0.5,
|
|
40
|
+
"concurrency": 1,
|
|
41
|
+
"disable_cuda_graph": true,
|
|
42
|
+
"ready_timeout": 300
|
|
43
|
+
},
|
|
44
|
+
"max_parallel_teachers": 1
|
|
45
|
+
},
|
|
46
|
+
"resources": {
|
|
47
|
+
"cpu": "8",
|
|
48
|
+
"memory": "32Gi",
|
|
49
|
+
"gpu_count": 1,
|
|
50
|
+
"gpu_type": "H800"
|
|
51
|
+
}
|
|
52
|
+
},
|
|
53
|
+
"filter": {
|
|
54
|
+
"params": {
|
|
55
|
+
"max_total_tokens": 1024,
|
|
56
|
+
"max_drop_ratio": 0.2,
|
|
57
|
+
"enable_thinking": false
|
|
58
|
+
},
|
|
59
|
+
"resources": {
|
|
60
|
+
"cpu": "2",
|
|
61
|
+
"memory": "4Gi",
|
|
62
|
+
"gpu_count": 0
|
|
63
|
+
}
|
|
64
|
+
},
|
|
65
|
+
"sft": {
|
|
66
|
+
"params": {
|
|
67
|
+
"batch_size": 2,
|
|
68
|
+
"learning_rate": 1e-06,
|
|
69
|
+
"warmup_updates": 0,
|
|
70
|
+
"context_length": 1024,
|
|
71
|
+
"enable_thinking": false,
|
|
72
|
+
"epochs": 1,
|
|
73
|
+
"updates": 1,
|
|
74
|
+
"save_interval": 1,
|
|
75
|
+
"seed": 42,
|
|
76
|
+
"topology": {
|
|
77
|
+
"actor_nodes": 1,
|
|
78
|
+
"max_tokens_per_gpu": 1024,
|
|
79
|
+
"tp": 1,
|
|
80
|
+
"cp": 1,
|
|
81
|
+
"pp": 1,
|
|
82
|
+
"ep": 1
|
|
83
|
+
},
|
|
84
|
+
"checkpoint_precision": "only-bf16",
|
|
85
|
+
"training_precision": "bf16",
|
|
86
|
+
"training_backend": "native"
|
|
87
|
+
},
|
|
88
|
+
"resources": {
|
|
89
|
+
"cpu": "8",
|
|
90
|
+
"memory": "64Gi",
|
|
91
|
+
"gpu_count": 1,
|
|
92
|
+
"gpu_type": "H800"
|
|
93
|
+
}
|
|
94
|
+
},
|
|
95
|
+
"opd": {
|
|
96
|
+
"params": {
|
|
97
|
+
"batch_size": 2,
|
|
98
|
+
"learning_rate": 1e-06,
|
|
99
|
+
"warmup_updates": 0,
|
|
100
|
+
"context_length": 1024,
|
|
101
|
+
"enable_thinking": false,
|
|
102
|
+
"updates": 1,
|
|
103
|
+
"save_interval": 1,
|
|
104
|
+
"seed": 42,
|
|
105
|
+
"topology": {
|
|
106
|
+
"actor_nodes": 1,
|
|
107
|
+
"max_tokens_per_gpu": 1024,
|
|
108
|
+
"rollout_concurrency": 1,
|
|
109
|
+
"tp": 1,
|
|
110
|
+
"cp": 1,
|
|
111
|
+
"pp": 1,
|
|
112
|
+
"ep": 1
|
|
113
|
+
},
|
|
114
|
+
"max_prompt_tokens": 256,
|
|
115
|
+
"max_new_tokens": 64,
|
|
116
|
+
"num_rollouts_per_prompt": 1,
|
|
117
|
+
"teacher_resources": {
|
|
118
|
+
"cpu": "8",
|
|
119
|
+
"memory": "64Gi",
|
|
120
|
+
"gpu_count": 1,
|
|
121
|
+
"gpu_type": "H800"
|
|
122
|
+
},
|
|
123
|
+
"teacher_service": {
|
|
124
|
+
"context_length": 2048,
|
|
125
|
+
"concurrency": 1,
|
|
126
|
+
"mem_fraction": 0.5,
|
|
127
|
+
"disable_cuda_graph": true,
|
|
128
|
+
"ready_timeout": 300
|
|
129
|
+
},
|
|
130
|
+
"distill_divergence": "jsd",
|
|
131
|
+
"routing_strategy": "hard",
|
|
132
|
+
"temperature": 1.0,
|
|
133
|
+
"top_p": 1.0,
|
|
134
|
+
"domain_mix_ratio": {
|
|
135
|
+
"math": 0.5,
|
|
136
|
+
"code": 0.5
|
|
137
|
+
}
|
|
138
|
+
},
|
|
139
|
+
"resources": {
|
|
140
|
+
"cpu": "8",
|
|
141
|
+
"memory": "64Gi",
|
|
142
|
+
"gpu_count": 1,
|
|
143
|
+
"gpu_type": "H800"
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
},
|
|
147
|
+
"visibility": "private",
|
|
148
|
+
"description": "双 Teacher 五阶段流程示例;默认停在 split,训练各一步,仅验证流程。运行前替换模型/数据引用并调整资源。"
|
|
149
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
{"id": "code-0001", "messages": [{"role": "user", "content": "用 Python 实现 add(a, b),返回两个数的和,并给出一个调用示例。"}], "metadata": {"teacher": "code", "domain": "code"}}
|
|
2
|
+
{"id": "code-0002", "messages": [{"role": "user", "content": "用 Python 实现 is_even(n),判断整数是否为偶数。"}], "metadata": {"teacher": "code", "domain": "code"}}
|
|
3
|
+
{"id": "code-0003", "messages": [{"role": "user", "content": "用 Python 实现 reverse_text(text),返回字符串反转的结果。"}], "metadata": {"teacher": "code", "domain": "code"}}
|
|
4
|
+
{"id": "code-0004", "messages": [{"role": "user", "content": "用 Python 实现 maximum(values),返回非空数字列表中的最大值。"}], "metadata": {"teacher": "code", "domain": "code"}}
|
|
5
|
+
{"id": "code-0005", "messages": [{"role": "user", "content": "用 Python 实现 count_vowels(text),忽略大小写统计英文元音字符的个数。"}], "metadata": {"teacher": "code", "domain": "code"}}
|
|
6
|
+
{"id": "code-0006", "messages": [{"role": "user", "content": "用 Python 实现 factorial(n),n 为非负整数,包含 n=0 的情况。"}], "metadata": {"teacher": "code", "domain": "code"}}
|
|
7
|
+
{"id": "code-0007", "messages": [{"role": "user", "content": "用 Python 实现 unique_in_order(values),去除可哈希元素列表中的重复元素并保留原顺序。"}], "metadata": {"teacher": "code", "domain": "code"}}
|
|
8
|
+
{"id": "code-0008", "messages": [{"role": "user", "content": "用 Python 实现 sum_of_squares(n),计算 1 到 n 的平方和。"}], "metadata": {"teacher": "code", "domain": "code"}}
|
|
9
|
+
{"id": "code-0009", "messages": [{"role": "user", "content": "用 Python 实现 word_count(text),按空白分词并返回词数。"}], "metadata": {"teacher": "code", "domain": "code"}}
|
|
10
|
+
{"id": "code-0010", "messages": [{"role": "user", "content": "用 Python 实现 is_palindrome(text),直接判断原字符串是否为回文。"}], "metadata": {"teacher": "code", "domain": "code"}}
|
|
11
|
+
{"id": "code-0011", "messages": [{"role": "user", "content": "用 Python 实现 merge_sorted(a, b),合并两个升序整数列表,返回升序列表。"}], "metadata": {"teacher": "code", "domain": "code"}}
|
|
12
|
+
{"id": "code-0012", "messages": [{"role": "user", "content": "用 Python 实现 clamp(value, low, high),将数值限制在闭区间内。"}], "metadata": {"teacher": "code", "domain": "code"}}
|
|
13
|
+
{"id": "code-0013", "messages": [{"role": "user", "content": "用 Python 实现 frequencies(values),返回可哈希元素的出现次数字典。"}], "metadata": {"teacher": "code", "domain": "code"}}
|
|
14
|
+
{"id": "code-0014", "messages": [{"role": "user", "content": "用 Python 实现 first_positive(values),返回第一个正数,无正数时返回 None。"}], "metadata": {"teacher": "code", "domain": "code"}}
|
|
15
|
+
{"id": "code-0015", "messages": [{"role": "user", "content": "用 Python 实现 fibonacci(n),返回第 n 个斐波那契数,规定 F(0)=0、F(1)=1。"}], "metadata": {"teacher": "code", "domain": "code"}}
|
|
16
|
+
{"id": "code-0016", "messages": [{"role": "user", "content": "用 Python 实现 flatten_once(rows),将二维列表展开一层。"}], "metadata": {"teacher": "code", "domain": "code"}}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
{"id": "math-0001", "messages": [{"role": "user", "content": "小明有 12 个苹果,送出 5 个,又买入 3 个,现在有几个?请解释计算过程。"}], "metadata": {"teacher": "math", "domain": "math"}}
|
|
2
|
+
{"id": "math-0002", "messages": [{"role": "user", "content": "一辆车每小时行驶 60 千米,行驶 2.5 小时,共行驶多少千米?"}], "metadata": {"teacher": "math", "domain": "math"}}
|
|
3
|
+
{"id": "math-0003", "messages": [{"role": "user", "content": "一件商品原价 200 元,打八折后价格是多少?"}], "metadata": {"teacher": "math", "domain": "math"}}
|
|
4
|
+
{"id": "math-0004", "messages": [{"role": "user", "content": "长方形长 8 米、宽 3 米,面积和周长分别是多少?"}], "metadata": {"teacher": "math", "domain": "math"}}
|
|
5
|
+
{"id": "math-0005", "messages": [{"role": "user", "content": "把 48 本书平均分给 6 个小组,每组有几本?"}], "metadata": {"teacher": "math", "domain": "math"}}
|
|
6
|
+
{"id": "math-0006", "messages": [{"role": "user", "content": "解方程:3x + 7 = 22。请给出步骤。"}], "metadata": {"teacher": "math", "domain": "math"}}
|
|
7
|
+
{"id": "math-0007", "messages": [{"role": "user", "content": "一个数的四分之一是 9,这个数是多少?"}], "metadata": {"teacher": "math", "domain": "math"}}
|
|
8
|
+
{"id": "math-0008", "messages": [{"role": "user", "content": "两种水果共 30 个,苹果比梨多 6 个,苹果和梨各几个?"}], "metadata": {"teacher": "math", "domain": "math"}}
|
|
9
|
+
{"id": "math-0009", "messages": [{"role": "user", "content": "计算 2/3 + 1/6,并化为最简分数。"}], "metadata": {"teacher": "math", "domain": "math"}}
|
|
10
|
+
{"id": "math-0010", "messages": [{"role": "user", "content": "水池每分钟流入 8 升水,同时流出 3 升,10 分钟净增加多少升?"}], "metadata": {"teacher": "math", "domain": "math"}}
|
|
11
|
+
{"id": "math-0011", "messages": [{"role": "user", "content": "甲、乙速度分别为每小时 5 千米和 3 千米,同向走 2 小时相差多远?"}], "metadata": {"teacher": "math", "domain": "math"}}
|
|
12
|
+
{"id": "math-0012", "messages": [{"role": "user", "content": "一本书共 120 页,第一天读 25%,还剩多少页?"}], "metadata": {"teacher": "math", "domain": "math"}}
|
|
13
|
+
{"id": "math-0013", "messages": [{"role": "user", "content": "三个连续整数的和是 36,三个整数分别是什么?"}], "metadata": {"teacher": "math", "domain": "math"}}
|
|
14
|
+
{"id": "math-0014", "messages": [{"role": "user", "content": "圆半径为 2 厘米,取圆周率 3.14,面积是多少?"}], "metadata": {"teacher": "math", "domain": "math"}}
|
|
15
|
+
{"id": "math-0015", "messages": [{"role": "user", "content": "5 次测验成绩分别为 80、90、85、95、100,平均分是多少?"}], "metadata": {"teacher": "math", "domain": "math"}}
|
|
16
|
+
{"id": "math-0016", "messages": [{"role": "user", "content": "一列火车长 200 米,以每秒 20 米通过长 300 米的桥,需要多少秒?"}], "metadata": {"teacher": "math", "domain": "math"}}
|
|
Binary file
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
# Model Merge:CPU TIES 三专家合并
|
|
2
|
+
|
|
3
|
+
Merge 将同底座专家的权重合成一个模型。本例使用数学、代码、指令三个专家,通过 TIES 筛选并合并相对底座的权重变化,再与底座进行评测对比。
|
|
4
|
+
|
|
5
|
+
本目录随 CLI 安装。用 `infix examples show merge -o text` 离线阅读,或用 `infix examples export merge --dir ./merge-demo` 导出配置和指南。后续命令在导出目录执行。
|
|
6
|
+
|
|
7
|
+
## 1. 准备底座与专家
|
|
8
|
+
|
|
9
|
+
首次使用时运行 `infix auth login`,在浏览器里确认比对码、选择工作空间并授权。Docker 沙箱或远程终端可加 `--no-browser`,用本机浏览器打开终端打印的链接。登录其他部署时加 `--api-url` 指定平台地址。已登录时可以直接用 `infix doctor` 检查连接。
|
|
10
|
+
|
|
11
|
+
```bash
|
|
12
|
+
infix auth login
|
|
13
|
+
infix doctor
|
|
14
|
+
infix asset model list --scope workspace
|
|
15
|
+
infix merge methods --method ties
|
|
16
|
+
infix resource list --task training
|
|
17
|
+
```
|
|
18
|
+
|
|
19
|
+
编辑 `merge.json`,替换所有 `REPLACE_WITH_*` 引用:
|
|
20
|
+
|
|
21
|
+
| 字段 | 填写内容 |
|
|
22
|
+
| --- | --- |
|
|
23
|
+
| `base_model` | 原始底座模型版本 |
|
|
24
|
+
| `expert_model[0]` | 从该底座训练的数学专家,对应 `expert_1` |
|
|
25
|
+
| `expert_model[1]` | 从该底座训练的代码专家,对应 `expert_2` |
|
|
26
|
+
| `expert_model[2]` | 从该底座训练的指令专家,对应 `expert_3` |
|
|
27
|
+
|
|
28
|
+
引用格式如 `workspace/my-base:v1.0.0`。底座与专家需要结构、tokenizer 和可信训练血缘兼容;名字都带 `it` 或参数量相同不足以证明兼容。平台会检查真实文件与血缘,手工修改描述无法替代认证。
|
|
29
|
+
|
|
30
|
+
`set.weights` 按专家顺序设置参与权重;`density` 控制保留的权重变化比例,`lambda` 控制合并变化的缩放,`normalize` 控制归一化。本例 `density=0.5`、`lambda=0.55` 仅作为实验起点。Merge 使用 CPU;配置省略 `hardware` 时使用平台默认资源。若需指定,在 JSON 顶层添加 `hardware`,填写 `resource list` 中可用的 CPU 规格;内存要能容纳所选模型。
|
|
31
|
+
|
|
32
|
+
## 2. 预检并创建 Merge
|
|
33
|
+
|
|
34
|
+
```bash
|
|
35
|
+
export MERGE_TASK="merge-demo-$(date +%Y%m%d-%H%M%S)-$RANDOM"
|
|
36
|
+
|
|
37
|
+
infix merge create --config merge.json --name "$MERGE_TASK" --dry-run
|
|
38
|
+
infix merge create --config merge.json --name "$MERGE_TASK" --wait --timeout 2h
|
|
39
|
+
infix merge get "$MERGE_TASK"
|
|
40
|
+
```
|
|
41
|
+
|
|
42
|
+
`--dry-run` 连接平台检查输入、算法参数和资源,不创建任务。用 `get` 的 `execution.status` 和 `stages` 查看执行和阶段状态,成功后可查看实际输出路径。失败时查看日志:
|
|
43
|
+
|
|
44
|
+
```bash
|
|
45
|
+
infix merge logs "$MERGE_TASK"
|
|
46
|
+
```
|
|
47
|
+
|
|
48
|
+
`--timeout` 和 Ctrl-C 只停止本地等待,远端任务继续。更换终端后,把 `MERGE_TASK` 重新设为已创建任务的名称,再查询或评测。
|
|
49
|
+
|
|
50
|
+
## 3. 与底座评测对比
|
|
51
|
+
|
|
52
|
+
以下示例要求底座和候选都支持原生聊天模板,并且当前平台可用 `official/IFEval`。把 `--baseline` 替换为配置中的实际底座:
|
|
53
|
+
|
|
54
|
+
```bash
|
|
55
|
+
export COMPARE_TASK="cmp-merge-$(date +%Y%m%d-%H%M%S)-$RANDOM"
|
|
56
|
+
|
|
57
|
+
infix evaluation compare \
|
|
58
|
+
--name "$COMPARE_TASK" \
|
|
59
|
+
--baseline workspace/REPLACE_WITH_BASE:v1.0.0 \
|
|
60
|
+
--candidate-from-merge "$MERGE_TASK" \
|
|
61
|
+
--dataset official/IFEval --eval-type official \
|
|
62
|
+
--chat-template model --max-parallel 1 --gpu-count 1 \
|
|
63
|
+
--wait --timeout 6h
|
|
64
|
+
|
|
65
|
+
infix evaluation compare-get "$COMPARE_TASK"
|
|
66
|
+
```
|
|
67
|
+
|
|
68
|
+
IFEval 衡量指令遵循;数学和代码能力应增加对应的独立评测集,可重复填写 `--dataset`。`--eval-type official` 要求数据资产绑定评测镜像支持的 benchmark,如 `gsm8k`、`humaneval_plus`;自定义资产显示名不一定是 benchmark 名。具体支持项以当前平台为准。
|
|
69
|
+
|
|
70
|
+
`--max-parallel 1` 表示最多同时运行一个评测子任务,每个子任务使用 `--gpu-count` 指定的 GPU。多个数据集会分别评测底座和候选。分数为空表示未成功得到结果;`partial_failed` 时查看失败子任务:
|
|
71
|
+
|
|
72
|
+
```bash
|
|
73
|
+
infix evaluation get REPLACE_WITH_FAILED_EVAL_TASK_ID
|
|
74
|
+
infix evaluation logs REPLACE_WITH_FAILED_EVAL_TASK_ID
|
|
75
|
+
```
|
|
76
|
+
|
|
77
|
+
基线和候选必须采用同一套模板协议。Gemma 2 IT 的原生模板不接受独立 system 消息,需要后端支持对应消息适配;升级后继续使用 `--chat-template model`。无原生聊天模板的模型可在平台支持时统一选择 `--chat-template plain`,并说明该实验采用纯文本协议。
|
|
78
|
+
|
|
79
|
+
复制多行命令时,续行符 `\` 必须是该行最后一个字符,后面不能有空格。出现 `Missing option '--eval-type'` 同时有 `zsh: command not found: --dataset`,通常是命令在数据集选项前意外断行。
|
|
80
|
+
|
|
81
|
+
## 4. 注册合并结果
|
|
82
|
+
|
|
83
|
+
评测满足要求后,将成功任务的产物复制为独立模型资产:
|
|
84
|
+
|
|
85
|
+
```bash
|
|
86
|
+
infix merge register "$MERGE_TASK" --name "model-merged-$(date +%Y%m%d-%H%M%S)" --version v1.0.0 --wait
|
|
87
|
+
```
|
|
88
|
+
|
|
89
|
+
资产 Ready 后可继续用于部署或后续任务。合并成功仅表示产物生成成功,最终效果需要看多个领域的评测结果。
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "merge-demo",
|
|
3
|
+
"visibility": "private",
|
|
4
|
+
"description": "CPU TIES 合并同底座的数学、代码、指令专家;运行前替换所有模型引用。",
|
|
5
|
+
"base_model": "workspace/REPLACE_WITH_BASE:v1.0.0",
|
|
6
|
+
"expert_model": [
|
|
7
|
+
"workspace/REPLACE_WITH_MATH_EXPERT:v1.0.0",
|
|
8
|
+
"workspace/REPLACE_WITH_CODE_EXPERT:v1.0.0",
|
|
9
|
+
"workspace/REPLACE_WITH_INSTRUCTION_EXPERT:v1.0.0"
|
|
10
|
+
],
|
|
11
|
+
"method": "ties",
|
|
12
|
+
"set": {
|
|
13
|
+
"weights": {
|
|
14
|
+
"expert_1": 1.0,
|
|
15
|
+
"expert_2": 1.0,
|
|
16
|
+
"expert_3": 1.0
|
|
17
|
+
},
|
|
18
|
+
"density": 0.5,
|
|
19
|
+
"lambda": 0.55,
|
|
20
|
+
"normalize": true,
|
|
21
|
+
"dtype": "bfloat16",
|
|
22
|
+
"seed": 42,
|
|
23
|
+
"num_threads": 8,
|
|
24
|
+
"out_shard_size": 1000000000
|
|
25
|
+
}
|
|
26
|
+
}
|
|
Binary file
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"""HTTP layer: authenticated client, pagination helpers."""
|