Open full-duplex voice models that hear your tone and speak with one. One GPU with vLLM-Omni, or fully offline on a Mac with MLX. Zero-shot voice cloning, OpenAI Realtime / GPT-Live compatible, free hosted API trial. Apache-2.0.
Python apple-siliconfull-duplexlivekitmacosmlxofflineopen-sourceopenai-realtimeparalinguisticspipecatrealtimespeechspeech-to-speechttsvllmvllm-omnivoice-assistantvoice-cloningzero-shot
finetune: 4B builds (continue the 4B tag LoRA, merge on CPU); flash/start.sh honours MODEL_DIR
BKtensorf5cafabe9a87
diff --git a/finetune/README.md b/finetune/README.mdindex 31e38a5..120c830 100644--- a/finetune/README.md+++ b/finetune/README.md@@ -7,6 +7,7 @@ You can adapt the **thinker** of Sophon-Realtime v1 (the part that listens and w- **What changes:** what the model says — content, persona, tone, domain knowledge, tool-calling habits.- **What does not:** turn-taking (turn questions go to the base model without the LoRA), and the voice, timbre and delivery (the talker).- **Expressive speech is kept:** the thinker writes sound tags (`[laughter]`, `[cough]`, `<strong>…</strong>`, …) and the talker performs them. Fine-tuning therefore **continues the bundled tag LoRA** instead of starting a new one; otherwise the model stops writing tags.+- **4B builds** (Sophon-Realtime-4B-Tag / Flash / E2E): see [section 7](#7-4b-builds-sophon-realtime-4b-tag---flash---e2e).## 1. Install@@ -138,6 +139,46 @@ The report compares:Keep the tag rate close to the original, and keep malformed tags and wrong-language replies near zero.+## 7. 4B builds (Sophon-Realtime-4B-Tag / -Flash / -E2E)++> **Being verified.** The 4B tag LoRA, the format conversion and the merge step below are checked: merging the released tag LoRA into the base with `sophon_swift.merge` reproduces the released 4B thinker bit for bit. A full train → merge → serve run on GPU is still in progress; memory figures and a tested learning rate will be added after it.++The three 4B builds share one thinker: DuplexJev-4B-Para v1.4 with the 4B tag LoRA (rank 16, alpha 32) merged in. Sections 1, 3 and 6 apply as written. What differs:++**Download.** The base and the tag LoRA are in separate repos:++```bash+modelscope download --model AdventistsAI/DuplexJev-4B-Para --local_dir DuplexJev-4B-Para+modelscope download --model AdventistsAI/Sophon-Realtime-4B-Tag --include 'adapters/*' --local_dir Sophon-Realtime-4B-Tag+python -m sophon_swift.adapters to-swift Sophon-Realtime-4B-Tag/adapters/tag tag4b_swift+```++The same tag LoRA serves all three 4B builds.++**Train.** As in section 4, with `--model DuplexJev-4B-Para --adapters tag4b_swift`. The tag LoRA itself was trained on the tag replay data for 2 epochs at learning rate 1e-4 (batch 4 × 2 accumulation, up to 4096 tokens, about 31 GB on one GPU); when continuing it on your data, start from 5e-5.++**Merge, then serve.** The 4B servers do not attach a LoRA at run time, so merge yours into the base. This runs on CPU (about 17 GB of RAM, one to two minutes):++```bash+python -m sophon_swift.merge --base DuplexJev-4B-Para --lora output/vx-xxx/checkpoint-yyy \+ --like ../flash/model/thinker --out thinker_mine+```++`--like` is the thinker of the build you serve (here a 4B Flash install in `../flash/model`); it supplies the config, tokenizer and file layout. Then build a model folder that uses your thinker and the build's other parts, and start the build on it:++```bash+mkdir model_mine+for f in ../flash/model/*; do [ "$(basename "$f")" = thinker ] || ln -s "$(realpath "$f")" model_mine/; done+mv thinker_mine model_mine/thinker+MODEL_DIR=$PWD/model_mine bash ../flash/start.sh+```++**Things to know:**++- **Turn-taking can change.** In the 4B builds the turn questions go to the same merged thinker, so unlike v1 your LoRA can change when the model takes the turn. Run the regression check of section 6 (serve `DuplexJev-4B-Para` with `tag=Sophon-Realtime-4B-Tag/adapters/tag`), and before deploying, try a few conversations with pauses and interruptions.+- **Think block.** At inference the 4B chat template adds an empty `<think>\n\n</think>\n\n` after the assistant header; the training template here does not. The released tag LoRA was trained this way and keeps the reference tag rate (0.36 on 150 held-out conversations).+- **Tool calls.** The 4B thinker does not support tool calling. Training on tool-call data may bring some of it back; we have not tested this.+## FAQ- **Can I train the audio side?** Not in this release. The talker reads the audio representation, so changing the encoder or the projector would break it.diff --git a/finetune/README_CN.md b/finetune/README_CN.mdindex a3d9b4a..671fa8a 100644--- a/finetune/README_CN.md+++ b/finetune/README_CN.md@@ -9,6 +9,7 @@ Sophon-Realtime v1 可以按业务场景微调**思考器**,也就是听用户- 接话判断:话轮题走不带 LoRA 的底座,微调影响不到。- 声音、音色和说话方式:它们由说话头决定。- **笑声、咳嗽等声音表现会保留**:思考器在回复里写声音标签(`[laughter]`、`[cough]`、`<strong>…</strong>` 等),说话头照着标签演出来。所以微调要**从自带的写标签 LoRA 接着训**,不要从零训一个新 LoRA,否则模型就不会再写标签。+- **4B 版**(Sophon-Realtime-4B-Tag / Flash / E2E)的做法见[第 7 节](#7-4b-版sophon-realtime-4b-tag---flash---e2e)。## 1. 环境@@ -143,6 +144,46 @@ python tools/regress.py --url http://127.0.0.1:8000 --data my_eval.jsonl --base重点看两点:写标签的比例不要掉得太多;不合法标签和语言不对的数量应接近 0。+## 7. 4B 版(Sophon-Realtime-4B-Tag / -Flash / -E2E)++> **验证中。** 4B 的写标签 LoRA、格式转换和下面的合并步骤已经核对过:用 `sophon_swift.merge` 把发布的写标签 LoRA 合并进底座,得到的权重和发布的 4B 思考器逐位一致。在 GPU 上完整跑一遍「训练 → 合并 → 部署」还在进行,跑完后补上显存数字和实测过的学习率。++三个 4B 版用同一个思考器:DuplexJev-4B-Para v1.4,合并了 4B 写标签 LoRA(rank 16,alpha 32)。第 1、3、6 节照常适用,不同的地方如下。++**下载。** 底座和写标签 LoRA 在两个仓库里:++```bash+modelscope download --model AdventistsAI/DuplexJev-4B-Para --local_dir DuplexJev-4B-Para+modelscope download --model AdventistsAI/Sophon-Realtime-4B-Tag --include 'adapters/*' --local_dir Sophon-Realtime-4B-Tag+python -m sophon_swift.adapters to-swift Sophon-Realtime-4B-Tag/adapters/tag tag4b_swift+```++三个 4B 版都用这同一个写标签 LoRA。++**训练。** 和第 4 节一样,改成 `--model DuplexJev-4B-Para --adapters tag4b_swift`。写标签 LoRA 本身是在标签回放数据上训的:2 个 epoch,学习率 1e-4,batch 4 × 累积 2,最长 4096 token,单卡约 31 GB。在你的数据上接着训时,学习率先用 5e-5。++**先合并,再部署。** 4B 版的服务不会在运行时挂 LoRA,所以要把你的 LoRA 合并进底座。在 CPU 上就能做,约需 17 GB 内存、一两分钟:++```bash+python -m sophon_swift.merge --base DuplexJev-4B-Para --lora output/vx-xxx/checkpoint-yyy \+ --like ../flash/model/thinker --out thinker_mine+```++`--like` 填你要部署的那个版本的思考器目录(这里是装在 `../flash/model` 的 4B Flash),配置、分词器和文件布局都从这里取。然后建一个模型目录,思考器换成你的,其余部分沿用原版,再用它启动:++```bash+mkdir model_mine+for f in ../flash/model/*; do [ "$(basename "$f")" = thinker ] || ln -s "$(realpath "$f")" model_mine/; done+mv thinker_mine model_mine/thinker+MODEL_DIR=$PWD/model_mine bash ../flash/start.sh+```++**注意:**++- **接话判断可能会变。** 4B 版的话轮题也走同一个合并后的思考器,所以和 v1 不同,你的 LoRA 可能改变模型什么时候接话。请做第 6 节的回归检查(部署 `DuplexJev-4B-Para`,用 `tag=Sophon-Realtime-4B-Tag/adapters/tag`);上线前再试几段有停顿、有打断的对话。+- **think 块。** 推理时 4B 的对话模板会在 assistant 开头后加一个空的 `<think>\n\n</think>\n\n`,这里的训练模板不加。发布的写标签 LoRA 就是这样训的,带标签比例和参照一致(150 条留出对话上为 0.36)。+- **工具调用。** 4B 思考器不支持工具调用。用工具调用数据训练也许能找回一部分,我们还没有测试过。+## 常见问题- **能不能训听觉部分?** 这个版本不支持。听觉编码器和投影器决定了说话头读到的表示,改了它们,说话头就对不上了。diff --git a/finetune/sophon_swift/merge.py b/finetune/sophon_swift/merge.pynew file mode 100644index 0000000..e9bc85f--- /dev/null+++ b/finetune/sophon_swift/merge.py@@ -0,0 +1,94 @@+# Copyright 2026 Adventists AI. Apache-2.0.+"""Merge a thinker LoRA into a base thinker, on CPU, in the file layout of a released thinker/ folder.++The 4B builds (Sophon-Realtime-4B-Tag / -Flash / -E2E) ship the thinker with the tag LoRA already merged, and their+servers do not attach a LoRA at run time. After fine-tuning the 4B tag LoRA, merge it into the plain base+(DuplexJev-4B-Para) and use the result as the build's thinker/:++ python -m sophon_swift.merge --base DuplexJev-4B-Para --lora output/vx-xxx/checkpoint-yyy \+ --like Sophon-Realtime-4B-Flash/thinker --out thinker_mine++--like gives everything except the weights (config, tokenizer, chat template) and the shard layout. Only the LLM+layers are changed; the audio encoder and the projector are copied from --base unchanged. No GPU needed (~17 GB RAM).+"""+import argparse+import json+import os+import shutil+from collections import defaultdict++PREFIX = "base_model.model."+++def load_lora(path):+ from safetensors.torch import load_file+ cfg = json.load(open(os.path.join(path, "adapter_config.json")))+ if cfg.get("modules_to_save"):+ raise ValueError("modules_to_save is not supported; train LoRA on the LLM only")+ scale = cfg["lora_alpha"] / cfg["r"]+ if cfg.get("use_rslora"):+ scale = cfg["lora_alpha"] / cfg["r"] ** 0.5+ t = load_file(os.path.join(path, "adapter_model.safetensors"))+ pairs = {}+ for k in t:+ if k.endswith(".lora_A.weight"):+ name = k[len(PREFIX):-len(".lora_A.weight")] + ".weight"+ pairs[name] = (t[k], t[k.replace(".lora_A.", ".lora_B.")])+ if len(pairs) * 2 != len(t):+ raise ValueError(f"unexpected tensors in {path}: {len(t)} tensors, {len(pairs)} LoRA pairs")+ return pairs, scale+++def main():+ ap = argparse.ArgumentParser()+ ap.add_argument("--base", required=True, help="plain base thinker, e.g. DuplexJev-4B-Para")+ ap.add_argument("--lora", required=True, help="ms-swift checkpoint or vLLM adapter folder")+ ap.add_argument("--like", required=True, help="a released thinker/ folder (gives config, tokenizer, shard layout)")+ ap.add_argument("--out", required=True)+ a = ap.parse_args()+ import torch+ from safetensors import safe_open+ from safetensors.torch import save_file++ pairs, scale = load_lora(a.lora)+ like_map = json.load(open(os.path.join(a.like, "model.safetensors.index.json")))["weight_map"]+ base_map = json.load(open(os.path.join(a.base, "model.safetensors.index.json")))["weight_map"]+ if set(like_map) != set(base_map):+ raise ValueError("--base and --like hold different tensors; are they the same model size?")+ missing = [k for k in pairs if k not in base_map]+ if missing:+ raise ValueError(f"{len(missing)} LoRA targets not in the base (e.g. {missing[0]}); wrong base model?")++ os.makedirs(a.out, exist_ok=True)+ for f in os.listdir(a.like):+ p = os.path.join(a.like, f)+ if os.path.isfile(p) and not f.endswith(".safetensors") and f != "model.safetensors.index.json":+ shutil.copy2(p, os.path.join(a.out, f))++ by_shard = defaultdict(list)+ for k, shard in like_map.items():+ by_shard[shard].append(k)+ handles = {}+ total, merged = 0, 0+ for shard in sorted(by_shard):+ out = {}+ for k in by_shard[shard]:+ src = base_map[k]+ if src not in handles:+ handles[src] = safe_open(os.path.join(a.base, src), "pt")+ w = handles[src].get_tensor(k)+ if k in pairs:+ A, B = pairs[k]+ w = (w.float() + scale * (B.float() @ A.float())).to(w.dtype)+ merged += 1+ out[k] = w.contiguous()+ total += w.numel() * w.element_size()+ save_file(out, os.path.join(a.out, shard), metadata={"format": "pt"})+ print(f"wrote {shard} ({len(out)} tensors)", flush=True)+ json.dump({"metadata": {"total_size": total}, "weight_map": like_map},+ open(os.path.join(a.out, "model.safetensors.index.json"), "w"), indent=2)+ print(f"merged {merged} LoRA pairs (scale {scale:g}) into {a.out}")+++if __name__ == "__main__":+ main()diff --git a/flash/start.sh b/flash/start.shindex edb32bc..0d1dca0 100755--- a/flash/start.sh+++ b/flash/start.sh@@ -1,14 +1,14 @@#!/bin/bash# Start Sophon-Realtime-32B-Flash on ONE GPU (80 GB: H100 / H800 / A100 80G).-# usage: bash start.sh env: GPU=0 PORT=8000 MPS=1+# usage: bash start.sh env: GPU=0 PORT=8000 MODEL_DIR=./model MPS=1# several GPUs: one instance per GPU, e.g. GPU=0 PORT=8000 bash start.sh; GPU=1 PORT=8001 bash start.sh (put a load balancer in front)# endpoints: ws://HOST:PORT/v1/realtime (full duplex) http://HOST:PORT/v1/chat/completions (audio in -> text + audio out)HERE=$(cd "$(dirname "$0")" && pwd); cd "$HERE"; mkdir -p logs-GPU=${GPU:-0}; PORT=${PORT:-8000}; PY=$HERE/.venv/bin+GPU=${GPU:-0}; PORT=${PORT:-8000}; PY=$HERE/.venv/bin; MODEL_DIR=${MODEL_DIR:-$HERE/model}[ -f logs/server_$PORT.pid ] && PORT=$PORT bash stop.sh >/dev/null 2>&1DEV=$GPU# a 4B model (Sophon-Realtime-4B-Flash) gets the one-24-GB-GPU config unless CONFIG says otherwise-grep -q '"hidden_size": 2560' "${MODEL_DIR:-$HERE/model}/thinker/config.json" 2>/dev/null && IS4B=1+grep -q '"hidden_size": 2560' "$MODEL_DIR/thinker/config.json" 2>/dev/null && IS4B=1SUF=1gpu; [ -n "$IS4B" ] && SUF=4bCONFIG=${CONFIG:-sophon_realtime_flash_$SUF.yaml}# vLLM compiles a few kernels at the first start (several minutes) and caches them. Keep the cache with this install: the default@@ -20,8 +20,8 @@ if [ "${MPS:-1}" = 1 ] && command -v nvidia-cuda-mps-control >/dev/null; thenif echo get_server_list | nvidia-cuda-mps-control >/dev/null 2>&1; then DEV=0; echo "MPS on (GPU $GPU)"; else unset CUDA_MPS_PIPE_DIRECTORY CUDA_MPS_LOG_DIRECTORY; fifised "s#__HERE__#$HERE#g" config/$CONFIG > logs/deploy_$PORT.yaml-SOPHON_MODEL=$HERE/model SOPHON_PORT=$PORT SOPHON_BRIDGE_PORT=${SOPHON_BRIDGE_PORT:-$((PORT+700))} VLLM_DISABLE_COMPILE_CACHE=1 CUDA_VISIBLE_DEVICES=$DEV PATH=$PY:$PATH \- setsid nohup $PY/vllm serve $HERE/model --omni --port $PORT --trust-remote-code --init-timeout 3000 --stage-init-timeout 3000 --deploy-config logs/deploy_$PORT.yaml > logs/server_$PORT.log 2>&1 < /dev/null &+SOPHON_MODEL=$MODEL_DIR SOPHON_PORT=$PORT SOPHON_BRIDGE_PORT=${SOPHON_BRIDGE_PORT:-$((PORT+700))} VLLM_DISABLE_COMPILE_CACHE=1 CUDA_VISIBLE_DEVICES=$DEV PATH=$PY:$PATH \+ setsid nohup $PY/vllm serve $MODEL_DIR --omni --port $PORT --trust-remote-code --init-timeout 3000 --stage-init-timeout 3000 --deploy-config logs/deploy_$PORT.yaml > logs/server_$PORT.log 2>&1 < /dev/null &echo $! > logs/server_$PORT.pidecho "starting (first start compiles kernels: about 10 min; later 5-8 min) ... log: logs/server_$PORT.log"for i in $(seq 1 240); do