mind-recursive 0.1.0__tar.gz
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.
- mind_recursive-0.1.0/.gitattributes +3 -0
- mind_recursive-0.1.0/.github/workflows/publish-pypi.yml +78 -0
- mind_recursive-0.1.0/.github/workflows/release.yml +59 -0
- mind_recursive-0.1.0/.gitignore +15 -0
- mind_recursive-0.1.0/LICENSE +21 -0
- mind_recursive-0.1.0/PKG-INFO +69 -0
- mind_recursive-0.1.0/README.md +37 -0
- mind_recursive-0.1.0/docs/README.md +163 -0
- mind_recursive-0.1.0/docs/guide/README.md +20 -0
- mind_recursive-0.1.0/docs/guide/async.md +49 -0
- mind_recursive-0.1.0/docs/guide/checkpoints.md +156 -0
- mind_recursive-0.1.0/docs/guide/data.md +153 -0
- mind_recursive-0.1.0/docs/guide/futures-and-errors.md +112 -0
- mind_recursive-0.1.0/docs/guide/platform.md +242 -0
- mind_recursive-0.1.0/docs/guide/quickstart.md +122 -0
- mind_recursive-0.1.0/docs/guide/reporter.md +195 -0
- mind_recursive-0.1.0/docs/guide/sampler.md +235 -0
- mind_recursive-0.1.0/docs/guide/service-client.md +166 -0
- mind_recursive-0.1.0/docs/guide/tinker.md +193 -0
- mind_recursive-0.1.0/docs/guide/trainer.md +195 -0
- mind_recursive-0.1.0/docs/guide/user-client.md +85 -0
- mind_recursive-0.1.0/docs/reference/api.md +389 -0
- mind_recursive-0.1.0/mind_recursive/__init__.py +191 -0
- mind_recursive-0.1.0/mind_recursive/_config.py +317 -0
- mind_recursive-0.1.0/mind_recursive/_console.py +72 -0
- mind_recursive-0.1.0/mind_recursive/_errors.py +213 -0
- mind_recursive-0.1.0/mind_recursive/_futures.py +277 -0
- mind_recursive-0.1.0/mind_recursive/_proto/__init__.py +23 -0
- mind_recursive-0.1.0/mind_recursive/_proto/codec.py +154 -0
- mind_recursive-0.1.0/mind_recursive/_proto/decode.py +332 -0
- mind_recursive-0.1.0/mind_recursive/_proto/encode.py +163 -0
- mind_recursive-0.1.0/mind_recursive/_proto/schema.py +186 -0
- mind_recursive-0.1.0/mind_recursive/_protocol.py +316 -0
- mind_recursive-0.1.0/mind_recursive/_session.py +217 -0
- mind_recursive-0.1.0/mind_recursive/_transport.py +433 -0
- mind_recursive-0.1.0/mind_recursive/_version.py +26 -0
- mind_recursive-0.1.0/mind_recursive/platform.py +1648 -0
- mind_recursive-0.1.0/mind_recursive/reporter.py +335 -0
- mind_recursive-0.1.0/mind_recursive/sampler.py +406 -0
- mind_recursive-0.1.0/mind_recursive/service.py +1462 -0
- mind_recursive-0.1.0/mind_recursive/tinker.py +170 -0
- mind_recursive-0.1.0/mind_recursive/trainer.py +1178 -0
- mind_recursive-0.1.0/mind_recursive/types.py +640 -0
- mind_recursive-0.1.0/mind_recursive/user.py +289 -0
- mind_recursive-0.1.0/pyproject.toml +72 -0
- mind_recursive-0.1.0/recipes/00_smoke.py +116 -0
- mind_recursive-0.1.0/recipes/01_sft.py +273 -0
- mind_recursive-0.1.0/recipes/02_sft_full.py +311 -0
- mind_recursive-0.1.0/recipes/03_grpo.py +368 -0
- mind_recursive-0.1.0/recipes/04_samplers.py +112 -0
- mind_recursive-0.1.0/recipes/README.md +140 -0
- mind_recursive-0.1.0/recipes/_common.py +134 -0
- mind_recursive-0.1.0/recipes/_renderer.py +376 -0
- mind_recursive-0.1.0/recipes/data/sft_demo.jsonl +8 -0
- mind_recursive-0.1.0/tests/__init__.py +0 -0
- mind_recursive-0.1.0/tests/fake_relay.py +573 -0
- mind_recursive-0.1.0/tests/test_async.py +148 -0
- mind_recursive-0.1.0/tests/test_config.py +268 -0
- mind_recursive-0.1.0/tests/test_create_from_state.py +129 -0
- mind_recursive-0.1.0/tests/test_e2e_real_socket.py +146 -0
- mind_recursive-0.1.0/tests/test_platform.py +544 -0
- mind_recursive-0.1.0/tests/test_proto_golden.py +449 -0
- mind_recursive-0.1.0/tests/test_proto_roundtrip.py +241 -0
- mind_recursive-0.1.0/tests/test_public_api.py +241 -0
- mind_recursive-0.1.0/tests/test_recipe_renderer.py +420 -0
- mind_recursive-0.1.0/tests/test_recipes.py +476 -0
- mind_recursive-0.1.0/tests/test_reporter.py +332 -0
- mind_recursive-0.1.0/tests/test_sampling_logprobs.py +307 -0
- mind_recursive-0.1.0/tests/test_session_and_types.py +372 -0
- mind_recursive-0.1.0/tests/test_tinker_compat.py +265 -0
- mind_recursive-0.1.0/tests/test_training_loop.py +558 -0
- mind_recursive-0.1.0/tests/test_transport.py +270 -0
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
name: Publish to PyPI
|
|
2
|
+
|
|
3
|
+
on:
|
|
4
|
+
push:
|
|
5
|
+
tags:
|
|
6
|
+
- "v*"
|
|
7
|
+
workflow_dispatch:
|
|
8
|
+
inputs:
|
|
9
|
+
tag_name:
|
|
10
|
+
description: Tag to build and publish
|
|
11
|
+
required: true
|
|
12
|
+
type: string
|
|
13
|
+
|
|
14
|
+
permissions:
|
|
15
|
+
contents: read
|
|
16
|
+
id-token: write
|
|
17
|
+
|
|
18
|
+
jobs:
|
|
19
|
+
publish:
|
|
20
|
+
runs-on: self-hosted
|
|
21
|
+
environment: pypi
|
|
22
|
+
steps:
|
|
23
|
+
- name: Resolve target ref
|
|
24
|
+
id: ref
|
|
25
|
+
run: |
|
|
26
|
+
if [ "$GITHUB_EVENT_NAME" = "workflow_dispatch" ]; then
|
|
27
|
+
TAG_NAME="${{ inputs.tag_name }}"
|
|
28
|
+
else
|
|
29
|
+
TAG_NAME="${GITHUB_REF##refs/tags/}"
|
|
30
|
+
fi
|
|
31
|
+
echo "tag_name=$TAG_NAME" >> "$GITHUB_OUTPUT"
|
|
32
|
+
|
|
33
|
+
- name: Checkout tag
|
|
34
|
+
uses: actions/checkout@v7
|
|
35
|
+
with:
|
|
36
|
+
ref: refs/tags/${{ steps.ref.outputs.tag_name }}
|
|
37
|
+
|
|
38
|
+
- name: Install uv
|
|
39
|
+
uses: astral-sh/setup-uv@v7
|
|
40
|
+
|
|
41
|
+
- name: Verify version matches tag
|
|
42
|
+
run: |
|
|
43
|
+
TAG_VERSION="${{ steps.ref.outputs.tag_name }}"
|
|
44
|
+
TAG_VERSION="${TAG_VERSION#v}"
|
|
45
|
+
PKG_VERSION="$(python3 -c 'import tomllib; print(tomllib.load(open("pyproject.toml", "rb"))["project"]["version"])')"
|
|
46
|
+
echo "Tag version: $TAG_VERSION"
|
|
47
|
+
echo "pyproject.toml version: $PKG_VERSION"
|
|
48
|
+
if [ "$TAG_VERSION" != "$PKG_VERSION" ]; then
|
|
49
|
+
echo "::error::Tag version ($TAG_VERSION) does not match pyproject.toml version ($PKG_VERSION)"
|
|
50
|
+
exit 1
|
|
51
|
+
fi
|
|
52
|
+
|
|
53
|
+
- name: Run tests
|
|
54
|
+
run: |
|
|
55
|
+
uv sync --extra dev
|
|
56
|
+
uv run pytest -q
|
|
57
|
+
|
|
58
|
+
- name: Build distributions
|
|
59
|
+
run: |
|
|
60
|
+
rm -rf dist
|
|
61
|
+
uv build
|
|
62
|
+
|
|
63
|
+
- name: Smoke test built wheel
|
|
64
|
+
run: |
|
|
65
|
+
EXPECTED_VERSION="${{ steps.ref.outputs.tag_name }}"
|
|
66
|
+
EXPECTED_VERSION="${EXPECTED_VERSION#v}"
|
|
67
|
+
uv run --no-project --with dist/*.whl python -P -c "
|
|
68
|
+
import mind_recursive
|
|
69
|
+
from mind_recursive import tinker
|
|
70
|
+
assert 'site-packages' in mind_recursive.__file__, mind_recursive.__file__
|
|
71
|
+
assert mind_recursive.__version__ == '$EXPECTED_VERSION', mind_recursive.__version__
|
|
72
|
+
assert mind_recursive.SDK_VERSION == f'mind-recursive-python/$EXPECTED_VERSION', mind_recursive.SDK_VERSION
|
|
73
|
+
assert tinker.TrainingClient is mind_recursive.LoraTrainer
|
|
74
|
+
print('Smoke test OK:', mind_recursive.__version__, mind_recursive.SDK_VERSION, mind_recursive.__file__)
|
|
75
|
+
"
|
|
76
|
+
|
|
77
|
+
- name: Publish to PyPI
|
|
78
|
+
run: uv publish --trusted-publishing always
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
# GitHub Action workflow for automated releases via mindlab-bot
|
|
2
|
+
# Copy this file to .github/workflows/release.yml in your private repository
|
|
3
|
+
|
|
4
|
+
name: Release to Public
|
|
5
|
+
|
|
6
|
+
on:
|
|
7
|
+
push:
|
|
8
|
+
tags:
|
|
9
|
+
- 'v*'
|
|
10
|
+
workflow_dispatch:
|
|
11
|
+
inputs:
|
|
12
|
+
tag_name:
|
|
13
|
+
description: Tag to release
|
|
14
|
+
required: true
|
|
15
|
+
type: string
|
|
16
|
+
|
|
17
|
+
jobs:
|
|
18
|
+
release:
|
|
19
|
+
runs-on: self-hosted
|
|
20
|
+
steps:
|
|
21
|
+
- name: Extract repo name and tag
|
|
22
|
+
id: extract
|
|
23
|
+
run: |
|
|
24
|
+
# Extract repo name from GITHUB_REPOSITORY (e.g., MindLab-Research/mint-quickstart-alpha -> mint-quickstart)
|
|
25
|
+
REPO_NAME="${GITHUB_REPOSITORY##*/}"
|
|
26
|
+
REPO_NAME="${REPO_NAME%-alpha}"
|
|
27
|
+
echo "repo_name=$REPO_NAME" >> $GITHUB_OUTPUT
|
|
28
|
+
|
|
29
|
+
# For manual dispatch, use the explicit input tag. For push events, use the pushed tag ref.
|
|
30
|
+
if [ "$GITHUB_EVENT_NAME" = "workflow_dispatch" ]; then
|
|
31
|
+
TAG_NAME="${{ inputs.tag_name }}"
|
|
32
|
+
else
|
|
33
|
+
TAG_NAME="${GITHUB_REF##refs/tags/}"
|
|
34
|
+
fi
|
|
35
|
+
echo "tag_name=$TAG_NAME" >> $GITHUB_OUTPUT
|
|
36
|
+
|
|
37
|
+
- name: Define action directory
|
|
38
|
+
run: |
|
|
39
|
+
ACTION_ROOT="$HOME/.mindlab-bot-actions"
|
|
40
|
+
ACTION_DIR="$ACTION_ROOT/${GITHUB_RUN_ID}-${GITHUB_RUN_ATTEMPT}"
|
|
41
|
+
mkdir -p "$ACTION_ROOT"
|
|
42
|
+
echo "MINDLAB_BOT_ACTION_DIR=$ACTION_DIR" >> "$GITHUB_ENV"
|
|
43
|
+
|
|
44
|
+
- name: Clone mindlab-bot
|
|
45
|
+
run: |
|
|
46
|
+
rm -rf "$MINDLAB_BOT_ACTION_DIR"
|
|
47
|
+
gh repo clone MindLab-Research/mindlab-bot "$MINDLAB_BOT_ACTION_DIR"
|
|
48
|
+
|
|
49
|
+
- name: Run release
|
|
50
|
+
working-directory: ${{ env.MINDLAB_BOT_ACTION_DIR }}
|
|
51
|
+
# pi config (~/.pi/agent/models.json + settings.json) is inherited from the runner user environment.
|
|
52
|
+
run: |
|
|
53
|
+
pi --no-session -p \
|
|
54
|
+
"Use the release skill to publish repository ${{ steps.extract.outputs.repo_name }} at tag ${{ steps.extract.outputs.tag_name }}"
|
|
55
|
+
|
|
56
|
+
- name: Cleanup
|
|
57
|
+
if: always()
|
|
58
|
+
run: |
|
|
59
|
+
rm -rf "$MINDLAB_BOT_ACTION_DIR"
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2025 Mind Lab
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
Metadata-Version: 2.5
|
|
2
|
+
Name: mind-recursive
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: Python SDK for the Mind Recursive platform: custom training loops, managed training, deployment and inference
|
|
5
|
+
Project-URL: Homepage, https://macaron.im/mindlab
|
|
6
|
+
Project-URL: Repository, https://github.com/MindLab-Research/mind-recursive-sdk
|
|
7
|
+
Author: Mind Lab
|
|
8
|
+
License-Expression: MIT
|
|
9
|
+
License-File: LICENSE
|
|
10
|
+
Keywords: lora,mind-recursive,mindlab,mint,ml,reinforcement-learning,tinker,training
|
|
11
|
+
Classifier: Development Status :: 3 - Alpha
|
|
12
|
+
Classifier: Intended Audience :: Developers
|
|
13
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
14
|
+
Classifier: Programming Language :: Python :: 3
|
|
15
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
16
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
17
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
18
|
+
Requires-Python: >=3.11
|
|
19
|
+
Requires-Dist: httpx>=0.27
|
|
20
|
+
Requires-Dist: numpy>=1.24
|
|
21
|
+
Provides-Extra: dev
|
|
22
|
+
Requires-Dist: jinja2>=3.1; extra == 'dev'
|
|
23
|
+
Requires-Dist: pytest-asyncio>=0.23; extra == 'dev'
|
|
24
|
+
Requires-Dist: pytest>=8; extra == 'dev'
|
|
25
|
+
Requires-Dist: transformers>=4.40; extra == 'dev'
|
|
26
|
+
Provides-Extra: recipes
|
|
27
|
+
Requires-Dist: jinja2>=3.1; extra == 'recipes'
|
|
28
|
+
Requires-Dist: transformers>=4.40; extra == 'recipes'
|
|
29
|
+
Provides-Extra: zstd
|
|
30
|
+
Requires-Dist: zstandard>=0.22; extra == 'zstd'
|
|
31
|
+
Description-Content-Type: text/markdown
|
|
32
|
+
|
|
33
|
+
# MIND-RECURSIVE SDK
|
|
34
|
+
|
|
35
|
+
## 安装
|
|
36
|
+
|
|
37
|
+
```bash
|
|
38
|
+
# uv (PyPI)
|
|
39
|
+
uv add mind-recursive
|
|
40
|
+
|
|
41
|
+
# pip (PyPI)
|
|
42
|
+
pip install mind-recursive
|
|
43
|
+
```
|
|
44
|
+
|
|
45
|
+
也可以直接从 GitHub 公开仓安装(固定版本时把 `@main` 换成具体 tag,例如 `@v0.1.0`):
|
|
46
|
+
|
|
47
|
+
```bash
|
|
48
|
+
# uv
|
|
49
|
+
uv add git+https://github.com/MindLab-Research/mind-recursive-sdk@main
|
|
50
|
+
# pip
|
|
51
|
+
pip install git+https://github.com/MindLab-Research/mind-recursive-sdk@main
|
|
52
|
+
```
|
|
53
|
+
|
|
54
|
+
## 配置
|
|
55
|
+
|
|
56
|
+
```bash
|
|
57
|
+
export MIND_RECURSIVE_API_KEY=sk-...
|
|
58
|
+
export MIND_RECURSIVE_BASE_URL=https://<origin> # 可选
|
|
59
|
+
export MIND_RECURSIVE_WEB_URL=https://mintrecursive.mindlab.im/v2train/records/sessions/ # 可选
|
|
60
|
+
```
|
|
61
|
+
|
|
62
|
+
| 变量 | 作用 |
|
|
63
|
+
|---|---|
|
|
64
|
+
| `MIND_RECURSIVE_API_KEY` | 用户 key,`sk-` 开头 |
|
|
65
|
+
| `MIND_RECURSIVE_BASE_URL` | 服务 origin;可带 `/api/mindrsi/v1`,SDK 会归约 |
|
|
66
|
+
| `MIND_RECURSIVE_WEB_URL` | Web 控制台 session 链接前缀;只用于打印,不发请求 |
|
|
67
|
+
|
|
68
|
+
|
|
69
|
+
使用前阅读文档: [mind-recursive SDK 文档](https://github.com/MindLab-Research/mind-recursive-sdk/blob/main/docs/README.md)。
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
# MIND-RECURSIVE SDK
|
|
2
|
+
|
|
3
|
+
## 安装
|
|
4
|
+
|
|
5
|
+
```bash
|
|
6
|
+
# uv (PyPI)
|
|
7
|
+
uv add mind-recursive
|
|
8
|
+
|
|
9
|
+
# pip (PyPI)
|
|
10
|
+
pip install mind-recursive
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
也可以直接从 GitHub 公开仓安装(固定版本时把 `@main` 换成具体 tag,例如 `@v0.1.0`):
|
|
14
|
+
|
|
15
|
+
```bash
|
|
16
|
+
# uv
|
|
17
|
+
uv add git+https://github.com/MindLab-Research/mind-recursive-sdk@main
|
|
18
|
+
# pip
|
|
19
|
+
pip install git+https://github.com/MindLab-Research/mind-recursive-sdk@main
|
|
20
|
+
```
|
|
21
|
+
|
|
22
|
+
## 配置
|
|
23
|
+
|
|
24
|
+
```bash
|
|
25
|
+
export MIND_RECURSIVE_API_KEY=sk-...
|
|
26
|
+
export MIND_RECURSIVE_BASE_URL=https://<origin> # 可选
|
|
27
|
+
export MIND_RECURSIVE_WEB_URL=https://mintrecursive.mindlab.im/v2train/records/sessions/ # 可选
|
|
28
|
+
```
|
|
29
|
+
|
|
30
|
+
| 变量 | 作用 |
|
|
31
|
+
|---|---|
|
|
32
|
+
| `MIND_RECURSIVE_API_KEY` | 用户 key,`sk-` 开头 |
|
|
33
|
+
| `MIND_RECURSIVE_BASE_URL` | 服务 origin;可带 `/api/mindrsi/v1`,SDK 会归约 |
|
|
34
|
+
| `MIND_RECURSIVE_WEB_URL` | Web 控制台 session 链接前缀;只用于打印,不发请求 |
|
|
35
|
+
|
|
36
|
+
|
|
37
|
+
使用前阅读文档: [mind-recursive SDK 文档](https://github.com/MindLab-Research/mind-recursive-sdk/blob/main/docs/README.md)。
|
|
@@ -0,0 +1,163 @@
|
|
|
1
|
+
# mind_recursive 使用文档
|
|
2
|
+
|
|
3
|
+
## 安装
|
|
4
|
+
|
|
5
|
+
```bash
|
|
6
|
+
# uv (PyPI)
|
|
7
|
+
uv add mind-recursive
|
|
8
|
+
|
|
9
|
+
# pip (PyPI)
|
|
10
|
+
pip install mind-recursive
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
也可以直接从 GitHub 公开仓安装(固定版本时把 `@main` 换成具体 tag,例如 `@v0.1.0`):
|
|
14
|
+
|
|
15
|
+
```bash
|
|
16
|
+
# uv
|
|
17
|
+
uv add git+https://github.com/MindLab-Research/mind-recursive-sdk@main
|
|
18
|
+
# pip
|
|
19
|
+
pip install git+https://github.com/MindLab-Research/mind-recursive-sdk@main
|
|
20
|
+
```
|
|
21
|
+
|
|
22
|
+
可选 extras:
|
|
23
|
+
|
|
24
|
+
| extra | 用途 |
|
|
25
|
+
|---|---|
|
|
26
|
+
| `zstd` | 服务端要求压缩 `forward_backward` 请求体时使用;没装只会 warning 并发未压缩 body |
|
|
27
|
+
| `recipes` | 运行 `recipes/` 里的示例,需要 `transformers` 和 `jinja2` |
|
|
28
|
+
| `dev` | 开发与测试 |
|
|
29
|
+
|
|
30
|
+
## 配置
|
|
31
|
+
|
|
32
|
+
```bash
|
|
33
|
+
export MIND_RECURSIVE_API_KEY=sk-...
|
|
34
|
+
export MIND_RECURSIVE_BASE_URL=https://<origin> # 可选
|
|
35
|
+
export MIND_RECURSIVE_WEB_URL=https://mintrecursive.mindlab.im/v2train/records/sessions/ # 可选
|
|
36
|
+
```
|
|
37
|
+
|
|
38
|
+
| 变量 | 作用 |
|
|
39
|
+
|---|---|
|
|
40
|
+
| `MIND_RECURSIVE_API_KEY` | 用户 key,`sk-` 开头 |
|
|
41
|
+
| `MIND_RECURSIVE_BASE_URL` | 服务 origin;可带 `/api/mindrsi/v1`,SDK 会归约 |
|
|
42
|
+
| `MIND_RECURSIVE_WEB_URL` | Web 控制台 session 链接前缀;只用于打印,不发请求 |
|
|
43
|
+
|
|
44
|
+
API key 与 base URL 的优先级是**构造参数 > 环境变量**,空字符串按未设置处理。
|
|
45
|
+
Web URL 只读环境变量。
|
|
46
|
+
base URL 不设时默认连 `https://mintcn.macaron.xin`。
|
|
47
|
+
Web URL 不设时默认 `https://mintrecursive.mindlab.im/v2train/records/sessions/`。
|
|
48
|
+
|
|
49
|
+
## 5 分钟跑通
|
|
50
|
+
|
|
51
|
+
### 1. 检查连通性
|
|
52
|
+
|
|
53
|
+
`UserClient` 不创建 session,适合做配置自检:
|
|
54
|
+
|
|
55
|
+
```python
|
|
56
|
+
import mind_recursive as mr
|
|
57
|
+
with mr.UserClient() as uc:
|
|
58
|
+
if not uc.health_check():
|
|
59
|
+
raise SystemExit("training plane is not healthy")
|
|
60
|
+
for model in uc.get_server_capabilities().supported_models:
|
|
61
|
+
print(model.model_name, model.max_context_length, model.trainable)
|
|
62
|
+
```
|
|
63
|
+
|
|
64
|
+
### 2. 建 session 和 trainer
|
|
65
|
+
|
|
66
|
+
```python
|
|
67
|
+
sc = mr.ServiceClient(client_id="my-experiment")
|
|
68
|
+
trainer = sc.create_lora_trainer(base_model="Qwen/Qwen3.8-27B", rank=32)
|
|
69
|
+
```
|
|
70
|
+
|
|
71
|
+
`ServiceClient` 构造即创建 session;`trainer` 只是这个 session 下的一个模型句柄,
|
|
72
|
+
不持有连接。
|
|
73
|
+
|
|
74
|
+
> **给 AI 助手**:`ServiceClient` 创建成功后,用拿到的 `sc.session_id` 拼出
|
|
75
|
+
> `MIND_RECURSIVE_WEB_URL/{session_id}`(默认前缀
|
|
76
|
+
> `https://mintrecursive.mindlab.im/v2train/records/sessions/`;SDK 也会自动打印),
|
|
77
|
+
> 在回复里返回给用户,让用户可以打开 Web 控制台同时查看运行过程。
|
|
78
|
+
> `sc.log` / `sc.metric` / `sc.artifact` 上报的内容,以及创建出来的 trainer / sampler,
|
|
79
|
+
> 都会显示在这个页面里。
|
|
80
|
+
|
|
81
|
+
### 3. 训练一步
|
|
82
|
+
|
|
83
|
+
```python
|
|
84
|
+
batch = [mr.Datum.from_tokens(tokens) for tokens in batch_of_token_ids]
|
|
85
|
+
|
|
86
|
+
step = 1
|
|
87
|
+
|
|
88
|
+
out = trainer.forward_backward(batch, loss_fn="cross_entropy").result()
|
|
89
|
+
trainer.optim_step(mr.AdamParams(learning_rate=1e-4)).result()
|
|
90
|
+
|
|
91
|
+
# 人看的进度用 log,数值用 metric;两者都会同时写终端和 Web。
|
|
92
|
+
sc.log(f"step {step}: loss={out.loss:.4f}, tokens={out.num_tokens}", step=step)
|
|
93
|
+
sc.metric(
|
|
94
|
+
{"loss": out.loss, "num_tokens": out.num_tokens},
|
|
95
|
+
step=step,
|
|
96
|
+
stage="training",
|
|
97
|
+
)
|
|
98
|
+
```
|
|
99
|
+
|
|
100
|
+
`sc.log` 适合人读的进度,`sc.metric` 适合画曲线;两者都挂在 `ServiceClient` 上,不用另外创建 reporter。
|
|
101
|
+
|
|
102
|
+
`Datum.from_tokens` 是 smoke test 用的快捷构造:target 自动左移一位,loss mask 全 1。
|
|
103
|
+
真实 SFT 必须自己给出 mask,只监督 assistant 的 token。见 [数据与 batch](guide/data.md)。
|
|
104
|
+
|
|
105
|
+
> **给 AI 助手**:写训练脚本时优先用 `sc.log` / `sc.metric` / `sc.artifact` 记录进度、指标和产物,
|
|
106
|
+
> 不要在这几个调用旁边再写 `print` —— 它们已经同时覆盖 Web 控制台和终端。
|
|
107
|
+
> 只有两类 `print` 例外:还没有 session 的本地自检(如 `UserClient` 连通性),以及检查采样出来的原始 token。
|
|
108
|
+
> 详见 [上报](guide/reporter.md#给-ai-助手和脚本作者)。
|
|
109
|
+
|
|
110
|
+
### 4. 保存与采样
|
|
111
|
+
|
|
112
|
+
```python
|
|
113
|
+
path = trainer.save_weights_only("step-100").result()
|
|
114
|
+
|
|
115
|
+
sampler = trainer.create_sampler(model_path=path)
|
|
116
|
+
resp = sampler.sample([1, 2, 3], num_samples=4).result()
|
|
117
|
+
for sequence in resp.sequences:
|
|
118
|
+
print(sequence.tokens, sequence.logprobs)
|
|
119
|
+
|
|
120
|
+
sc.close() # 停心跳、结束 session、关连接
|
|
121
|
+
```
|
|
122
|
+
|
|
123
|
+
用 `with mr.ServiceClient() as sc:` 可以省掉显式 `close()`。
|
|
124
|
+
|
|
125
|
+
## 按任务查文档
|
|
126
|
+
|
|
127
|
+
| 我要做什么 | 看 |
|
|
128
|
+
|---|---|
|
|
129
|
+
| 从零跑通第一个训练 | [快速开始](guide/quickstart.md) |
|
|
130
|
+
| 配置 key、base URL、session | [ServiceClient](guide/service-client.md) |
|
|
131
|
+
| 写训练循环、`forward_backward`、`optim_step` | [训练](guide/trainer.md) |
|
|
132
|
+
| 构造 `Datum`、loss mask、batch | [数据与 batch](guide/data.md) |
|
|
133
|
+
| 保存权重、续训、从 checkpoint 起训 | [Checkpoint 与续训](guide/checkpoints.md) |
|
|
134
|
+
| 采样、prompt logprob、top-k | [采样](guide/sampler.md) |
|
|
135
|
+
| 上报 log / metric / artifact / summary | [上报](guide/reporter.md) |
|
|
136
|
+
| 查询模型列表和健康状态 | [UserClient](guide/user-client.md) |
|
|
137
|
+
| 理解 future、超时和异常 | [Future 与错误](guide/futures-and-errors.md) |
|
|
138
|
+
| 并发采样 / 异步训练循环 | [异步调用](guide/async.md) |
|
|
139
|
+
| 从 Tinker 代码迁移 | [Tinker 迁移](guide/tinker.md) |
|
|
140
|
+
| 查公开 API 的签名和返回类型 | [API 参考](reference/api.md) |
|
|
141
|
+
| 跑可修改的完整示例 | [recipes](../recipes/README.md) |
|
|
142
|
+
|
|
143
|
+
## 核心对象
|
|
144
|
+
|
|
145
|
+
| 对象 | 是什么 |
|
|
146
|
+
|---|---|
|
|
147
|
+
| `UserClient` | 用户级查询,无 session。`health_check()` / `get_server_capabilities()` |
|
|
148
|
+
| `ServiceClient` | 一个连接 + 一个 session。构造即创建 session |
|
|
149
|
+
| `LoraTrainer` | `sc.create_lora_trainer()` 创建的训练模型句柄 |
|
|
150
|
+
| `Sampler` | `sc.create_sampler()` 或 `trainer.create_sampler()` 创建的采样句柄 |
|
|
151
|
+
| `APIFuture` | 训练和采样调用的返回值,用 `.result()` 取结果 |
|
|
152
|
+
|
|
153
|
+
一个 `ServiceClient` 只有一份连接、一个 session 和一套计费归属;trainer / sampler
|
|
154
|
+
都没有 `close()`。`sc.close()` 是唯一需要的清理。
|
|
155
|
+
|
|
156
|
+
## 文档目录
|
|
157
|
+
|
|
158
|
+
```text
|
|
159
|
+
docs/
|
|
160
|
+
README.md 本页:安装、配置、快速开始、任务索引
|
|
161
|
+
guide/ 面向使用者的任务文档
|
|
162
|
+
reference/api.md 公开 API 签名与返回类型
|
|
163
|
+
```
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
# 使用指南
|
|
2
|
+
|
|
3
|
+
按任务选择:
|
|
4
|
+
|
|
5
|
+
| 文档 | 内容 |
|
|
6
|
+
|---|---|
|
|
7
|
+
| [快速开始](quickstart.md) | 从空环境跑通一次训练、保存和采样 |
|
|
8
|
+
| [ServiceClient](service-client.md) | 认证、base URL、session 生命周期 |
|
|
9
|
+
| [训练](trainer.md) | `forward_backward`、`optim_step`、Adam 参数、自动分块 |
|
|
10
|
+
| [数据与 batch](data.md) | `Datum`、`ModelInput`、`TensorData`、loss mask |
|
|
11
|
+
| [Checkpoint 与续训](checkpoints.md) | 两种 save、加载、从 checkpoint 起训 |
|
|
12
|
+
| [采样](sampler.md) | token 级采样、logprob、top-k、解码参数 |
|
|
13
|
+
| [上报](reporter.md) | log / event / metric / artifact / summary |
|
|
14
|
+
| [UserClient](user-client.md) | 无 session 的模型与健康查询 |
|
|
15
|
+
| [数据集、托管训练、部署与推理](platform.md) | `uc.datasets` / `uc.training` / `uc.models` / `uc.deployments` / `uc.chat.completions` |
|
|
16
|
+
| [Future 与错误](futures-and-errors.md) | `APIFuture`、超时、异常与重试 |
|
|
17
|
+
| [异步调用](async.md) | `*_async` 方法、并发采样、`await sc.aclose()` |
|
|
18
|
+
| [Tinker 迁移](tinker.md) | Tinker 拼写别名:已覆盖、未覆盖与行为差异 |
|
|
19
|
+
|
|
20
|
+
API 签名速查见 [reference/api.md](../reference/api.md)。
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
# 异步调用
|
|
2
|
+
|
|
3
|
+
SDK 同时提供同步和原生 async 两套调用方式,走同一组 HTTP 接口、同一套 future 协议;
|
|
4
|
+
后端不需要任何适配。
|
|
5
|
+
|
|
6
|
+
## 规则
|
|
7
|
+
|
|
8
|
+
- 同步方法直接返回结果或 `APIFuture`;`*_async` 方法返回 awaitable,`await` 后拿到最终结果。
|
|
9
|
+
- `ServiceClient` 的构造函数仍然是同步的(它要创建 session);之后所有训练、采样、上报查询都有 async 版本。
|
|
10
|
+
- 异步调用结束后用 `await sc.aclose()`,它会结束 session 并关闭 async / sync 两个连接池。
|
|
11
|
+
- 心跳仍在后台线程运行,不阻塞事件循环。
|
|
12
|
+
|
|
13
|
+
## 示例
|
|
14
|
+
|
|
15
|
+
```python
|
|
16
|
+
import asyncio
|
|
17
|
+
import mind_recursive as mr
|
|
18
|
+
async def main():
|
|
19
|
+
sc = mr.ServiceClient()
|
|
20
|
+
try:
|
|
21
|
+
trainer = await sc.create_lora_trainer_async(
|
|
22
|
+
base_model="Qwen/Qwen3.8-27B", rank=32
|
|
23
|
+
)
|
|
24
|
+
out = await trainer.forward_backward_async(batch)
|
|
25
|
+
await trainer.optim_step_async()
|
|
26
|
+
|
|
27
|
+
sampler = await trainer.save_weights_and_get_sampler_async("step-10")
|
|
28
|
+
|
|
29
|
+
# 并发采样:所有请求同时发出,事件循环负责等待。
|
|
30
|
+
results = await asyncio.gather(*[
|
|
31
|
+
sampler.sample_async(prompt) for prompt in prompts
|
|
32
|
+
])
|
|
33
|
+
return results
|
|
34
|
+
finally:
|
|
35
|
+
await sc.aclose()
|
|
36
|
+
|
|
37
|
+
asyncio.run(main())
|
|
38
|
+
```
|
|
39
|
+
|
|
40
|
+
## 覆盖范围
|
|
41
|
+
|
|
42
|
+
| 对象 | async 方法 |
|
|
43
|
+
|---|---|
|
|
44
|
+
| `ServiceClient` | `create_lora_trainer_async` / `create_lora_trainer_from_state_async` / `create_sampler_async` / `create_sampling_client_async` / `create_training_client_from_state(_with_optimizer)_async` / `get_server_capabilities_async` / `close_async` |
|
|
45
|
+
| `LoraTrainer` | `forward_async` / `forward_backward_async` / `optim_step_async` / `save_weights_only_async`(别名 `save_weights_for_sampler_async`)/ `save_state_async` / `load_weights_async` / `load_state_async` / `load_state_with_optimizer_async` / `get_info_async` / `create_sampler_async` / `create_sampling_client_async` / `save_weights_and_get_sampler_async` / `save_weights_and_get_sampling_client_async` |
|
|
46
|
+
| `Sampler` | `sample_async` / `compute_logprobs_async` / `get_base_model_async` |
|
|
47
|
+
| `UserClient` | `get_server_capabilities_async` / `health_check_async` / `close_async` |
|
|
48
|
+
|
|
49
|
+
自定义 loss(`forward_backward_custom`)仍不提供:那是服务端能力,不是 async 能解决的。
|
|
@@ -0,0 +1,156 @@
|
|
|
1
|
+
# Checkpoint 与续训
|
|
2
|
+
|
|
3
|
+
这一页讲四件事:保存什么、怎么加载、怎么从 checkpoint 起一个新的训练、以及续训时
|
|
4
|
+
选哪个入口。
|
|
5
|
+
|
|
6
|
+
## 两种保存
|
|
7
|
+
|
|
8
|
+
`LoraTrainer` 有两个公开的保存方法:
|
|
9
|
+
|
|
10
|
+
| 方法 | 保存内容 | 路径 | 用途 |
|
|
11
|
+
|---|---|---|---|
|
|
12
|
+
| `save_weights_only(name)` | 只有 LoRA 权重 | `mint://.../adapters/...` | 采样、部署 |
|
|
13
|
+
| `save_state(name)` | 权重 + 优化器状态 | `mint://.../checkpoints/...` | 续训 |
|
|
14
|
+
|
|
15
|
+
```python
|
|
16
|
+
weights_path = trainer.save_weights_only("step-100").result()
|
|
17
|
+
state_path = trainer.save_state("step-100").result()
|
|
18
|
+
```
|
|
19
|
+
|
|
20
|
+
两者的返回值都是 `APIFuture[str]`,`.result()` 得到路径。
|
|
21
|
+
|
|
22
|
+
命名规则:`name` 必须非空,只能包含 ASCII 字母、数字、`-`、`_`、`.`,且不能是
|
|
23
|
+
`.` 或 `..`。SDK 在本地校验,不合法会抛 `ConfigurationError`,不会发请求。
|
|
24
|
+
|
|
25
|
+
两者都接受 `overwrite=False`:同名保存默认报冲突(`ConflictError`),要覆盖必须
|
|
26
|
+
显式传 `overwrite=True`。
|
|
27
|
+
|
|
28
|
+
`save_weights_only` 不能用 `ephemeral` 前缀作名字。`save_weights_and_get_sampling_client()`
|
|
29
|
+
每步把临时导出存成 `ephemeral-<seq>`,所以这些名字是保留的,SDK 在本地直接拒绝,
|
|
30
|
+
抛 `ConfigurationError`。
|
|
31
|
+
|
|
32
|
+
两种保存的区别:
|
|
33
|
+
|
|
34
|
+
- **持久保存**:传 `name`(`save_weights_only` / `save_weights_and_get_sampler`),
|
|
35
|
+
想留下的权重走这条路。
|
|
36
|
+
- **临时保存**:`save_weights_and_get_sampling_client()`,不传 `name`。每步存一个
|
|
37
|
+
`ephemeral-<seq>`、24 小时后过期;推理服务要先部署这份权重才能采样,所以每步会建
|
|
38
|
+
一个临时部署,新部署就绪后释放上一个。适合 RL 每步采样。
|
|
39
|
+
|
|
40
|
+
保存成功后,路径会自动登记为 artifact:`save_weights_only` 登记
|
|
41
|
+
`sampler_weights`,`save_state` 登记 `checkpoint`。不需要再调用 `sc.artifact()`。
|
|
42
|
+
保存失败不会登记。
|
|
43
|
+
|
|
44
|
+
## 加载到当前模型
|
|
45
|
+
|
|
46
|
+
`load_weights(path, *, optimizer=True)` 把 checkpoint 加载进一个已经存在的模型:
|
|
47
|
+
|
|
48
|
+
```python
|
|
49
|
+
trainer.load_weights(state_path).result() # 权重 + 优化器
|
|
50
|
+
trainer.load_weights(weights_path, optimizer=False).result() # 只加载权重
|
|
51
|
+
```
|
|
52
|
+
|
|
53
|
+
`optimizer=True` 是默认值,用于续训;`optimizer=False` 用于只换权重、保留当前优化器
|
|
54
|
+
状态(例如回滚到某个权重快照)。
|
|
55
|
+
|
|
56
|
+
上游拼写的两个方法固定了 `optimizer`:
|
|
57
|
+
|
|
58
|
+
```python
|
|
59
|
+
trainer.load_state(path).result() # 只加载权重
|
|
60
|
+
trainer.load_state_with_optimizer(path).result() # 权重 + 优化器
|
|
61
|
+
```
|
|
62
|
+
|
|
63
|
+
`load_state` 不是 `load_weights` 的别名,它只加载权重。
|
|
64
|
+
|
|
65
|
+
## 从 checkpoint 起训
|
|
66
|
+
|
|
67
|
+
`create_lora_trainer_from_state` 在一次提交里创建模型并加载 checkpoint:
|
|
68
|
+
|
|
69
|
+
```python
|
|
70
|
+
trainer = sc.create_lora_trainer_from_state(
|
|
71
|
+
"mint://.../checkpoints/sft-step-500",
|
|
72
|
+
base_model="Qwen/Qwen3.8-27B",
|
|
73
|
+
)
|
|
74
|
+
```
|
|
75
|
+
|
|
76
|
+
不会再先随机初始化一份 adapter 再覆盖。
|
|
77
|
+
|
|
78
|
+
### 参数
|
|
79
|
+
|
|
80
|
+
| 参数 | 必填 | 说明 |
|
|
81
|
+
|---|---|---|
|
|
82
|
+
| `path` | 是 | `save_state` 返回的 `checkpoints/...` 路径 |
|
|
83
|
+
| `base_model` | 是 | 这次训练使用的 API 层模型名 |
|
|
84
|
+
| `rank` | 否 | 覆盖 checkpoint 的 rank |
|
|
85
|
+
| `train_mlp` | 否 | 覆盖 MLP 是否参与训练 |
|
|
86
|
+
| `train_attn` | 否 | 覆盖 attention 是否参与训练 |
|
|
87
|
+
| `load_optimizer` | 否 | `None` 跟随 checkpoint;`False` 只加载权重;`True` 要求 checkpoint 含优化器 |
|
|
88
|
+
| `user_metadata` | 否 | 记录在资源上的标签 |
|
|
89
|
+
|
|
90
|
+
不传的结构参数不会出现在请求里,由服务端从 checkpoint 解析:
|
|
91
|
+
|
|
92
|
+
```python
|
|
93
|
+
# 只覆盖 rank,其余沿用 checkpoint
|
|
94
|
+
trainer = sc.create_lora_trainer_from_state(
|
|
95
|
+
state_path,
|
|
96
|
+
base_model="Qwen/Qwen3.8-27B",
|
|
97
|
+
rank=16,
|
|
98
|
+
)
|
|
99
|
+
```
|
|
100
|
+
|
|
101
|
+
`trainer.lora_config` 只有在 `rank`、`train_mlp`、`train_attn` **三个都显式给出**
|
|
102
|
+
时才有值,否则是 `None`。effective rank 用:
|
|
103
|
+
|
|
104
|
+
```python
|
|
105
|
+
trainer.get_info().lora_rank
|
|
106
|
+
```
|
|
107
|
+
|
|
108
|
+
### 路径类型
|
|
109
|
+
|
|
110
|
+
`path` 必须是训练状态(`checkpoints/...`)。`save_weights_only` 产出的
|
|
111
|
+
`adapters/...` 不是训练状态,服务端会拒绝。SDK 不检查 `mint://` 前缀或路径形状,
|
|
112
|
+
只校验非空字符串;路径能否解析由服务端决定。
|
|
113
|
+
|
|
114
|
+
### base model 身份
|
|
115
|
+
|
|
116
|
+
`base_model` 必须是这个 checkpoint 对应的模型。当前服务端不会从 artifact 推断
|
|
117
|
+
`base_model`,SDK 也不做本地身份校验;传错时可能加载成功,所以续训时要自己保证
|
|
118
|
+
`base_model` 与保存 checkpoint 时一致。
|
|
119
|
+
|
|
120
|
+
## 两种续训方式怎么选
|
|
121
|
+
|
|
122
|
+
| 场景 | 用 |
|
|
123
|
+
|---|---|
|
|
124
|
+
| 新建一个模型,从 checkpoint 继续训练 | `sc.create_lora_trainer_from_state(path, base_model=...)` |
|
|
125
|
+
| 往一个已经存在的模型加载权重 / 回滚 / warm start | `trainer.load_weights(path, optimizer=...)` |
|
|
126
|
+
|
|
127
|
+
完整例子:
|
|
128
|
+
|
|
129
|
+
```python
|
|
130
|
+
with mr.ServiceClient() as sc:
|
|
131
|
+
# 第一次训练
|
|
132
|
+
first = sc.create_lora_trainer(base_model="Qwen/Qwen3.8-27B", rank=32)
|
|
133
|
+
...
|
|
134
|
+
state = first.save_state("step-500").result()
|
|
135
|
+
|
|
136
|
+
with mr.ServiceClient() as sc:
|
|
137
|
+
# 新进程续训:一次提交完成建模型 + 加载
|
|
138
|
+
resumed = sc.create_lora_trainer_from_state(
|
|
139
|
+
state,
|
|
140
|
+
base_model="Qwen/Qwen3.8-27B",
|
|
141
|
+
)
|
|
142
|
+
out = resumed.forward_backward(next_batch).result()
|
|
143
|
+
resumed.optim_step(mr.AdamParams(learning_rate=1e-4)).result()
|
|
144
|
+
```
|
|
145
|
+
|
|
146
|
+
如果只想在同一个模型上继续,不需要新建:
|
|
147
|
+
|
|
148
|
+
```python
|
|
149
|
+
trainer.load_state_with_optimizer(state).result()
|
|
150
|
+
```
|
|
151
|
+
|
|
152
|
+
## 相关文档
|
|
153
|
+
|
|
154
|
+
- [训练](trainer.md)
|
|
155
|
+
- [数据与 batch](data.md)
|
|
156
|
+
- [上报](reporter.md):保存成功后的 artifact 自动登记
|