MCPcopy Create free account
hub / github.com/OpenDriveLab/ReSim / chat

Method chat

SwissArmyTransformer/examples/chatglm2/chat_model.py:162–177  ·  view source on GitHub ↗
(self, tokenizer, query: str, history: List[Tuple[str, str]] = None, max_length: int = 8192, num_beams=1,
             do_sample=True, top_p=0.8, temperature=0.8, logits_processor=None, **kwargs)

Source from the content-addressed store, hash-verified

160
161 @torch.no_grad()
162 def chat(self, tokenizer, query: str, history: List[Tuple[str, str]] = None, max_length: int = 8192, num_beams=1,
163 do_sample=True, top_p=0.8, temperature=0.8, logits_processor=None, **kwargs):
164 if history is None:
165 history = []
166 if logits_processor is None:
167 logits_processor = LogitsProcessorList()
168 logits_processor.append(InvalidScoreLogitsProcessor())
169 gen_kwargs = {"max_length": max_length, "num_beams": num_beams, "do_sample": do_sample, "top_p": top_p,
170 "temperature": temperature, "logits_processor": logits_processor, **kwargs}
171 inputs = self.build_inputs(tokenizer, query, history=history)
172 outputs = self.generate(**inputs, **gen_kwargs)
173 outputs = outputs.tolist()[0][len(inputs["input_ids"][0]):]
174 response = tokenizer.decode(outputs)
175 response = self.process_response(response)
176 history = history + [(query, response)]
177 return response, history
178
179 @torch.no_grad()
180 def batch_generate(self, tokenizer, queries, max_length: int = 8192, num_beams=1,

Callers 2

chat.pyFile · 0.45
inference_adgen.pyFile · 0.45

Calls 5

build_inputsMethod · 0.95
process_responseMethod · 0.95
appendMethod · 0.80
decodeMethod · 0.45

Tested by

no test coverage detected