MCPcopy
hub / github.com/tinygrad/tinygrad / stream_decoder

Method stream_decoder

tinygrad/llm/cli.py:63–66  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

61
62 def decode(self, ids:list[int]) -> str: return b''.join(self._tok2bytes[tid] for tid in ids).decode(errors='replace')
63 def stream_decoder(self) -> typing.Callable[..., str]:
64 dec = codecs.getincrementaldecoder('utf-8')('replace')
65 def _decode(tid:int|None=None) -> str: return dec.decode(self._tok2bytes[tid]) if tid is not None else dec.decode(b'', final=True)
66 return _decode
67 def role(self, role:str):
68 if self.preset == 'olmo': return self.encode("<|" + role + "|>\n") # OLMoE Instruct format
69 if self.preset == 'kimi-k2': return self.encode("<|im_" + role + "|>" + role + "<|im_middle|>")

Callers 3

test_stream_decoderMethod · 0.95
run_modelMethod · 0.80
mainFunction · 0.80

Calls

no outgoing calls

Tested by 1

test_stream_decoderMethod · 0.76