MCPcopy Create free account
hub / github.com/microsoft/BitNet / trim_answer

Method trim_answer

gpu/generate.py:290–298  ·  view source on GitHub ↗

Trim the answer to end it on an eos token.

(prompt_len, tokens)

Source from the content-addressed store, hash-verified

288 stats.end_phase(tokens=niter * bs)
289
290 def trim_answer(prompt_len, tokens):
291 # print(prompt, tokens)
292 """Trim the answer to end it on an eos token."""
293 tokens = tokens[: max_seq_length - prompt_len]
294 eos_id = self.tokenizer.eot_id
295 if eos_id in tokens:
296 return tokens[: tokens.index(eos_id) + 1]
297 else:
298 return tokens
299
300 answers = [
301 trim_answer(prompt_len, answer)

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected