MCPcopy Index your code
hub / github.com/tinygrad/tinygrad / validate_model

Function validate_model

examples/tinychat/tinychat-browser/compile.py:82–101  ·  view source on GitHub ↗
(model, tokenizer)

Source from the content-addressed store, hash-verified

80 return metadata
81
82def validate_model(model, tokenizer):
83 prompt = "yo"
84 toks = [tokenizer.bos_id]
85 toks += [tokenizer.special_tokens["<|start_header_id|>"]] + tokenizer.encode("user") + [tokenizer.special_tokens["<|end_header_id|>"]] + tokenizer.encode("\n\n")
86 toks += tokenizer.encode(prompt) + [tokenizer.special_tokens["<|eot_id|>"]]
87 toks += [tokenizer.special_tokens["<|start_header_id|>"]] + tokenizer.encode("assistant") + [tokenizer.special_tokens["<|end_header_id|>"]] + tokenizer.encode("\n\n")
88 start_pos = 0
89 run = TinyJit(model.forward)
90 for tok in toks[:-1]:
91 run(Tensor([[tok]]), Variable("start_pos", 0, model.max_context).bind(start_pos), 0.0, 0, 0.0, 0.0, 0.0).realize()
92 start_pos += 1
93 tok = toks[-1]
94 result = ""
95 expected = "How's it going?"
96 while True:
97 tok = run(Tensor([[tok]]), Variable("start_pos", 0, model.max_context).bind(start_pos), 0.0, 0, 0.0, 0.0, 0.0).item()
98 start_pos += 1
99 if tok in tokenizer.stop_tokens or len(result) > len(expected): break
100 result += tokenizer.decode([tok])
101 assert result == expected, f"Model validation failed, expected output: {expected}, actual output: {result}"
102
103if __name__=="__main__":
104 # Export BPE data for use with tiktoken.js

Callers 1

compile.pyFile · 0.85

Calls 9

TinyJitClass · 0.90
TensorClass · 0.90
realizeMethod · 0.80
itemMethod · 0.80
runFunction · 0.50
VariableFunction · 0.50
encodeMethod · 0.45
bindMethod · 0.45
decodeMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…