原书出处
Build a Reasoning Model (From Scratch)
token_ids, max_new_tokens, eos_token_id=None ): input_length = token_ids.shape[1] model.eval() cache = KVCache(n_layers=model.cfg["n_layers"]) #A model.reset_kv_cache() out = model(token_ids, cache=cache)[:, -1] #B for _ in range(max_new_tokens): next_token = torch.argmax(out, dim=-1, keepdim=True) if (eos_token_id is not None and next_token.item() == eos_token_id): break token_ids = torch.cat([token_ids, next_token], dim=1) out = model(next_token, cache=cache)[:, -1] #C return token_ids[:, input_length:] #A Initialize the KV cache #B In the first round, the whole input
原书定位详情
来源:a19c7933-4eda-4176-aebd-30fe7e1ad292
正文位置:extracted/Build a Reasoning Model (From Scratch)/_epub-src/OEBPS/Text/chapter-2.html
EPUB SHA-256:52d4d07986020be70f5aac21762dfcf60fcba08db0ba29d4f63957caf12aa377