Atsatoru commited on
Commit
739739a
·
verified ·
1 Parent(s): 40d1cb8

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +4 -2
app.py CHANGED
@@ -1223,17 +1223,19 @@ HÃY TRẢ LỜI NGƯỜI DÂNG:"""
1223
 
1224
  # Bước 9: Generate response với dynamic temperature - dùng model.generate trực tiếp
1225
  inputs = tokenizer(text_prompt, return_tensors="pt").to(model.device)
 
1226
 
1227
  outputs = model.generate(
1228
  **inputs,
1229
- max_new_tokens=256, # Giảm từ 768 xuống 256 để nhanh hơn
1230
  temperature=temperature,
1231
  top_p=0.9,
1232
  repetition_penalty=1.15,
1233
  do_sample=temperature > 0.2
1234
  )
1235
 
1236
- response_text = tokenizer.decode(outputs[0], skip_special_tokens=True)
 
1237
 
1238
  # Clean response
1239
  if "<|im_start|>assistant\n" in response_text:
 
1223
 
1224
  # Bước 9: Generate response với dynamic temperature - dùng model.generate trực tiếp
1225
  inputs = tokenizer(text_prompt, return_tensors="pt").to(model.device)
1226
+ input_length = inputs.input_ids.shape[1] # Lấy độ dài của prompt đầu vào
1227
 
1228
  outputs = model.generate(
1229
  **inputs,
1230
+ max_new_tokens=512, # Tăng lên một chút để tránh bị cắt chữ
1231
  temperature=temperature,
1232
  top_p=0.9,
1233
  repetition_penalty=1.15,
1234
  do_sample=temperature > 0.2
1235
  )
1236
 
1237
+ # CHỈ giải mã những token mới (phần sau input_length)
1238
+ response_text = tokenizer.decode(outputs[0][input_length:], skip_special_tokens=True)
1239
 
1240
  # Clean response
1241
  if "<|im_start|>assistant\n" in response_text: