Curious-PM commited on
Commit
f21e85d
·
verified ·
1 Parent(s): eef18b5

Upload app.py with huggingface_hub

Browse files
Files changed (1) hide show
  1. app.py +10 -5
app.py CHANGED
@@ -37,18 +37,23 @@ def generate_reply(question):
37
  {"role": "system", "content": SYSTEM_PROMPT},
38
  {"role": "user", "content": question.strip()},
39
  ]
40
- inputs = tokenizer.apply_chat_template(
41
- msgs, return_tensors="pt", add_generation_prompt=True
42
- ).to("cuda")
 
 
43
  model.to("cuda")
44
  with torch.no_grad():
45
  out = model.generate(
46
- inputs,
47
  max_new_tokens=600,
48
  do_sample=False,
49
  pad_token_id=tokenizer.eos_token_id,
50
  )
51
- reply = tokenizer.decode(out[0][inputs.shape[1]:], skip_special_tokens=True)
 
 
 
52
  return reply
53
 
54
 
 
37
  {"role": "system", "content": SYSTEM_PROMPT},
38
  {"role": "user", "content": question.strip()},
39
  ]
40
+ # Two-step tokenization for safe unpacking with model.generate(**inputs)
41
+ text = tokenizer.apply_chat_template(
42
+ msgs, tokenize=False, add_generation_prompt=True
43
+ )
44
+ inputs = tokenizer(text, return_tensors="pt").to("cuda")
45
  model.to("cuda")
46
  with torch.no_grad():
47
  out = model.generate(
48
+ **inputs,
49
  max_new_tokens=600,
50
  do_sample=False,
51
  pad_token_id=tokenizer.eos_token_id,
52
  )
53
+ reply = tokenizer.decode(
54
+ out[0][inputs.input_ids.shape[1]:],
55
+ skip_special_tokens=True,
56
+ )
57
  return reply
58
 
59