Repository navigation
Commit cc9e4cb
feat(tts): use llama.cpp common_sampler for backbone logits + prompt-derived GBNF grammar
Backbone-logits sampling (the cb0-from-backbone token in run_codebook_ar —
MOSS-TTSD's merged text+speech vocab) now goes through llama.cpp's `common`
sampling layer (common_sampler) instead of a hand-rolled llama_sampler chain,
so chain assembly, grammar apply/resample, and penalty bookkeeping are reused
rather than reimplemented. codec_lm audio-codebook heads (residual depth
decoder, Chatterbox speech_head) and the LFM2 recomputed text logits stay on
the raw SamplerChain — they are arbitrary float arrays not tied to a
llama_context, so common_sampler (which reads llama_get_logits_ith) can't drive
them and grammar never applies there. The split is documented in tts_runner.cpp.
Grammar support:
* tts_runner_params.grammar — user-supplied GBNF passthrough (attached to the
backbone sampler when non-empty).
* codec_common::tts_auto_grammar(pi, text) — metadata-driven GBNF generator
(ported concept from llama.rn rn-tts build_dynamic_grammar). First
application: MOSS-TTSD cb0 — constrains decode-phase cb0 to the speech-token
range [cb0_speech_range_start, cb0_speech_range_end) ∪ {eos_code_c0} so the
backbone can't drift into arbitrary text tokens mid-utterance. The speech
range detokenizes as the pieces "<0>".."<1023>" + "<|end_of_speech|>"; the
HF reference (modeling_moss_ttsd) treats a non-speech cb0 as its natural
stop trigger, so eos stays permitted (a hard speech-only constraint would be
wrong). User grammar overrides auto.
Build plumbing (cmake/SetupTtsBackbone.cmake): enable LLAMA_BUILD_COMMON and
export the mangled common_sampler_* C++ symbols through libttsbackbone.so via an
unquoted `extern "C++" { common_sampler*; }` version-script glob; the three
common archives (llama-common, llama-common-base, cpp-httplib) go inside the
--whole-archive group so the symbols survive to the version script. Verified:
19 common_sampler symbols exported, 233 llama_ symbols, 0 ggml_ symbols — the
ggml 0.15 isolation is preserved (common references ggml only as undefined
symbols resolved internally against the bundled ggml).
Metadata: moss_ttsd.py converter now also writes codec.lm.cb0_speech_range_end
(scalar mirror of speech_token_range[1]); audio_lm surfaces both range bounds on
audio_lm_prompt_info.
tts-cli: --grammar FILE|STRING flag (loads file contents or literal GBNF).
Verify: cold ExternalProject rebuild links clean; common_sampler_* resolves at
runtime. ttscli_synthesize_smoke 8/8 with matching stop reasons; CSM greedy
byte-identical (cb0_from_backbone=0, never touches common_sampler; CER 0.000);
MOSS-TTSD CER 0.143 unchanged (auto-grammar, greedy) — no regression, drift
guard active under sampling. Bogus --grammar → clean "failed to parse grammar"
error, no crash.
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>1 parent 92e9884 commit cc9e4cb
7 files changed
Lines changed: 338 additions & 23 deletions
File tree
- cmake
- common
- examples
- scripts/converters/lm_adaptor
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
18 | 18 | | |
19 | 19 | | |
20 | 20 | | |
21 | | - | |
22 | | - | |
23 | | - | |
24 | | - | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
25 | 27 | | |
26 | 28 | | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
27 | 42 | | |
28 | 43 | | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
29 | 47 | | |
30 | 48 | | |
31 | 49 | | |
| |||
43 | 61 | | |
44 | 62 | | |
45 | 63 | | |
46 | | - | |
| 64 | + | |
47 | 65 | | |
48 | 66 | | |
49 | 67 | | |
50 | 68 | | |
51 | 69 | | |
52 | | - | |
| 70 | + | |
53 | 71 | | |
54 | 72 | | |
55 | 73 | | |
56 | 74 | | |
57 | 75 | | |
58 | | - | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
59 | 84 | | |
60 | | - | |
| 85 | + | |
| 86 | + | |
61 | 87 | | |
62 | 88 | | |
63 | 89 | | |
| |||
72 | 98 | | |
73 | 99 | | |
74 | 100 | | |
75 | | - | |
| 101 | + | |
| 102 | + | |
76 | 103 | | |
77 | 104 | | |
78 | 105 | | |
| 106 | + | |
79 | 107 | | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
881 | 881 | | |
882 | 882 | | |
883 | 883 | | |
| 884 | + | |
| 885 | + | |
| 886 | + | |
| 887 | + | |
| 888 | + | |
884 | 889 | | |
885 | 890 | | |
886 | 891 | | |
| |||
1051 | 1056 | | |
1052 | 1057 | | |
1053 | 1058 | | |
| 1059 | + | |
| 1060 | + | |
| 1061 | + | |
| 1062 | + | |
| 1063 | + | |
| 1064 | + | |
| 1065 | + | |
| 1066 | + | |
| 1067 | + | |
| 1068 | + | |
| 1069 | + | |
| 1070 | + | |
| 1071 | + | |
| 1072 | + | |
| 1073 | + | |
| 1074 | + | |
| 1075 | + | |
| 1076 | + | |
| 1077 | + | |
| 1078 | + | |
| 1079 | + | |
| 1080 | + | |
| 1081 | + | |
| 1082 | + | |
| 1083 | + | |
| 1084 | + | |
| 1085 | + | |
| 1086 | + | |
| 1087 | + | |
| 1088 | + | |
| 1089 | + | |
| 1090 | + | |
| 1091 | + | |
| 1092 | + | |
| 1093 | + | |
| 1094 | + | |
| 1095 | + | |
| 1096 | + | |
| 1097 | + | |
| 1098 | + | |
| 1099 | + | |
| 1100 | + | |
| 1101 | + | |
| 1102 | + | |
| 1103 | + | |
| 1104 | + | |
| 1105 | + | |
| 1106 | + | |
| 1107 | + | |
| 1108 | + | |
| 1109 | + | |
| 1110 | + | |
| 1111 | + | |
| 1112 | + | |
| 1113 | + | |
| 1114 | + | |
| 1115 | + | |
| 1116 | + | |
| 1117 | + | |
| 1118 | + | |
| 1119 | + | |
| 1120 | + | |
| 1121 | + | |
| 1122 | + | |
| 1123 | + | |
| 1124 | + | |
| 1125 | + | |
| 1126 | + | |
| 1127 | + | |
| 1128 | + | |
| 1129 | + | |
| 1130 | + | |
| 1131 | + | |
| 1132 | + | |
| 1133 | + | |
| 1134 | + | |
| 1135 | + | |
| 1136 | + | |
| 1137 | + | |
| 1138 | + | |
| 1139 | + | |
| 1140 | + | |
| 1141 | + | |
| 1142 | + | |
| 1143 | + | |
| 1144 | + | |
| 1145 | + | |
| 1146 | + | |
| 1147 | + | |
| 1148 | + | |
| 1149 | + | |
| 1150 | + | |
1054 | 1151 | | |
1055 | 1152 | | |
1056 | 1153 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
456 | 456 | | |
457 | 457 | | |
458 | 458 | | |
| 459 | + | |
| 460 | + | |
| 461 | + | |
| 462 | + | |
| 463 | + | |
| 464 | + | |
| 465 | + | |
| 466 | + | |
| 467 | + | |
| 468 | + | |
| 469 | + | |
459 | 470 | | |
460 | 471 | | |
461 | 472 | | |
462 | 473 | | |
463 | 474 | | |
464 | 475 | | |
465 | 476 | | |
| 477 | + | |
| 478 | + | |
| 479 | + | |
| 480 | + | |
| 481 | + | |
| 482 | + | |
| 483 | + | |
| 484 | + | |
| 485 | + | |
| 486 | + | |
| 487 | + | |
| 488 | + | |
| 489 | + | |
| 490 | + | |
| 491 | + | |
| 492 | + | |
| 493 | + | |
| 494 | + | |
| 495 | + | |
| 496 | + | |
| 497 | + | |
| 498 | + | |
| 499 | + | |
| 500 | + | |
466 | 501 | | |
467 | 502 | | |
468 | 503 | | |
| |||
0 commit comments