MCPcopy Create free account
hub / github.com/RightNow-AI/TIDE / test_inference

Function test_inference

modal_setup/dev_app.py:56–87  ·  view source on GitHub ↗

Test TIDE inference on a model.

(
    model_name: str = "meta-llama/Llama-3.1-8B-Instruct",
    prompt: str = "Explain quantum computing in simple terms:",
    max_new_tokens: int = 256,
)

Source from the content-addressed store, hash-verified

54 timeout=3600,
55)
56def test_inference(
57 model_name: str = "meta-llama/Llama-3.1-8B-Instruct",
58 prompt: str = "Explain quantum computing in simple terms:",
59 max_new_tokens: int = 256,
60):
61 """Test TIDE inference on a model."""
62 import torch
63 from transformers import AutoModelForCausalLM, AutoTokenizer
64 from TIDE.config import TIDEConfig
65 from TIDE.runtime import TIDERuntime
66
67 model = AutoModelForCausalLM.from_pretrained(
68 model_name,
69 torch_dtype=torch.float16,
70 device_map="auto",
71 cache_dir="/root/models",
72 )
73 tokenizer = AutoTokenizer.from_pretrained(model_name, cache_dir="/root/models")
74
75 safe_name = model_name.replace("/", "_")
76 router_path = f"/root/routers/{safe_name}_router.pt"
77
78 runtime = TIDERuntime(model, router_path, config=TIDEConfig())
79
80 inputs = tokenizer(prompt, return_tensors="pt").to(model.device)
81 output = runtime.generate(inputs.input_ids, max_new_tokens=max_new_tokens, temperature=0)
82 text = tokenizer.decode(output[0], skip_special_tokens=True)
83
84 return {
85 "output": text,
86 "stats": runtime.last_stats.summary() if runtime.last_stats else "N/A",
87 }

Callers

nothing calls this directly

Calls 5

generateMethod · 0.95
TIDERuntimeClass · 0.90
TIDEConfigClass · 0.90
toMethod · 0.80
summaryMethod · 0.80

Tested by

no test coverage detected