MaduRox commited on
Commit
74aa433
·
1 Parent(s): 9ab7159

fix: configure clean chat template and hybrid RIF sliding window on T4 GPU

Browse files
Files changed (1) hide show
  1. app.py +6 -10
app.py CHANGED
@@ -62,15 +62,12 @@ def kalpana_generate(prompt: str, max_tokens: float = 256, temperature: float =
62
 
63
  _load_model(device, dtype)
64
 
65
- messages = [
66
- {"role": "system", "content": "You are a helpful, intelligent AI assistant. Always answer user queries clearly, accurately, and concisely in English."},
67
- {"role": "user", "content": prompt.strip()}
68
- ]
69
  fmt = _LOCAL_TOKENIZER.apply_chat_template(messages, tokenize=False, add_generation_prompt=True)
70
  inputs = _LOCAL_TOKENIZER(fmt, return_tensors="pt").to(device)
71
 
72
  num_layers = getattr(_LOCAL_QWEN_MODEL.config, "num_hidden_layers", 24)
73
- cache = KalpanaDynamicCache(num_layers=num_layers, bands=2048)
74
 
75
  t0 = time.perf_counter()
76
  with torch.inference_mode():
@@ -78,11 +75,10 @@ def kalpana_generate(prompt: str, max_tokens: float = 256, temperature: float =
78
  **inputs,
79
  past_key_values=cache,
80
  max_new_tokens=int(max_tokens),
81
- do_sample=True,
82
- temperature=float(temperature) if float(temperature) > 0 else 0.6,
83
- top_p=0.85,
84
- top_k=40,
85
- repetition_penalty=1.15,
86
  pad_token_id=_LOCAL_TOKENIZER.eos_token_id,
87
  )
88
  t1 = time.perf_counter()
 
62
 
63
  _load_model(device, dtype)
64
 
65
+ messages = [{"role": "user", "content": prompt.strip()}]
 
 
 
66
  fmt = _LOCAL_TOKENIZER.apply_chat_template(messages, tokenize=False, add_generation_prompt=True)
67
  inputs = _LOCAL_TOKENIZER(fmt, return_tensors="pt").to(device)
68
 
69
  num_layers = getattr(_LOCAL_QWEN_MODEL.config, "num_hidden_layers", 24)
70
+ cache = KalpanaDynamicCache(num_layers=num_layers, bands=2048, sliding_window=128)
71
 
72
  t0 = time.perf_counter()
73
  with torch.inference_mode():
 
75
  **inputs,
76
  past_key_values=cache,
77
  max_new_tokens=int(max_tokens),
78
+ do_sample=(float(temperature) > 0),
79
+ temperature=float(temperature) if float(temperature) > 0 else 1.0,
80
+ top_p=0.9,
81
+ repetition_penalty=1.1,
 
82
  pad_token_id=_LOCAL_TOKENIZER.eos_token_id,
83
  )
84
  t1 = time.perf_counter()