forked from nazirlouis/ada_local
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdebug_router.py
More file actions
41 lines (33 loc) · 1.26 KB
/
debug_router.py
File metadata and controls
41 lines (33 loc) · 1.26 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
"""Debug script to see raw model output."""
import torch
from core.router import FunctionGemmaRouter, TOOLS
router = FunctionGemmaRouter(compile_model=False)
SYSTEM_MSG = "You are a model that can do function calling with the following functions"
test_prompts = [
"Turn on the living room lights",
"Set a timer for 10 minutes",
"Add buy groceries to my list",
]
for user_prompt in test_prompts:
messages = [
{"role": "developer", "content": SYSTEM_MSG},
{"role": "user", "content": user_prompt},
]
prompt = router.tokenizer.apply_chat_template(
messages, tools=TOOLS, add_generation_prompt=True, tokenize=False
)
inputs = router.tokenizer(prompt, return_tensors="pt").to(router.model.device)
with torch.inference_mode():
outputs = router.model.generate(
**inputs,
max_new_tokens=150,
do_sample=False,
use_cache=True,
pad_token_id=router.tokenizer.pad_token_id
)
new_tokens = outputs[0][inputs['input_ids'].shape[1]:]
response = router.tokenizer.decode(new_tokens, skip_special_tokens=False)
print(f"\n{'='*60}")
print(f"PROMPT: {user_prompt}")
print(f"RAW OUTPUT: {repr(response)}")
print(f"{'='*60}")