MCPcopy Create free account
hub / github.com/OpenMOSS/MOSS-TTS / step

Function step

moss_tts_delay/llama_cpp/delay_state.py:133–256  ·  view source on GitHub ↗

Execute one autoregressive step. Returns: next_input_ids: (33,) int64 — [text_token, audio_0, ..., audio_31]

(
    state: DelayState,
    text_logits: np.ndarray,
    audio_logits: np.ndarray,
    config: SamplingConfig,
)

Source from the content-addressed store, hash-verified

131
132
133def step(
134 state: DelayState,
135 text_logits: np.ndarray,
136 audio_logits: np.ndarray,
137 config: SamplingConfig,
138) -> np.ndarray:
139 """Execute one autoregressive step.
140
141 Returns:
142 next_input_ids: (33,) int64 — [text_token, audio_0, ..., audio_31]
143 """
144 if state.is_stopping:
145 pad_result = np.full(1 + N_VQ, AUDIO_PAD_CODE, dtype=np.int64)
146 pad_result[0] = PAD_TOKEN_ID
147 return pad_result
148
149 n_vq = N_VQ
150
151 # --- Text token decision ---
152 if state.delayed_length < n_vq:
153 next_text = AUDIO_ASSISTANT_DELAY_SLOT_TOKEN_ID
154 elif state.delayed_length == n_vq:
155 next_text = AUDIO_END_TOKEN_ID
156 state.is_audio = False
157 else:
158 text_temp = config.text_temperature if config.text_temperature > 0 else 1.0
159 text_do_sample = config.text_temperature > 0
160 scaled = text_logits / text_temp
161
162 if not state.is_audio:
163 scaled[_PRE_EXCLUDE_IDS] = -np.inf
164 else:
165 mask = np.ones(scaled.shape[0], dtype=bool)
166 mask[_AUDIO_ALLOWED_IDS] = False
167 scaled[mask] = -np.inf
168
169 if state.time_step == 0:
170 scaled[AUDIO_ASSISTANT_DELAY_SLOT_TOKEN_ID] = -np.inf
171 if state.time_step <= n_vq:
172 scaled[IM_END_TOKEN_ID] = -np.inf
173
174 next_text = int(sample_token(
175 scaled[np.newaxis, :],
176 top_p=config.text_top_p,
177 top_k=config.text_top_k,
178 do_sample=text_do_sample,
179 )[0])
180
181 if next_text == AUDIO_START_TOKEN_ID:
182 state.is_audio = True
183 if next_text == IM_END_TOKEN_ID:
184 state.is_stopping = True
185
186 # --- Audio token decision ---
187 next_audio = np.full(n_vq, AUDIO_PAD_CODE, dtype=np.int64)
188
189 pre_audio_mask = np.arange(n_vq) < state.audio_length
190 if state.delayed_length == INT64_MAX:

Callers

nothing calls this directly

Calls 3

audio_historyMethod · 0.80
append_audioMethod · 0.80
sample_tokenFunction · 0.70

Tested by

no test coverage detected