Vision-CAIR commited on
Commit
a79e6ff
β€’
1 Parent(s): d1a6bf6

Update minigpt4/conversation/conversation.py

Browse files
minigpt4/conversation/conversation.py CHANGED
@@ -135,9 +135,14 @@ class Chat:
135
  conv.append_message(conv.roles[0], text)
136
 
137
  def answer(self, conv, img_list, max_new_tokens=200, num_beams=5, min_length=1, top_p=0.9,
138
- repetition_penalty=1.0, length_penalty=1, temperature=1):
139
  conv.append_message(conv.roles[1], None)
140
  embs = self.get_context_emb(conv, img_list)
 
 
 
 
 
141
  outputs = self.model.llama_model.generate(
142
  inputs_embeds=embs,
143
  max_new_tokens=max_new_tokens,
 
135
  conv.append_message(conv.roles[0], text)
136
 
137
  def answer(self, conv, img_list, max_new_tokens=200, num_beams=5, min_length=1, top_p=0.9,
138
+ repetition_penalty=1.0, length_penalty=1, temperature=1, max_length=2000):
139
  conv.append_message(conv.roles[1], None)
140
  embs = self.get_context_emb(conv, img_list)
141
+
142
+ current_max_len = embs.shape[1] + max_new_tokens
143
+ if current_max_len - max_length + 100 > 0:
144
+ begin_idx = max(0, current_max_len - max_length)
145
+ embs = embs[:, begin_idx:]
146
  outputs = self.model.llama_model.generate(
147
  inputs_embeds=embs,
148
  max_new_tokens=max_new_tokens,