sophon-realtime 1.0.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.
@@ -0,0 +1,202 @@
1
+
2
+ Apache License
3
+ Version 2.0, January 2004
4
+ http://www.apache.org/licenses/
5
+
6
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
7
+
8
+ 1. Definitions.
9
+
10
+ "License" shall mean the terms and conditions for use, reproduction,
11
+ and distribution as defined by Sections 1 through 9 of this document.
12
+
13
+ "Licensor" shall mean the copyright owner or entity authorized by
14
+ the copyright owner that is granting the License.
15
+
16
+ "Legal Entity" shall mean the union of the acting entity and all
17
+ other entities that control, are controlled by, or are under common
18
+ control with that entity. For the purposes of this definition,
19
+ "control" means (i) the power, direct or indirect, to cause the
20
+ direction or management of such entity, whether by contract or
21
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
22
+ outstanding shares, or (iii) beneficial ownership of such entity.
23
+
24
+ "You" (or "Your") shall mean an individual or Legal Entity
25
+ exercising permissions granted by this License.
26
+
27
+ "Source" form shall mean the preferred form for making modifications,
28
+ including but not limited to software source code, documentation
29
+ source, and configuration files.
30
+
31
+ "Object" form shall mean any form resulting from mechanical
32
+ transformation or translation of a Source form, including but
33
+ not limited to compiled object code, generated documentation,
34
+ and conversions to other media types.
35
+
36
+ "Work" shall mean the work of authorship, whether in Source or
37
+ Object form, made available under the License, as indicated by a
38
+ copyright notice that is included in or attached to the work
39
+ (an example is provided in the Appendix below).
40
+
41
+ "Derivative Works" shall mean any work, whether in Source or Object
42
+ form, that is based on (or derived from) the Work and for which the
43
+ editorial revisions, annotations, elaborations, or other modifications
44
+ represent, as a whole, an original work of authorship. For the purposes
45
+ of this License, Derivative Works shall not include works that remain
46
+ separable from, or merely link (or bind by name) to the interfaces of,
47
+ the Work and Derivative Works thereof.
48
+
49
+ "Contribution" shall mean any work of authorship, including
50
+ the original version of the Work and any modifications or additions
51
+ to that Work or Derivative Works thereof, that is intentionally
52
+ submitted to Licensor for inclusion in the Work by the copyright owner
53
+ or by an individual or Legal Entity authorized to submit on behalf of
54
+ the copyright owner. For the purposes of this definition, "submitted"
55
+ means any form of electronic, verbal, or written communication sent
56
+ to the Licensor or its representatives, including but not limited to
57
+ communication on electronic mailing lists, source code control systems,
58
+ and issue tracking systems that are managed by, or on behalf of, the
59
+ Licensor for the purpose of discussing and improving the Work, but
60
+ excluding communication that is conspicuously marked or otherwise
61
+ designated in writing by the copyright owner as "Not a Contribution."
62
+
63
+ "Contributor" shall mean Licensor and any individual or Legal Entity
64
+ on behalf of whom a Contribution has been received by Licensor and
65
+ subsequently incorporated within the Work.
66
+
67
+ 2. Grant of Copyright License. Subject to the terms and conditions of
68
+ this License, each Contributor hereby grants to You a perpetual,
69
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
70
+ copyright license to reproduce, prepare Derivative Works of,
71
+ publicly display, publicly perform, sublicense, and distribute the
72
+ Work and such Derivative Works in Source or Object form.
73
+
74
+ 3. Grant of Patent License. Subject to the terms and conditions of
75
+ this License, each Contributor hereby grants to You a perpetual,
76
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
77
+ (except as stated in this section) patent license to make, have made,
78
+ use, offer to sell, sell, import, and otherwise transfer the Work,
79
+ where such license applies only to those patent claims licensable
80
+ by such Contributor that are necessarily infringed by their
81
+ Contribution(s) alone or by combination of their Contribution(s)
82
+ with the Work to which such Contribution(s) was submitted. If You
83
+ institute patent litigation against any entity (including a
84
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
85
+ or a Contribution incorporated within the Work constitutes direct
86
+ or contributory patent infringement, then any patent licenses
87
+ granted to You under this License for that Work shall terminate
88
+ as of the date such litigation is filed.
89
+
90
+ 4. Redistribution. You may reproduce and distribute copies of the
91
+ Work or Derivative Works thereof in any medium, with or without
92
+ modifications, and in Source or Object form, provided that You
93
+ meet the following conditions:
94
+
95
+ (a) You must give any other recipients of the Work or
96
+ Derivative Works a copy of this License; and
97
+
98
+ (b) You must cause any modified files to carry prominent notices
99
+ stating that You changed the files; and
100
+
101
+ (c) You must retain, in the Source form of any Derivative Works
102
+ that You distribute, all copyright, patent, trademark, and
103
+ attribution notices from the Source form of the Work,
104
+ excluding those notices that do not pertain to any part of
105
+ the Derivative Works; and
106
+
107
+ (d) If the Work includes a "NOTICE" text file as part of its
108
+ distribution, then any Derivative Works that You distribute must
109
+ include a readable copy of the attribution notices contained
110
+ within such NOTICE file, excluding those notices that do not
111
+ pertain to any part of the Derivative Works, in at least one
112
+ of the following places: within a NOTICE text file distributed
113
+ as part of the Derivative Works; within the Source form or
114
+ documentation, if provided along with the Derivative Works; or,
115
+ within a display generated by the Derivative Works, if and
116
+ wherever such third-party notices normally appear. The contents
117
+ of the NOTICE file are for informational purposes only and
118
+ do not modify the License. You may add Your own attribution
119
+ notices within Derivative Works that You distribute, alongside
120
+ or as an addendum to the NOTICE text from the Work, provided
121
+ that such additional attribution notices cannot be construed
122
+ as modifying the License.
123
+
124
+ You may add Your own copyright statement to Your modifications and
125
+ may provide additional or different license terms and conditions
126
+ for use, reproduction, or distribution of Your modifications, or
127
+ for any such Derivative Works as a whole, provided Your use,
128
+ reproduction, and distribution of the Work otherwise complies with
129
+ the conditions stated in this License.
130
+
131
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
132
+ any Contribution intentionally submitted for inclusion in the Work
133
+ by You to the Licensor shall be under the terms and conditions of
134
+ this License, without any additional terms or conditions.
135
+ Notwithstanding the above, nothing herein shall supersede or modify
136
+ the terms of any separate license agreement you may have executed
137
+ with Licensor regarding such Contributions.
138
+
139
+ 6. Trademarks. This License does not grant permission to use the trade
140
+ names, trademarks, service marks, or product names of the Licensor,
141
+ except as required for reasonable and customary use in describing the
142
+ origin of the Work and reproducing the content of the NOTICE file.
143
+
144
+ 7. Disclaimer of Warranty. Unless required by applicable law or
145
+ agreed to in writing, Licensor provides the Work (and each
146
+ Contributor provides its Contributions) on an "AS IS" BASIS,
147
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
148
+ implied, including, without limitation, any warranties or conditions
149
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
150
+ PARTICULAR PURPOSE. You are solely responsible for determining the
151
+ appropriateness of using or redistributing the Work and assume any
152
+ risks associated with Your exercise of permissions under this License.
153
+
154
+ 8. Limitation of Liability. In no event and under no legal theory,
155
+ whether in tort (including negligence), contract, or otherwise,
156
+ unless required by applicable law (such as deliberate and grossly
157
+ negligent acts) or agreed to in writing, shall any Contributor be
158
+ liable to You for damages, including any direct, indirect, special,
159
+ incidental, or consequential damages of any character arising as a
160
+ result of this License or out of the use or inability to use the
161
+ Work (including but not limited to damages for loss of goodwill,
162
+ work stoppage, computer failure or malfunction, or any and all
163
+ other commercial damages or losses), even if such Contributor
164
+ has been advised of the possibility of such damages.
165
+
166
+ 9. Accepting Warranty or Additional Liability. While redistributing
167
+ the Work or Derivative Works thereof, You may choose to offer,
168
+ and charge a fee for, acceptance of support, warranty, indemnity,
169
+ or other liability obligations and/or rights consistent with this
170
+ License. However, in accepting such obligations, You may act only
171
+ on Your own behalf and on Your sole responsibility, not on behalf
172
+ of any other Contributor, and only if You agree to indemnify,
173
+ defend, and hold each Contributor harmless for any liability
174
+ incurred by, or claims asserted against, such Contributor by reason
175
+ of your accepting any such warranty or additional liability.
176
+
177
+ END OF TERMS AND CONDITIONS
178
+
179
+ APPENDIX: How to apply the Apache License to your work.
180
+
181
+ To apply the Apache License to your work, attach the following
182
+ boilerplate notice, with the fields enclosed by brackets "[]"
183
+ replaced with your own identifying information. (Don't include
184
+ the brackets!) The text should be enclosed in the appropriate
185
+ comment syntax for the file format. We also recommend that a
186
+ file or class name and description of purpose be included on the
187
+ same "printed page" as the copyright notice for easier
188
+ identification within third-party archives.
189
+
190
+ Copyright [yyyy] [name of copyright owner]
191
+
192
+ Licensed under the Apache License, Version 2.0 (the "License");
193
+ you may not use this file except in compliance with the License.
194
+ You may obtain a copy of the License at
195
+
196
+ http://www.apache.org/licenses/LICENSE-2.0
197
+
198
+ Unless required by applicable law or agreed to in writing, software
199
+ distributed under the License is distributed on an "AS IS" BASIS,
200
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
201
+ See the License for the specific language governing permissions and
202
+ limitations under the License.
@@ -0,0 +1,9 @@
1
+ Copyright 2026 Adventists.ai.
2
+
3
+ Sophon-Realtime-32B-Tag bundles model weights derived from the following works, each licensed under the Apache License 2.0:
4
+ - thinker/: derived from Qwen3-VL-32B-Instruct by the Qwen team, Alibaba (https://huggingface.co/Qwen/Qwen3-VL-32B-Instruct),
5
+ via DuplexJev-32B-Para (Adventists.ai) with a merged tag-writing adapter; quantized to FP8. Its audio encoder is derived from
6
+ Qwen3-ASR (Qwen team, Alibaba, Apache License 2.0).
7
+ - talker/: tag-tts (Adventists.ai), derived from Fun-CosyVoice3-0.5B by the FunAudioLLM team, Alibaba
8
+ (https://github.com/FunAudioLLM/CosyVoice); the language model was fine-tuned to perform sound tags, the flow model was
9
+ distilled to 4 steps, and the HiFT vocoder is redistributed unchanged.
@@ -0,0 +1,38 @@
1
+ Metadata-Version: 2.4
2
+ Name: sophon-realtime
3
+ Version: 1.0.0
4
+ Summary: Sophon-Realtime v1: open full-duplex voice model that hears your tone and speaks with one (Tag build, one GPU, vLLM-Omni)
5
+ Author: Adventists AI
6
+ License-Expression: Apache-2.0
7
+ Project-URL: Homepage, https://github.com/adventists-ai/sophon-realtime
8
+ Project-URL: ModelScope, https://www.modelscope.cn/models/AdventistsAI/Sophon-Realtime-v1
9
+ Project-URL: Hugging Face, https://huggingface.co/adventists-ai/Sophon-Realtime-32B-Tag
10
+ Requires-Python: >=3.10
11
+ Description-Content-Type: text/markdown
12
+ License-File: LICENSE
13
+ License-File: NOTICE
14
+ Requires-Dist: vllm==0.30.0
15
+ Requires-Dist: vllm-omni==0.30.0
16
+ Requires-Dist: duplexjev-vllm==0.3.0
17
+ Requires-Dist: modelscope
18
+ Provides-Extra: trt
19
+ Requires-Dist: tensorrt-cu13==10.13.3.9; extra == "trt"
20
+ Dynamic: license-file
21
+
22
+ # sophon-realtime
23
+
24
+ **Sophon-Realtime v1**: an open full-duplex voice model that hears your tone and speaks with one. This package installs the recommended **Tag** build as a vLLM-Omni plugin, plus a small command line to download and serve it on one 80 GB GPU.
25
+
26
+ ```bash
27
+ pip install sophon-realtime # Python 3.12, Linux, CUDA; installs vLLM 0.30 + vLLM-Omni 0.30
28
+ sophon-realtime serve # downloads Sophon-Realtime-32B-Tag (~42 GB) on first run, then serves on port 8000
29
+ ```
30
+
31
+ - Full duplex: `ws://HOST:8000/v1/realtime` (turn-taking, barge-in, back-channels; OpenAI-Realtime-style)
32
+ - `POST /v1/chat/completions` (audio in, text + audio out)
33
+ - Options: `--port`, `--gpu`, `--model DIR`, `--source modelscope|hf`; `sophon-realtime download` only downloads.
34
+ - Optional TensorRT for faster speech: `pip install "sophon-realtime[trt]"`.
35
+
36
+ VoiceBench 82.8 and Big Bench Audio 81.8% (#1 among open full-duplex models), #1 in paralinguistic understanding, NVV-SuperBench 0.86 (zh) / 0.80 (en). Client examples, the Flash build, Live mode (OpenAI GPT-Live compatible) and fine-tuning: https://github.com/adventists-ai/sophon-realtime
37
+
38
+ Apache-2.0. Third-party notices: NOTICE.
@@ -0,0 +1,17 @@
1
+ # sophon-realtime
2
+
3
+ **Sophon-Realtime v1**: an open full-duplex voice model that hears your tone and speaks with one. This package installs the recommended **Tag** build as a vLLM-Omni plugin, plus a small command line to download and serve it on one 80 GB GPU.
4
+
5
+ ```bash
6
+ pip install sophon-realtime # Python 3.12, Linux, CUDA; installs vLLM 0.30 + vLLM-Omni 0.30
7
+ sophon-realtime serve # downloads Sophon-Realtime-32B-Tag (~42 GB) on first run, then serves on port 8000
8
+ ```
9
+
10
+ - Full duplex: `ws://HOST:8000/v1/realtime` (turn-taking, barge-in, back-channels; OpenAI-Realtime-style)
11
+ - `POST /v1/chat/completions` (audio in, text + audio out)
12
+ - Options: `--port`, `--gpu`, `--model DIR`, `--source modelscope|hf`; `sophon-realtime download` only downloads.
13
+ - Optional TensorRT for faster speech: `pip install "sophon-realtime[trt]"`.
14
+
15
+ VoiceBench 82.8 and Big Bench Audio 81.8% (#1 among open full-duplex models), #1 in paralinguistic understanding, NVV-SuperBench 0.86 (zh) / 0.80 (en). Client examples, the Flash build, Live mode (OpenAI GPT-Live compatible) and fine-tuning: https://github.com/adventists-ai/sophon-realtime
16
+
17
+ Apache-2.0. Third-party notices: NOTICE.
@@ -0,0 +1,36 @@
1
+ [build-system]
2
+ requires = ["setuptools>=61"]
3
+ build-backend = "setuptools.build_meta"
4
+
5
+ [project]
6
+ name = "sophon-realtime"
7
+ version = "1.0.0"
8
+ description = "Sophon-Realtime v1: open full-duplex voice model that hears your tone and speaks with one (Tag build, one GPU, vLLM-Omni)"
9
+ readme = "README.md"
10
+ requires-python = ">=3.10"
11
+ license = "Apache-2.0"
12
+ authors = [{name = "Adventists AI"}]
13
+ dependencies = ["vllm==0.30.0", "vllm-omni==0.30.0", "duplexjev-vllm==0.3.0", "modelscope"]
14
+
15
+ [project.optional-dependencies]
16
+ trt = ["tensorrt-cu13==10.13.3.9"]
17
+
18
+ [project.urls]
19
+ Homepage = "https://github.com/adventists-ai/sophon-realtime"
20
+ ModelScope = "https://www.modelscope.cn/models/AdventistsAI/Sophon-Realtime-v1"
21
+ "Hugging Face" = "https://huggingface.co/adventists-ai/Sophon-Realtime-32B-Tag"
22
+
23
+ [project.scripts]
24
+ sophon-realtime = "sophon_realtime.cli:main"
25
+
26
+ [project.entry-points."vllm_omni.general_plugins"]
27
+ sophon_realtime = "sophon_realtime:register"
28
+
29
+ [project.entry-points."vllm.general_plugins"]
30
+ sophon_realtime = "sophon_realtime:register"
31
+
32
+ [tool.setuptools.packages.find]
33
+ include = ["sophon_realtime*"]
34
+
35
+ [tool.setuptools.package-data]
36
+ sophon_realtime = ["deploy/*.yaml", "deploy/*.onnx", "deploy/*.json"]
@@ -0,0 +1,4 @@
1
+ [egg_info]
2
+ tag_build =
3
+ tag_date = 0
4
+
@@ -0,0 +1,53 @@
1
+ """Sophon-Realtime-32B-Tag: DuplexJev (listen + write, with sound tags) -> tag-tts talker (CosyVoice3 LM, text streamed in
2
+ bistream style while it is written) -> CosyVoice3 flow + HiFT, served as one vLLM-Omni model.
3
+
4
+ vllm serve <Sophon-Realtime-32B-Tag dir> --omni --deploy-config <sophon_realtime_tag_1gpu.yaml>
5
+ """
6
+ __version__ = "1.0.0"
7
+ ARCH = "SophonRealtimeForConditionalGeneration"
8
+ TALKER_ARCH = "SophonTagTalker"
9
+ _done = False
10
+
11
+
12
+ def register():
13
+ global _done
14
+ if _done:
15
+ return
16
+ _done = True
17
+ from transformers import AutoConfig
18
+ from .config import SophonRealtimeConfig
19
+ try:
20
+ AutoConfig.register(SophonRealtimeConfig.model_type, SophonRealtimeConfig)
21
+ except ValueError:
22
+ pass
23
+ try:
24
+ from vllm_omni.transformers_utils.configs.cosyvoice3 import CosyVoice3Config
25
+ AutoConfig.register("cosyvoice3", CosyVoice3Config)
26
+ except Exception: # noqa: BLE001 already registered by vllm-omni
27
+ pass
28
+ try: # the talker re-emits the voice prompt (embed.*): keep the latest instead of concatenating per step
29
+ from vllm_omni.outputs.output_modality import TensorAccumulationStrategy, register_key_accumulation_strategy
30
+ for k in ("embed.speech_token", "embed.speech_feat", "embed.embedding", "embed.speech_token_len"):
31
+ register_key_accumulation_strategy(k, TensorAccumulationStrategy.REPLACE)
32
+ except Exception: # noqa: BLE001
33
+ pass
34
+ try:
35
+ import duplexjev_vllm
36
+ duplexjev_vllm.register()
37
+ except Exception: # noqa: BLE001
38
+ pass
39
+ from vllm import ModelRegistry
40
+ if TALKER_ARCH not in ModelRegistry.get_supported_archs():
41
+ ModelRegistry.register_model(TALKER_ARCH, "sophon_realtime.talker_tag:SophonTagTalker")
42
+ try:
43
+ from vllm.model_executor.models.registry import _LazyRegisteredModel
44
+ from vllm_omni.model_executor.models.registry import OmniModelRegistry
45
+ OmniModelRegistry.models.setdefault(TALKER_ARCH, _LazyRegisteredModel(module_name="sophon_realtime.talker_tag", class_name="SophonTagTalker"))
46
+ OmniModelRegistry.models.setdefault("DuplexJevForConditionalGeneration", _LazyRegisteredModel(module_name="duplexjev_vllm.model", class_name="DuplexJevForConditionalGeneration"))
47
+ OmniModelRegistry.models.setdefault("DuplexJevVisionForConditionalGeneration", _LazyRegisteredModel(module_name="duplexjev_vllm.vision_model", class_name="DuplexJevVisionForConditionalGeneration"))
48
+ from vllm_omni.config.pipeline_registry import OMNI_PIPELINES, register_pipeline
49
+ from .pipeline import SOPHON_REALTIME_PIPELINE
50
+ if SOPHON_REALTIME_PIPELINE.model_type not in OMNI_PIPELINES:
51
+ register_pipeline(SOPHON_REALTIME_PIPELINE)
52
+ except ImportError:
53
+ pass
@@ -0,0 +1,79 @@
1
+ """Client tool bridge: lets a gateway outside the serving process see the model's tool calls and hand back results.
2
+
3
+ Engine-agnostic contract (the same two calls are implemented by every engine adapter):
4
+ GET /bridge/<key>/events?wait=<s> -> {"events": [{"type": "tool_call", "call_id", "name", "arguments"}]} (long poll)
5
+ POST /bridge/<key>/result <- {"call_id": str|null, "output": str, "speak": bool}
6
+ <key> is the session's extra_body.bridge_key. Enabled when SOPHON_BRIDGE_PORT is set; binds 127.0.0.1 only."""
7
+ from __future__ import annotations
8
+
9
+ import json
10
+ import os
11
+ import threading
12
+ import time
13
+ from http.server import BaseHTTPRequestHandler, ThreadingHTTPServer
14
+ from urllib.parse import parse_qs, urlparse
15
+
16
+ PORT = int(os.environ.get("SOPHON_BRIDGE_PORT", "0") or 0)
17
+
18
+
19
+ class Bridge:
20
+ def __init__(self, on_result):
21
+ self.on_result = on_result # (key, call_id, output, speak) -> bool
22
+ self.q: dict[str, list] = {}
23
+ self.cv = threading.Condition()
24
+ self.seen: dict[str, float] = {}
25
+ self._srv = None
26
+
27
+ def start(self):
28
+ if not PORT or self._srv is not None:
29
+ return
30
+ br = self
31
+
32
+ class H(BaseHTTPRequestHandler):
33
+ def log_message(self, *a):
34
+ pass
35
+
36
+ def _send(self, code, obj):
37
+ b = json.dumps(obj, ensure_ascii=False).encode()
38
+ try:
39
+ self.send_response(code); self.send_header("Content-Type", "application/json"); self.send_header("Content-Length", str(len(b))); self.end_headers(); self.wfile.write(b)
40
+ except (BrokenPipeError, ConnectionResetError):
41
+ pass # the gateway closed the long poll (session ended)
42
+
43
+ def do_GET(self):
44
+ u = urlparse(self.path); p = u.path.strip("/").split("/")
45
+ if len(p) == 3 and p[0] == "bridge" and p[2] == "events":
46
+ wait = min(float(parse_qs(u.query).get("wait", ["20"])[0]), 60.0)
47
+ return self._send(200, {"events": br.pop(p[1], wait)})
48
+ self._send(404, {"error": "not found"})
49
+
50
+ def do_POST(self):
51
+ p = urlparse(self.path).path.strip("/").split("/")
52
+ n = int(self.headers.get("Content-Length") or 0)
53
+ try:
54
+ j = json.loads(self.rfile.read(n) or b"{}")
55
+ except Exception: # noqa: BLE001
56
+ return self._send(400, {"error": "bad json"})
57
+ if len(p) == 3 and p[0] == "bridge" and p[2] == "result":
58
+ ok = br.on_result(p[1], j.get("call_id"), str(j.get("output", "")), bool(j.get("speak", True)))
59
+ return self._send(200 if ok else 404, {"ok": ok})
60
+ self._send(404, {"error": "not found"})
61
+
62
+ self._srv = ThreadingHTTPServer(("127.0.0.1", PORT), H)
63
+ threading.Thread(target=self._srv.serve_forever, daemon=True, name="sophon-bridge").start()
64
+
65
+ def push(self, key, ev):
66
+ with self.cv:
67
+ self.q.setdefault(key, []).append(ev); self.cv.notify_all()
68
+
69
+ def pop(self, key, wait):
70
+ end = time.monotonic() + wait
71
+ with self.cv:
72
+ self.seen[key] = time.monotonic()
73
+ while not self.q.get(key):
74
+ left = end - time.monotonic()
75
+ if left <= 0:
76
+ return []
77
+ self.cv.wait(left)
78
+ out, self.q[key] = self.q[key], []
79
+ return out
@@ -0,0 +1,102 @@
1
+ """sophon-realtime command line: download the Tag weights and serve them with vLLM-Omni on one GPU.
2
+
3
+ sophon-realtime download [--dir DIR] [--source modelscope|hf]
4
+ sophon-realtime serve [--model DIR] [--port 8000] [--gpu 0]
5
+
6
+ `serve` downloads Sophon-Realtime-32B-Tag first if --model does not hold it.
7
+ Endpoints: ws://HOST:PORT/v1/realtime (full duplex) and POST /v1/chat/completions (audio in -> text + audio out).
8
+ Live mode (OpenAI GPT-Live compatible) and examples: https://github.com/adventists-ai/sophon-realtime
9
+ """
10
+ import argparse, os, shutil, subprocess, sys
11
+
12
+ REPO = {"modelscope": "AdventistsAI/Sophon-Realtime-32B-Tag", "hf": "adventists-ai/Sophon-Realtime-32B-Tag"}
13
+ DEFAULT_DIR = "Sophon-Realtime-32B-Tag"
14
+ HERE = os.path.dirname(os.path.abspath(__file__))
15
+
16
+
17
+ def _is_tag(d):
18
+ return os.path.isfile(os.path.join(d, "config.json")) and os.path.isdir(os.path.join(d, "thinker")) and os.path.isfile(
19
+ os.path.join(d, "talker", "flow.decoder.estimator.fp32.onnx"))
20
+
21
+
22
+ def _source(s):
23
+ if s != "auto":
24
+ return s
25
+ try:
26
+ import modelscope # noqa: F401
27
+ return "modelscope"
28
+ except ImportError:
29
+ return "hf"
30
+
31
+
32
+ def download(dirname, source="auto"):
33
+ src = _source(source)
34
+ print(f"downloading {REPO[src]} ({src}) -> {dirname} (about 42 GB)", flush=True)
35
+ if src == "modelscope":
36
+ from modelscope import snapshot_download
37
+ snapshot_download(REPO[src], local_dir=dirname)
38
+ else:
39
+ from huggingface_hub import snapshot_download
40
+ snapshot_download(REPO[src], local_dir=dirname)
41
+ return dirname
42
+
43
+
44
+ def serve(a):
45
+ model = os.path.abspath(a.model)
46
+ if not _is_tag(model):
47
+ if os.path.isdir(model) and os.listdir(model):
48
+ print(f"{a.model} does not hold Sophon-Realtime-32B-Tag weights; downloading them to ./{DEFAULT_DIR}", flush=True)
49
+ model = os.path.abspath(DEFAULT_DIR)
50
+ if not _is_tag(model):
51
+ download(model, a.source)
52
+ os.makedirs(a.log_dir, exist_ok=True)
53
+ cfg_src = os.path.join(HERE, "deploy", "sophon_realtime_tag_1gpu.yaml")
54
+ cfg = os.path.join(os.path.abspath(a.log_dir), f"deploy_{a.port}.yaml")
55
+ with open(cfg_src) as f:
56
+ txt = f.read().replace("__HERE__/config/silero_vad.onnx", os.path.join(HERE, "deploy", "silero_vad.onnx"))
57
+ with open(cfg, "w") as f:
58
+ f.write(txt)
59
+ try:
60
+ import tensorrt # noqa: F401
61
+ trt = "1"
62
+ except ImportError:
63
+ trt = "0"
64
+ env = dict(os.environ)
65
+ env.setdefault("CUDA_VISIBLE_DEVICES", str(a.gpu))
66
+ env.update({k: env.get(k, v) for k, v in {
67
+ "SOPHON_MODEL": model, "SOPHON_PORT": str(a.port), "SOPHON_BRIDGE_PORT": str(a.port + 700),
68
+ "VLLM_DISABLE_COMPILE_CACHE": "1", "COSYVOICE3_TRT": trt,
69
+ "SOPHON_FLOW_STEPS": "4", "SOPHON_FLOW_CFG": "0", "COSYVOICE3_BATCH_FLOW": "1", "SOPHON_FLOW_MAXB": "16",
70
+ "SOPHON_FLOW_ONNX": os.path.join(model, "talker", "flow.decoder.estimator.fp32.onnx")}.items()})
71
+ vllm = shutil.which("vllm") or "vllm"
72
+ cmd = [vllm, "serve", model, "--omni", "--host", a.host, "--port", str(a.port), "--trust-remote-code",
73
+ "--init-timeout", "3000", "--stage-init-timeout", "3000", "--deploy-config", cfg]
74
+ print("first start builds kernels / TensorRT engine: 5-20 min; later 5-8 min", flush=True)
75
+ print(f"when ready: ws://HOST:{a.port}/v1/realtime http://HOST:{a.port}/v1/chat/completions", flush=True)
76
+ os.execvpe(cmd[0], cmd, env)
77
+
78
+
79
+ def main(argv=None):
80
+ ap = argparse.ArgumentParser(prog="sophon-realtime", description="Sophon-Realtime v1 (Tag build) on one 80 GB GPU with vLLM-Omni.")
81
+ sub = ap.add_subparsers(dest="cmd")
82
+ d = sub.add_parser("download", help="download Sophon-Realtime-32B-Tag")
83
+ d.add_argument("--dir", default=DEFAULT_DIR); d.add_argument("--source", default="auto", choices=["auto", "modelscope", "hf"])
84
+ s = sub.add_parser("serve", help="serve the Tag build (downloads the weights if needed)")
85
+ s.add_argument("--model", default=DEFAULT_DIR, help=f"weights directory (default ./{DEFAULT_DIR})")
86
+ s.add_argument("--host", default="0.0.0.0"); s.add_argument("--port", type=int, default=8000)
87
+ s.add_argument("--gpu", default="0", help="GPU index (ignored if CUDA_VISIBLE_DEVICES is set)")
88
+ s.add_argument("--source", default="auto", choices=["auto", "modelscope", "hf"])
89
+ s.add_argument("--log-dir", default="logs")
90
+ a = ap.parse_args(argv)
91
+ if a.cmd == "download":
92
+ download(a.dir, a.source)
93
+ elif a.cmd == "serve":
94
+ serve(a)
95
+ else:
96
+ ap.print_help()
97
+ return 1
98
+ return 0
99
+
100
+
101
+ if __name__ == "__main__":
102
+ sys.exit(main())
@@ -0,0 +1,11 @@
1
+ from transformers import PretrainedConfig
2
+
3
+
4
+ class SophonRealtimeConfig(PretrainedConfig):
5
+ """Root config: only describes the layout (thinker/, talker/, voices/ subdirs); each stage's weights live in its own subdir."""
6
+ model_type = "sophon_realtime"
7
+
8
+ def __init__(self, thinker_subdir="thinker", talker_subdir="talker", voices_subdir="voices", default_voice="chelsie", default_language="zh", **kw):
9
+ self.thinker_subdir = thinker_subdir; self.talker_subdir = talker_subdir; self.voices_subdir = voices_subdir
10
+ self.default_voice = default_voice; self.default_language = default_language
11
+ super().__init__(**kw)
@@ -0,0 +1,79 @@
1
+ # Sophon-Realtime-32B-Tag, ONE GPU (H100/A100 80 GB): thinker = offline FP8 (tag-writing merged), tag-tts talker + flow/HiFT on the same card.
2
+ # vllm serve <Sophon-Realtime-32B-Tag> --omni --deploy-config sophon_realtime_tag_1gpu.yaml
3
+ async_chunk: true
4
+ session_mode: duplex
5
+ duplex_session:
6
+ max_sessions: 32
7
+ idle_ttl_s: 60
8
+ server_vad_model_path: __HERE__/config/silero_vad.onnx
9
+
10
+ connectors:
11
+ connector_of_shared_memory:
12
+ name: SharedMemoryConnector
13
+ extra:
14
+ codec_streaming: true
15
+ connector_get_sleep_s: 0.002
16
+ connector_get_max_wait_first_chunk: 3000
17
+ connector_get_max_wait: 300
18
+ codec_chunk_frames: 10 # first flow chunk = 10 speech tokens (hop 10, voice prompts are trimmed to a multiple of 10)
19
+ codec_left_context_frames: 25
20
+ codec_vocab_size: 6561
21
+
22
+ stages:
23
+ - stage_id: 0
24
+ max_num_seqs: 32
25
+ gpu_memory_utilization: 0.62
26
+ trust_remote_code: true
27
+ enable_prefix_caching: true
28
+ max_model_len: 8192
29
+ mm_processor_cache_gb: 0
30
+ devices: "0"
31
+ limit_mm_per_prompt:
32
+ audio: 20
33
+ image: 2
34
+ output_connectors:
35
+ to_stage_1: connector_of_shared_memory
36
+ default_sampling_params:
37
+ temperature: 0.7
38
+ top_p: 0.9
39
+ max_tokens: 400
40
+
41
+ - stage_id: 1
42
+ max_num_seqs: 32
43
+ max_num_batched_tokens: 4096
44
+ gpu_memory_utilization: 0.08
45
+ enforce_eager: false
46
+ trust_remote_code: true
47
+ enable_prefix_caching: false
48
+ async_scheduling: false
49
+ max_model_len: 4096
50
+ devices: "0"
51
+ hf_overrides:
52
+ async_chunk_prewarm_prompt_len: 8 # [sos] + "You are a helpful assistant.<|endofprompt|>" (7 tokens)
53
+ input_connectors:
54
+ from_stage_0: connector_of_shared_memory
55
+ output_connectors:
56
+ to_stage_2: connector_of_shared_memory
57
+ default_sampling_params:
58
+ max_tokens: 2048
59
+ top_k: 25
60
+ top_p: 0.8
61
+ disable_hybrid_kv_cache_manager: true
62
+ mm_processor_cache_gb: 0
63
+ skip_mm_profiling: true
64
+
65
+ - stage_id: 2
66
+ max_num_batched_tokens: 32768
67
+ max_num_seqs: 32
68
+ gpu_memory_utilization: 0.08
69
+ enforce_eager: true
70
+ trust_remote_code: true
71
+ enable_prefix_caching: false
72
+ max_model_len: 32768
73
+ devices: "0"
74
+ input_connectors:
75
+ from_stage_1: connector_of_shared_memory
76
+ default_sampling_params:
77
+ max_tokens: 2048
78
+ disable_hybrid_kv_cache_manager: true
79
+ skip_mm_profiling: true
@@ -0,0 +1,4 @@
1
+ {
2
+ "zh": "你是智子(Sophon),AI降临派(Adventists AI)训练的 Sophon 系列模型,能听、能看,也能说。你会直接听到用户的语音,你的回复会被直接合成为语音说出来。请像真人对话一样,用自然的口语一两句话回应用户,注意用户的情绪。只写要说出口的话,不要写括号说明、表情或格式符号;数字、日期、金额、符号和英文缩写都直接写成口语念法。需要时可以用声音标签表现笑声、咳嗽和重读。",
3
+ "en": "You are Sophon, a model of the Sophon series trained by Adventists AI (AI降临派); you can hear, see and speak. You hear the user's speech directly, and your reply will be spoken aloud. Respond the way a person would in conversation, in one or two natural spoken sentences, paying attention to the user's emotion. Write only the words to be spoken: no parenthetical notes, emoji or formatting; write numbers and symbols the way they are read aloud. When it fits, you may use sound tags for laughter, coughs and emphasis."
4
+ }