MCPcopy Create free account
hub / github.com/OpenBMB/AgentCPM-GUI / _decode_default

Function _decode_default

eval/utils/utils_odyssey/qwen_generation_utils.py:196–226  ·  view source on GitHub ↗
(
    tokens: List[int],
    *,
    stop_words: List[str],
    eod_words: List[str],
    tokenizer: PreTrainedTokenizer,
    raw_text_len: int,
    verbose: bool = False,
    return_end_reason: bool = False,
    errors: str='replace',
)

Source from the content-addressed store, hash-verified

194
195
196def _decode_default(
197 tokens: List[int],
198 *,
199 stop_words: List[str],
200 eod_words: List[str],
201 tokenizer: PreTrainedTokenizer,
202 raw_text_len: int,
203 verbose: bool = False,
204 return_end_reason: bool = False,
205 errors: str='replace',
206):
207 trim_decode_tokens = tokenizer.decode(tokens, errors=errors)[raw_text_len:]
208 if verbose:
209 print("\nRaw Generate: ", trim_decode_tokens)
210
211 end_reason = f"Gen length {len(tokens)}"
212 for stop_word in stop_words:
213 trim_decode_tokens = trim_decode_tokens.replace(stop_word, "").strip()
214 for eod_word in eod_words:
215 if eod_word in trim_decode_tokens:
216 end_reason = f"Gen {eod_word!r}"
217 trim_decode_tokens = trim_decode_tokens.split(eod_word)[0]
218 trim_decode_tokens = trim_decode_tokens.strip()
219 if verbose:
220 print("\nEnd Reason:", end_reason)
221 print("\nGenerate: ", trim_decode_tokens)
222
223 if return_end_reason:
224 return trim_decode_tokens, end_reason
225 else:
226 return trim_decode_tokens
227
228
229def _decode_chatml(

Callers 1

decode_tokensFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected