ciyidogan commited on
Commit
af7f9a1
·
verified ·
1 Parent(s): 4113d2a

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +16 -4
app.py CHANGED
@@ -65,13 +65,24 @@ def generate(req: UserInputRequest):
65
  {"role": "user", "content": req.user_input}
66
  ]
67
 
68
- chat_input = tokenizer.apply_chat_template(
 
69
  messages,
70
  add_generation_prompt=True,
71
- return_tensors="pt"
 
 
 
 
 
 
 
72
  ).to(model.device)
73
 
74
- input_len = chat_input.shape[-1]
 
 
 
75
  total_ctx = model.config.max_position_embeddings if hasattr(model.config, 'max_position_embeddings') else 4096
76
  max_new_tokens = max(1, total_ctx - input_len)
77
 
@@ -83,7 +94,8 @@ def generate(req: UserInputRequest):
83
  ]
84
 
85
  outputs = model.generate(
86
- input_ids=chat_input,
 
87
  max_new_tokens=max_new_tokens,
88
  eos_token_id=terminators
89
  )
 
65
  {"role": "user", "content": req.user_input}
66
  ]
67
 
68
+ # === Önce chat template string'ini al
69
+ chat_template_str = tokenizer.apply_chat_template(
70
  messages,
71
  add_generation_prompt=True,
72
+ return_tensors=None
73
+ )
74
+
75
+ # === Sonra tokenizer() ile input_ids + attention_mask hazırla
76
+ tokenized_inputs = tokenizer(
77
+ chat_template_str,
78
+ return_tensors="pt",
79
+ padding=True
80
  ).to(model.device)
81
 
82
+ input_ids = tokenized_inputs['input_ids']
83
+ attention_mask = tokenized_inputs['attention_mask']
84
+
85
+ input_len = input_ids.shape[-1]
86
  total_ctx = model.config.max_position_embeddings if hasattr(model.config, 'max_position_embeddings') else 4096
87
  max_new_tokens = max(1, total_ctx - input_len)
88
 
 
94
  ]
95
 
96
  outputs = model.generate(
97
+ input_ids=input_ids,
98
+ attention_mask=attention_mask,
99
  max_new_tokens=max_new_tokens,
100
  eos_token_id=terminators
101
  )