renderers 0.1.7__tar.gz → 0.1.8.dev1__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.
- {renderers-0.1.7 → renderers-0.1.8.dev1}/.github/workflows/publish.yml +4 -15
- {renderers-0.1.7 → renderers-0.1.8.dev1}/.gitignore +2 -0
- renderers-0.1.8.dev1/LICENSE +201 -0
- {renderers-0.1.7 → renderers-0.1.8.dev1}/PKG-INFO +7 -1
- {renderers-0.1.7 → renderers-0.1.8.dev1}/README.md +4 -0
- {renderers-0.1.7 → renderers-0.1.8.dev1}/examples/README.md +18 -0
- renderers-0.1.8.dev1/examples/sglang/online_multiturn_sglang.py +255 -0
- {renderers-0.1.7 → renderers-0.1.8.dev1}/pyproject.toml +27 -2
- {renderers-0.1.7 → renderers-0.1.8.dev1}/renderers/__init__.py +15 -0
- renderers-0.1.8.dev1/renderers/_version.py +24 -0
- {renderers-0.1.7 → renderers-0.1.8.dev1}/renderers/base.py +87 -6
- {renderers-0.1.7 → renderers-0.1.8.dev1}/renderers/client.py +28 -8
- {renderers-0.1.7 → renderers-0.1.8.dev1}/renderers/deepseek_v3.py +6 -1
- {renderers-0.1.7 → renderers-0.1.8.dev1}/renderers/default.py +7 -2
- {renderers-0.1.7 → renderers-0.1.8.dev1}/renderers/glm45.py +7 -1
- {renderers-0.1.7 → renderers-0.1.8.dev1}/renderers/glm5.py +7 -1
- {renderers-0.1.7 → renderers-0.1.8.dev1}/renderers/gpt_oss.py +6 -1
- {renderers-0.1.7 → renderers-0.1.8.dev1}/renderers/kimi_k2.py +6 -1
- {renderers-0.1.7 → renderers-0.1.8.dev1}/renderers/kimi_k25.py +138 -45
- renderers-0.1.8.dev1/renderers/laguna_xs2.py +381 -0
- {renderers-0.1.7 → renderers-0.1.8.dev1}/renderers/minimax_m2.py +7 -1
- {renderers-0.1.7 → renderers-0.1.8.dev1}/renderers/nemotron3.py +6 -1
- {renderers-0.1.7 → renderers-0.1.8.dev1}/renderers/parsers.py +167 -51
- renderers-0.1.8.dev1/renderers/parsing.py +1266 -0
- {renderers-0.1.7 → renderers-0.1.8.dev1}/renderers/qwen3.py +6 -1
- {renderers-0.1.7 → renderers-0.1.8.dev1}/renderers/qwen35.py +56 -8
- {renderers-0.1.7 → renderers-0.1.8.dev1}/renderers/qwen3_vl.py +7 -2
- {renderers-0.1.7 → renderers-0.1.8.dev1}/tests/conftest.py +1 -0
- {renderers-0.1.7 → renderers-0.1.8.dev1}/tests/test_client.py +80 -29
- {renderers-0.1.7 → renderers-0.1.8.dev1}/tests/test_multimodal.py +169 -0
- renderers-0.1.8.dev1/tests/test_parse_response.py +137 -0
- {renderers-0.1.7 → renderers-0.1.8.dev1}/tests/test_parse_response_robustness.py +13 -7
- {renderers-0.1.7 → renderers-0.1.8.dev1}/tests/test_parsers.py +46 -8
- {renderers-0.1.7 → renderers-0.1.8.dev1}/tests/test_preserve_thinking.py +1 -0
- {renderers-0.1.7 → renderers-0.1.8.dev1}/tests/test_roundtrip.py +10 -15
- renderers-0.1.8.dev1/tests/test_tool_arg_type_preservation.py +139 -0
- renderers-0.1.7/renderers/parsing.py +0 -784
- renderers-0.1.7/tests/test_parse_response.py +0 -95
- {renderers-0.1.7 → renderers-0.1.8.dev1}/.github/workflows/style.yml +0 -0
- {renderers-0.1.7 → renderers-0.1.8.dev1}/.github/workflows/test.yml +0 -0
- {renderers-0.1.7 → renderers-0.1.8.dev1}/.pre-commit-config.yaml +0 -0
- {renderers-0.1.7 → renderers-0.1.8.dev1}/examples/sglang/multiturn_generate_sglang.py +0 -0
- {renderers-0.1.7 → renderers-0.1.8.dev1}/examples/tinker/multiturn_generate_tinker.py +0 -0
- {renderers-0.1.7 → renderers-0.1.8.dev1}/examples/transformers/multiturn_generate_transformers.py +0 -0
- {renderers-0.1.7 → renderers-0.1.8.dev1}/examples/vllm/multiturn_generate_vllm.py +0 -0
- {renderers-0.1.7 → renderers-0.1.8.dev1}/renderers/qwen36.py +0 -0
- {renderers-0.1.7 → renderers-0.1.8.dev1}/tests/test_bridge.py +0 -0
- {renderers-0.1.7 → renderers-0.1.8.dev1}/tests/test_build_helpers.py +0 -0
- {renderers-0.1.7 → renderers-0.1.8.dev1}/tests/test_gpt_oss_harmony_parity.py +0 -0
- {renderers-0.1.7 → renderers-0.1.8.dev1}/tests/test_incremental.py +0 -0
- {renderers-0.1.7 → renderers-0.1.8.dev1}/tests/test_load_tokenizer.py +0 -0
- {renderers-0.1.7 → renderers-0.1.8.dev1}/tests/test_message_indices.py +0 -0
- {renderers-0.1.7 → renderers-0.1.8.dev1}/tests/test_qwen35_size_coverage.py +0 -0
- {renderers-0.1.7 → renderers-0.1.8.dev1}/tests/test_render_ids.py +0 -0
- {renderers-0.1.7 → renderers-0.1.8.dev1}/uv.lock +0 -0
|
@@ -41,6 +41,10 @@ jobs:
|
|
|
41
41
|
TAG="$PUSHED_REF"
|
|
42
42
|
fi
|
|
43
43
|
|
|
44
|
+
# The package version is derived from this tag by hatch-vcs
|
|
45
|
+
# at build time (see [tool.hatch.version] in pyproject.toml).
|
|
46
|
+
# We only need to validate the tag shape — there's no
|
|
47
|
+
# ``project.version`` field to cross-check anymore.
|
|
44
48
|
case "$TAG" in
|
|
45
49
|
renderers-v*) ;;
|
|
46
50
|
*)
|
|
@@ -49,21 +53,6 @@ jobs:
|
|
|
49
53
|
;;
|
|
50
54
|
esac
|
|
51
55
|
|
|
52
|
-
VERSION="${TAG#renderers-v}"
|
|
53
|
-
FILE_VERSION=$(python - <<'PY'
|
|
54
|
-
import tomllib
|
|
55
|
-
from pathlib import Path
|
|
56
|
-
with Path('pyproject.toml').open('rb') as f:
|
|
57
|
-
data = tomllib.load(f)
|
|
58
|
-
print(data['project']['version'])
|
|
59
|
-
PY
|
|
60
|
-
)
|
|
61
|
-
|
|
62
|
-
if [ "$FILE_VERSION" != "$VERSION" ]; then
|
|
63
|
-
echo "Version mismatch: tag requests '$VERSION' but pyproject.toml defines '$FILE_VERSION'" >&2
|
|
64
|
-
exit 1
|
|
65
|
-
fi
|
|
66
|
-
|
|
67
56
|
echo "tag=$TAG" >> "$GITHUB_OUTPUT"
|
|
68
57
|
|
|
69
58
|
- uses: astral-sh/setup-uv@v7
|
|
@@ -0,0 +1,201 @@
|
|
|
1
|
+
Apache License
|
|
2
|
+
Version 2.0, January 2004
|
|
3
|
+
http://www.apache.org/licenses/
|
|
4
|
+
|
|
5
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
6
|
+
|
|
7
|
+
1. Definitions.
|
|
8
|
+
|
|
9
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
10
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
11
|
+
|
|
12
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
13
|
+
the copyright owner that is granting the License.
|
|
14
|
+
|
|
15
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
16
|
+
other entities that control, are controlled by, or are under common
|
|
17
|
+
control with that entity. For the purposes of this definition,
|
|
18
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
19
|
+
direction or management of such entity, whether by contract or
|
|
20
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
21
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
22
|
+
|
|
23
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
24
|
+
exercising permissions granted by this License.
|
|
25
|
+
|
|
26
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
27
|
+
including but not limited to software source code, documentation
|
|
28
|
+
source, and configuration files.
|
|
29
|
+
|
|
30
|
+
"Object" form shall mean any form resulting from mechanical
|
|
31
|
+
transformation or translation of a Source form, including but
|
|
32
|
+
not limited to compiled object code, generated documentation,
|
|
33
|
+
and conversions to other media types.
|
|
34
|
+
|
|
35
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
36
|
+
Object form, made available under the License, as indicated by a
|
|
37
|
+
copyright notice that is included in or attached to the work
|
|
38
|
+
(an example is provided in the Appendix below).
|
|
39
|
+
|
|
40
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
41
|
+
form, that is based on (or derived from) the Work and for which the
|
|
42
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
43
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
44
|
+
of this License, Derivative Works shall not include works that remain
|
|
45
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
46
|
+
the Work and Derivative Works thereof.
|
|
47
|
+
|
|
48
|
+
"Contribution" shall mean any work of authorship, including
|
|
49
|
+
the original version of the Work and any modifications or additions
|
|
50
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
51
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
52
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
53
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
54
|
+
means any form of electronic, verbal, or written communication sent
|
|
55
|
+
to the Licensor or its representatives, including but not limited to
|
|
56
|
+
communication on electronic mailing lists, source code control systems,
|
|
57
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
58
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
59
|
+
excluding communication that is conspicuously marked or otherwise
|
|
60
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
61
|
+
|
|
62
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
63
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
64
|
+
subsequently incorporated within the Work.
|
|
65
|
+
|
|
66
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
67
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
68
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
69
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
70
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
71
|
+
Work and such Derivative Works in Source or Object form.
|
|
72
|
+
|
|
73
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
74
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
75
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
76
|
+
(except as stated in this section) patent license to make, have made,
|
|
77
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
78
|
+
where such license applies only to those patent claims licensable
|
|
79
|
+
by such Contributor that are necessarily infringed by their
|
|
80
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
81
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
82
|
+
institute patent litigation against any entity (including a
|
|
83
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
84
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
85
|
+
or contributory patent infringement, then any patent licenses
|
|
86
|
+
granted to You under this License for that Work shall terminate
|
|
87
|
+
as of the date such litigation is filed.
|
|
88
|
+
|
|
89
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
90
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
91
|
+
modifications, and in Source or Object form, provided that You
|
|
92
|
+
meet the following conditions:
|
|
93
|
+
|
|
94
|
+
(a) You must give any other recipients of the Work or
|
|
95
|
+
Derivative Works a copy of this License; and
|
|
96
|
+
|
|
97
|
+
(b) You must cause any modified files to carry prominent notices
|
|
98
|
+
stating that You changed the files; and
|
|
99
|
+
|
|
100
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
101
|
+
that You distribute, all copyright, patent, trademark, and
|
|
102
|
+
attribution notices from the Source form of the Work,
|
|
103
|
+
excluding those notices that do not pertain to any part of
|
|
104
|
+
the Derivative Works; and
|
|
105
|
+
|
|
106
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
107
|
+
distribution, then any Derivative Works that You distribute must
|
|
108
|
+
include a readable copy of the attribution notices contained
|
|
109
|
+
within such NOTICE file, excluding those notices that do not
|
|
110
|
+
pertain to any part of the Derivative Works, in at least one
|
|
111
|
+
of the following places: within a NOTICE text file distributed
|
|
112
|
+
as part of the Derivative Works; within the Source form or
|
|
113
|
+
documentation, if provided along with the Derivative Works; or,
|
|
114
|
+
within a display generated by the Derivative Works, if and
|
|
115
|
+
wherever such third-party notices normally appear. The contents
|
|
116
|
+
of the NOTICE file are for informational purposes only and
|
|
117
|
+
do not modify the License. You may add Your own attribution
|
|
118
|
+
notices within Derivative Works that You distribute, alongside
|
|
119
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
120
|
+
that such additional attribution notices cannot be construed
|
|
121
|
+
as modifying the License.
|
|
122
|
+
|
|
123
|
+
You may add Your own copyright statement to Your modifications and
|
|
124
|
+
may provide additional or different license terms and conditions
|
|
125
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
126
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
127
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
128
|
+
the conditions stated in this License.
|
|
129
|
+
|
|
130
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
131
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
132
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
133
|
+
this License, without any additional terms or conditions.
|
|
134
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
135
|
+
the terms of any separate license agreement you may have executed
|
|
136
|
+
with Licensor regarding such Contributions.
|
|
137
|
+
|
|
138
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
139
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
140
|
+
except as required for describing the origin of the Work and
|
|
141
|
+
reproducing the content of the NOTICE file.
|
|
142
|
+
|
|
143
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
144
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
145
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
146
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
147
|
+
implied, including, without limitation, any warranties or conditions
|
|
148
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
149
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
150
|
+
appropriateness of using or redistributing the Work and assume any
|
|
151
|
+
risks associated with Your exercise of permissions under this License.
|
|
152
|
+
|
|
153
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
154
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
155
|
+
unless required by applicable law (such as deliberate and grossly
|
|
156
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
157
|
+
liable to You for damages, including any direct, indirect, special,
|
|
158
|
+
incidental, or consequential damages of any character arising as a
|
|
159
|
+
result of this License or out of the use or inability to use the
|
|
160
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
161
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
162
|
+
other commercial damages or losses), even if such Contributor
|
|
163
|
+
has been advised of the possibility of such damages.
|
|
164
|
+
|
|
165
|
+
9. Accepting Warranty or Support. While redistributing
|
|
166
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
167
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
168
|
+
or other liability obligations and/or rights consistent with this
|
|
169
|
+
License. However, in accepting such obligations, You may act only
|
|
170
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
171
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
172
|
+
defend, and hold each Contributor harmless for any liability
|
|
173
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
174
|
+
of your accepting any such warranty or support.
|
|
175
|
+
|
|
176
|
+
END OF TERMS AND CONDITIONS
|
|
177
|
+
|
|
178
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
179
|
+
|
|
180
|
+
To apply the Apache License to your work, attach the following
|
|
181
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
182
|
+
replaced with your own identifying information. (Don't include
|
|
183
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
184
|
+
comment syntax for the file format. We also recommend that a
|
|
185
|
+
file or class name and description of purpose be included on the
|
|
186
|
+
same "printed page" as the copyright notice for easier
|
|
187
|
+
identification within third-party archives.
|
|
188
|
+
|
|
189
|
+
Copyright 2026 Prime Intellect
|
|
190
|
+
|
|
191
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
192
|
+
you may not use this file except in compliance with the License.
|
|
193
|
+
You may obtain a copy of the License at
|
|
194
|
+
|
|
195
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
196
|
+
|
|
197
|
+
Unless required by applicable law or agreed to in writing, software
|
|
198
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
199
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
200
|
+
See the License for the specific language governing permissions and
|
|
201
|
+
limitations under the License.
|
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: renderers
|
|
3
|
-
Version: 0.1.
|
|
3
|
+
Version: 0.1.8.dev1
|
|
4
4
|
Summary: Chat template renderers — deterministic message-to-token conversion for LLM training
|
|
5
|
+
License-Expression: Apache-2.0
|
|
6
|
+
License-File: LICENSE
|
|
5
7
|
Requires-Python: <3.14,>=3.10
|
|
6
8
|
Requires-Dist: jinja2
|
|
7
9
|
Requires-Dist: numpy
|
|
@@ -154,3 +156,7 @@ uv run pytest
|
|
|
154
156
|
```
|
|
155
157
|
|
|
156
158
|
Round-trip parity (render → parse → original) and token-level parity against `apply_chat_template` are tested per renderer. End-to-end validation runs against Reverse-Text, Wordle, OpenCode-Math, and RLM-SWE environments.
|
|
159
|
+
|
|
160
|
+
## License
|
|
161
|
+
|
|
162
|
+
Licensed under the [Apache License, Version 2.0](LICENSE).
|
|
@@ -141,3 +141,7 @@ uv run pytest
|
|
|
141
141
|
```
|
|
142
142
|
|
|
143
143
|
Round-trip parity (render → parse → original) and token-level parity against `apply_chat_template` are tested per renderer. End-to-end validation runs against Reverse-Text, Wordle, OpenCode-Math, and RLM-SWE environments.
|
|
144
|
+
|
|
145
|
+
## License
|
|
146
|
+
|
|
147
|
+
Licensed under the [Apache License, Version 2.0](LICENSE).
|
|
@@ -31,6 +31,24 @@ CUDA_VISIBLE_DEVICES=1 uv run --script examples/sglang/multiturn_generate_sglang
|
|
|
31
31
|
The SGLang script uses `input_ids`, so SGLang does not apply a chat template.
|
|
32
32
|
It leaves `openai-harmony` at SGLang's pinned version for dependency resolution.
|
|
33
33
|
|
|
34
|
+
### SGLang HTTP Recipe (online)
|
|
35
|
+
|
|
36
|
+
For a token-in/token-out HTTP path against an already-running SGLang server:
|
|
37
|
+
|
|
38
|
+
```bash
|
|
39
|
+
sglang serve --model-path Qwen/Qwen3.5-4B \
|
|
40
|
+
--host 0.0.0.0 --port 30000 --tensor-parallel-size 1 --trust-remote-code &
|
|
41
|
+
|
|
42
|
+
uv run python examples/sglang/online_multiturn_sglang.py \
|
|
43
|
+
--base-url http://localhost:30000 --model Qwen/Qwen3.5-4B
|
|
44
|
+
```
|
|
45
|
+
|
|
46
|
+
The HTTP recipe posts `input_ids` to `/generate`; streaming is intentionally
|
|
47
|
+
unsupported because `parse_response`/`bridge_to_next_turn` require the full
|
|
48
|
+
completion. The source-checkout command above uses the local `renderers`
|
|
49
|
+
package; the PEP 723 `uv run --script` form requires a published package that
|
|
50
|
+
satisfies the script header.
|
|
51
|
+
|
|
34
52
|
## Transformers Multi-Turn Recipe
|
|
35
53
|
|
|
36
54
|
```bash
|
|
@@ -0,0 +1,255 @@
|
|
|
1
|
+
#!/usr/bin/env -S uv run --script
|
|
2
|
+
# /// script
|
|
3
|
+
# requires-python = ">=3.10,<3.14"
|
|
4
|
+
# dependencies = [
|
|
5
|
+
# "renderers>=0.1.6",
|
|
6
|
+
# "transformers>=5.3.0",
|
|
7
|
+
# "httpx>=0.27",
|
|
8
|
+
# "openai-harmony==0.0.4",
|
|
9
|
+
# "tiktoken",
|
|
10
|
+
# "jinja2",
|
|
11
|
+
# "numpy",
|
|
12
|
+
# ]
|
|
13
|
+
# ///
|
|
14
|
+
"""SGLang online generation from renderer-owned prompt token IDs.
|
|
15
|
+
|
|
16
|
+
Mirrors `multiturn_generate_sglang.py` but talks to an already-running SGLang
|
|
17
|
+
HTTP server over `/generate` instead of an in-process `sgl.Engine`. The
|
|
18
|
+
renderer owns chat templating and parsing; SGLang only does token-in,
|
|
19
|
+
token-out.
|
|
20
|
+
|
|
21
|
+
Streaming is intentionally not supported: `parse_response` and
|
|
22
|
+
`bridge_to_next_turn` both need the complete `completion_ids`.
|
|
23
|
+
|
|
24
|
+
Launch a server first, e.g.
|
|
25
|
+
|
|
26
|
+
sglang serve --model-path Qwen/Qwen3.5-4B \\
|
|
27
|
+
--host 0.0.0.0 --port 30000 --tensor-parallel-size 1 --trust-remote-code
|
|
28
|
+
|
|
29
|
+
then, from a source checkout,
|
|
30
|
+
|
|
31
|
+
uv run python examples/sglang/online_multiturn_sglang.py \\
|
|
32
|
+
--base-url http://localhost:30000 --model Qwen/Qwen3.5-4B
|
|
33
|
+
|
|
34
|
+
The PEP 723 `uv run --script` form requires a published `renderers` package
|
|
35
|
+
that satisfies the script header.
|
|
36
|
+
"""
|
|
37
|
+
|
|
38
|
+
from __future__ import annotations
|
|
39
|
+
|
|
40
|
+
import argparse
|
|
41
|
+
import asyncio
|
|
42
|
+
import json
|
|
43
|
+
from typing import Any
|
|
44
|
+
|
|
45
|
+
import httpx
|
|
46
|
+
from renderers.base import Renderer
|
|
47
|
+
from renderers.gpt_oss import GptOssRenderer
|
|
48
|
+
from renderers.qwen35 import Qwen35Renderer
|
|
49
|
+
from transformers import AutoTokenizer
|
|
50
|
+
|
|
51
|
+
|
|
52
|
+
TOOLS = [
|
|
53
|
+
{
|
|
54
|
+
"type": "function",
|
|
55
|
+
"function": {
|
|
56
|
+
"name": "multiply",
|
|
57
|
+
"description": "Multiply two integers.",
|
|
58
|
+
"parameters": {
|
|
59
|
+
"type": "object",
|
|
60
|
+
"properties": {
|
|
61
|
+
"a": {"type": "integer"},
|
|
62
|
+
"b": {"type": "integer"},
|
|
63
|
+
},
|
|
64
|
+
"required": ["a", "b"],
|
|
65
|
+
},
|
|
66
|
+
},
|
|
67
|
+
}
|
|
68
|
+
]
|
|
69
|
+
|
|
70
|
+
|
|
71
|
+
def make_renderer(model: str, enable_thinking: bool | None) -> Renderer:
|
|
72
|
+
tokenizer = AutoTokenizer.from_pretrained(model, trust_remote_code=False)
|
|
73
|
+
if model.startswith("Qwen/Qwen3.5-"):
|
|
74
|
+
return Qwen35Renderer(tokenizer, enable_thinking=enable_thinking)
|
|
75
|
+
if model == "openai/gpt-oss-20b":
|
|
76
|
+
return GptOssRenderer(tokenizer)
|
|
77
|
+
raise ValueError(f"unsupported demo model: {model}")
|
|
78
|
+
|
|
79
|
+
|
|
80
|
+
def completion_ids(output: dict, prompt_ids: list[int]) -> list[int]:
|
|
81
|
+
ids = list(output.get("output_ids") or output.get("token_ids") or [])
|
|
82
|
+
if not ids:
|
|
83
|
+
raise RuntimeError("SGLang did not return completion token IDs")
|
|
84
|
+
# Match offline recipe: strip prefix only if SGLang echoed the prompt back.
|
|
85
|
+
return ids[len(prompt_ids) :] if ids[: len(prompt_ids)] == prompt_ids else ids
|
|
86
|
+
|
|
87
|
+
|
|
88
|
+
async def generate_sglang(
|
|
89
|
+
*,
|
|
90
|
+
client: httpx.AsyncClient,
|
|
91
|
+
base_url: str,
|
|
92
|
+
renderer: Renderer,
|
|
93
|
+
prompt_ids: list[int],
|
|
94
|
+
max_new_tokens: int,
|
|
95
|
+
extra_key: str | None = None,
|
|
96
|
+
) -> dict[str, Any]:
|
|
97
|
+
body: dict[str, Any] = {
|
|
98
|
+
"input_ids": prompt_ids,
|
|
99
|
+
"sampling_params": {
|
|
100
|
+
"temperature": 0.0,
|
|
101
|
+
"max_new_tokens": max_new_tokens,
|
|
102
|
+
"stop_token_ids": renderer.get_stop_token_ids(),
|
|
103
|
+
"skip_special_tokens": False,
|
|
104
|
+
"no_stop_trim": True,
|
|
105
|
+
},
|
|
106
|
+
"stream": False,
|
|
107
|
+
}
|
|
108
|
+
if extra_key is not None:
|
|
109
|
+
body["extra_key"] = extra_key
|
|
110
|
+
response = await client.post(f"{base_url.rstrip('/')}/generate", json=body)
|
|
111
|
+
response.raise_for_status()
|
|
112
|
+
return response.json()
|
|
113
|
+
|
|
114
|
+
|
|
115
|
+
def print_parsed(label: str, turn: str, parsed) -> None:
|
|
116
|
+
print(f"\n[{label}] {turn}")
|
|
117
|
+
if parsed.reasoning_content:
|
|
118
|
+
print(f"reasoning: {parsed.reasoning_content[:240]}")
|
|
119
|
+
if parsed.tool_calls:
|
|
120
|
+
print(f"tool_calls: {json.dumps(parsed.tool_calls, ensure_ascii=False)}")
|
|
121
|
+
if parsed.content:
|
|
122
|
+
print(f"content: {parsed.content}")
|
|
123
|
+
|
|
124
|
+
|
|
125
|
+
async def run_one(
|
|
126
|
+
*,
|
|
127
|
+
client: httpx.AsyncClient,
|
|
128
|
+
base_url: str,
|
|
129
|
+
model: str,
|
|
130
|
+
enable_thinking: bool | None,
|
|
131
|
+
max_new_tokens: int,
|
|
132
|
+
) -> None:
|
|
133
|
+
label = (
|
|
134
|
+
model
|
|
135
|
+
if enable_thinking is None
|
|
136
|
+
else f"{model} enable_thinking={enable_thinking}"
|
|
137
|
+
)
|
|
138
|
+
print(f"\n=== {label} ===")
|
|
139
|
+
|
|
140
|
+
renderer = make_renderer(model, enable_thinking)
|
|
141
|
+
|
|
142
|
+
messages: list[dict[str, Any]] = [
|
|
143
|
+
{"role": "system", "content": "You are a concise tool-using assistant."},
|
|
144
|
+
{
|
|
145
|
+
"role": "user",
|
|
146
|
+
"content": "Use the multiply tool for 17 * 23, then summarize.",
|
|
147
|
+
},
|
|
148
|
+
]
|
|
149
|
+
|
|
150
|
+
# Turn 1: render locally, send token IDs. SGLang never sees messages.
|
|
151
|
+
prompt_ids = renderer.render_ids(messages, tools=TOOLS, add_generation_prompt=True)
|
|
152
|
+
output1 = await generate_sglang(
|
|
153
|
+
client=client,
|
|
154
|
+
base_url=base_url,
|
|
155
|
+
renderer=renderer,
|
|
156
|
+
prompt_ids=prompt_ids,
|
|
157
|
+
max_new_tokens=max_new_tokens,
|
|
158
|
+
)
|
|
159
|
+
completion1 = completion_ids(output1, prompt_ids)
|
|
160
|
+
parsed1 = renderer.parse_response(completion1)
|
|
161
|
+
print_parsed(label, "turn 1", parsed1)
|
|
162
|
+
|
|
163
|
+
assistant: dict[str, Any] = {"role": "assistant", "content": parsed1.content}
|
|
164
|
+
if parsed1.reasoning_content:
|
|
165
|
+
assistant["reasoning_content"] = parsed1.reasoning_content
|
|
166
|
+
if parsed1.tool_calls:
|
|
167
|
+
assistant["tool_calls"] = parsed1.tool_calls
|
|
168
|
+
messages.append(assistant)
|
|
169
|
+
|
|
170
|
+
if parsed1.tool_calls:
|
|
171
|
+
new_messages: list[dict[str, Any]] = []
|
|
172
|
+
for idx, tool_call in enumerate(parsed1.tool_calls):
|
|
173
|
+
fn = tool_call.get("function") or tool_call
|
|
174
|
+
tool_args = fn.get("arguments") or {}
|
|
175
|
+
if isinstance(tool_args, str):
|
|
176
|
+
tool_args = json.loads(tool_args)
|
|
177
|
+
new_messages.append(
|
|
178
|
+
{
|
|
179
|
+
"role": "tool",
|
|
180
|
+
"tool_call_id": tool_call.get("id", f"call_{idx}"),
|
|
181
|
+
"name": fn.get("name", "multiply"),
|
|
182
|
+
"content": json.dumps(
|
|
183
|
+
{"result": int(tool_args["a"]) * int(tool_args["b"])}
|
|
184
|
+
),
|
|
185
|
+
}
|
|
186
|
+
)
|
|
187
|
+
else:
|
|
188
|
+
new_messages = [
|
|
189
|
+
{"role": "user", "content": "Give the final answer in one sentence."}
|
|
190
|
+
]
|
|
191
|
+
|
|
192
|
+
# Turn 2: bridge extends prompt_ids + completion1 exactly.
|
|
193
|
+
bridged_ids = renderer.bridge_to_next_turn(
|
|
194
|
+
prompt_ids, completion1, new_messages, tools=TOOLS
|
|
195
|
+
)
|
|
196
|
+
if bridged_ids is None:
|
|
197
|
+
raise RuntimeError("bridge_to_next_turn returned None")
|
|
198
|
+
assert bridged_ids[: len(prompt_ids) + len(completion1)] == (
|
|
199
|
+
prompt_ids + completion1
|
|
200
|
+
)
|
|
201
|
+
|
|
202
|
+
output2 = await generate_sglang(
|
|
203
|
+
client=client,
|
|
204
|
+
base_url=base_url,
|
|
205
|
+
renderer=renderer,
|
|
206
|
+
prompt_ids=bridged_ids,
|
|
207
|
+
max_new_tokens=max_new_tokens,
|
|
208
|
+
)
|
|
209
|
+
completion2 = completion_ids(output2, bridged_ids)
|
|
210
|
+
print_parsed(label, "turn 2", renderer.parse_response(completion2))
|
|
211
|
+
|
|
212
|
+
|
|
213
|
+
async def main() -> None:
|
|
214
|
+
parser = argparse.ArgumentParser()
|
|
215
|
+
parser.add_argument(
|
|
216
|
+
"--base-url",
|
|
217
|
+
default="http://localhost:30000",
|
|
218
|
+
help="SGLang HTTP server base URL.",
|
|
219
|
+
)
|
|
220
|
+
parser.add_argument(
|
|
221
|
+
"--model",
|
|
222
|
+
default="Qwen/Qwen3.5-4B",
|
|
223
|
+
help="Must match the model the SGLang server is serving.",
|
|
224
|
+
)
|
|
225
|
+
parser.add_argument(
|
|
226
|
+
"--enable-thinking",
|
|
227
|
+
choices=["true", "false", "both"],
|
|
228
|
+
default="both",
|
|
229
|
+
help="Qwen3.5 thinking mode. Ignored for gpt-oss.",
|
|
230
|
+
)
|
|
231
|
+
parser.add_argument("--max-new-tokens", type=int, default=512)
|
|
232
|
+
parser.add_argument("--timeout", type=float, default=600.0)
|
|
233
|
+
args = parser.parse_args()
|
|
234
|
+
|
|
235
|
+
if args.model.startswith("Qwen/Qwen3.5-"):
|
|
236
|
+
if args.enable_thinking == "both":
|
|
237
|
+
modes: list[bool | None] = [True, False]
|
|
238
|
+
else:
|
|
239
|
+
modes = [args.enable_thinking == "true"]
|
|
240
|
+
else:
|
|
241
|
+
modes = [None]
|
|
242
|
+
|
|
243
|
+
async with httpx.AsyncClient(timeout=args.timeout) as client:
|
|
244
|
+
for mode in modes:
|
|
245
|
+
await run_one(
|
|
246
|
+
client=client,
|
|
247
|
+
base_url=args.base_url,
|
|
248
|
+
model=args.model,
|
|
249
|
+
enable_thinking=mode,
|
|
250
|
+
max_new_tokens=args.max_new_tokens,
|
|
251
|
+
)
|
|
252
|
+
|
|
253
|
+
|
|
254
|
+
if __name__ == "__main__":
|
|
255
|
+
asyncio.run(main())
|
|
@@ -1,12 +1,18 @@
|
|
|
1
1
|
[build-system]
|
|
2
|
-
requires = ["hatchling"]
|
|
2
|
+
requires = ["hatchling", "hatch-vcs"]
|
|
3
3
|
build-backend = "hatchling.build"
|
|
4
4
|
|
|
5
5
|
[project]
|
|
6
6
|
name = "renderers"
|
|
7
|
-
|
|
7
|
+
# Derived from git tags by hatch-vcs (see [tool.hatch.version] below).
|
|
8
|
+
# Untagged commits get PEP 440 dev versions like ``0.1.8.dev3+g4c877be4``
|
|
9
|
+
# so any commit is uniquely installable; tagged commits get clean
|
|
10
|
+
# release versions like ``0.1.8``.
|
|
11
|
+
dynamic = ["version"]
|
|
8
12
|
description = "Chat template renderers — deterministic message-to-token conversion for LLM training"
|
|
9
13
|
readme = "README.md"
|
|
14
|
+
license = "Apache-2.0"
|
|
15
|
+
license-files = ["LICENSE"]
|
|
10
16
|
requires-python = ">=3.10,<3.14"
|
|
11
17
|
dependencies = [
|
|
12
18
|
"numpy",
|
|
@@ -20,6 +26,25 @@ dependencies = [
|
|
|
20
26
|
"openai-harmony>=0.0.8",
|
|
21
27
|
]
|
|
22
28
|
|
|
29
|
+
[tool.hatch.version]
|
|
30
|
+
source = "vcs"
|
|
31
|
+
# Tags look like ``renderers-v0.1.8`` (prefix matches the publish.yml
|
|
32
|
+
# release contract); strip the prefix to get a PEP 440 version. The
|
|
33
|
+
# regex accepts any PEP 440-valid suffix after the prefix so we can
|
|
34
|
+
# tag pre-releases like ``renderers-v0.2.0rc1`` later if needed.
|
|
35
|
+
tag-pattern = '^renderers-v(?P<version>.+)$'
|
|
36
|
+
# Used when building from a context without VCS metadata (e.g. an
|
|
37
|
+
# sdist consumed by a downstream that doesn't ship .git). Real
|
|
38
|
+
# builds from a checkout get the resolved version; this fallback
|
|
39
|
+
# only fires when the resolver has nothing to go on.
|
|
40
|
+
fallback-version = "0.0.0"
|
|
41
|
+
|
|
42
|
+
[tool.hatch.build.hooks.vcs]
|
|
43
|
+
# Write the resolved version to a Python file so it can be inspected
|
|
44
|
+
# at runtime via ``renderers.__version__`` without re-parsing the
|
|
45
|
+
# wheel metadata.
|
|
46
|
+
version-file = "renderers/_version.py"
|
|
47
|
+
|
|
23
48
|
[tool.hatch.build.targets.wheel]
|
|
24
49
|
packages = ["renderers"]
|
|
25
50
|
|
|
@@ -1,3 +1,11 @@
|
|
|
1
|
+
try:
|
|
2
|
+
from renderers._version import __version__
|
|
3
|
+
except ImportError:
|
|
4
|
+
# Source checkout without a built artifact (e.g. editable install
|
|
5
|
+
# before the first ``uv build`` populates ``_version.py``). Real
|
|
6
|
+
# installs always have it.
|
|
7
|
+
__version__ = "0+unknown"
|
|
8
|
+
|
|
1
9
|
from renderers.base import (
|
|
2
10
|
Content,
|
|
3
11
|
ContentPart,
|
|
@@ -7,6 +15,7 @@ from renderers.base import (
|
|
|
7
15
|
MultiModalData,
|
|
8
16
|
MultimodalRenderer,
|
|
9
17
|
ParsedResponse,
|
|
18
|
+
ParsedToolCall,
|
|
10
19
|
PlaceholderRange,
|
|
11
20
|
RenderedConversation,
|
|
12
21
|
RenderedTokens,
|
|
@@ -16,6 +25,7 @@ from renderers.base import (
|
|
|
16
25
|
ThinkingPart,
|
|
17
26
|
ToolCall,
|
|
18
27
|
ToolCallFunction,
|
|
28
|
+
ToolCallParseStatus,
|
|
19
29
|
ToolSpec,
|
|
20
30
|
VideoPart,
|
|
21
31
|
build_training_sample,
|
|
@@ -33,6 +43,7 @@ from renderers.glm45 import GLM45Renderer
|
|
|
33
43
|
from renderers.gpt_oss import GptOssRenderer
|
|
34
44
|
from renderers.kimi_k2 import KimiK2Renderer
|
|
35
45
|
from renderers.kimi_k25 import KimiK25Renderer
|
|
46
|
+
from renderers.laguna_xs2 import LagunaXS2Renderer
|
|
36
47
|
from renderers.minimax_m2 import MiniMaxM2Renderer
|
|
37
48
|
from renderers.nemotron3 import Nemotron3Renderer
|
|
38
49
|
from renderers.qwen3 import Qwen3Renderer
|
|
@@ -51,6 +62,7 @@ __all__ = [
|
|
|
51
62
|
"ImagePart",
|
|
52
63
|
"KimiK2Renderer",
|
|
53
64
|
"KimiK25Renderer",
|
|
65
|
+
"LagunaXS2Renderer",
|
|
54
66
|
"MULTIMODAL_MODELS",
|
|
55
67
|
"Message",
|
|
56
68
|
"MiniMaxM2Renderer",
|
|
@@ -58,6 +70,7 @@ __all__ = [
|
|
|
58
70
|
"MultimodalRenderer",
|
|
59
71
|
"Nemotron3Renderer",
|
|
60
72
|
"ParsedResponse",
|
|
73
|
+
"ParsedToolCall",
|
|
61
74
|
"PlaceholderRange",
|
|
62
75
|
"Qwen3Renderer",
|
|
63
76
|
"Qwen3VLRenderer",
|
|
@@ -71,8 +84,10 @@ __all__ = [
|
|
|
71
84
|
"ThinkingPart",
|
|
72
85
|
"ToolCall",
|
|
73
86
|
"ToolCallFunction",
|
|
87
|
+
"ToolCallParseStatus",
|
|
74
88
|
"ToolSpec",
|
|
75
89
|
"VideoPart",
|
|
90
|
+
"__version__",
|
|
76
91
|
"build_training_sample",
|
|
77
92
|
"build_trajectory_step",
|
|
78
93
|
"create_renderer",
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
# file generated by vcs-versioning
|
|
2
|
+
# don't change, don't track in version control
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
__all__ = [
|
|
6
|
+
"__version__",
|
|
7
|
+
"__version_tuple__",
|
|
8
|
+
"version",
|
|
9
|
+
"version_tuple",
|
|
10
|
+
"__commit_id__",
|
|
11
|
+
"commit_id",
|
|
12
|
+
]
|
|
13
|
+
|
|
14
|
+
version: str
|
|
15
|
+
__version__: str
|
|
16
|
+
__version_tuple__: tuple[int | str, ...]
|
|
17
|
+
version_tuple: tuple[int | str, ...]
|
|
18
|
+
commit_id: str | None
|
|
19
|
+
__commit_id__: str | None
|
|
20
|
+
|
|
21
|
+
__version__ = version = '0.1.8.dev1'
|
|
22
|
+
__version_tuple__ = version_tuple = (0, 1, 8, 'dev1')
|
|
23
|
+
|
|
24
|
+
__commit_id__ = commit_id = None
|