MCPcopy Create free account
hub / github.com/OpenMOSS/MOSS / infer_

Method infer_

moss_inference.py:315–340  ·  view source on GitHub ↗

Inference method that computes logits and past key values. Args: input_ids (torch.Tensor): The input IDs tensor. attention_mask (torch.Tensor): The attention mask tensor. past_key_values (Optional[Tuple[torch.Tensor]]): The past key values tuple.

(
        self,
        input_ids: torch.Tensor,
        attention_mask: torch.Tensor,
        past_key_values: Optional[Tuple[torch.Tensor]],
    )

Source from the content-addressed store, hash-verified

313 return logits
314
315 def infer_(
316 self,
317 input_ids: torch.Tensor,
318 attention_mask: torch.Tensor,
319 past_key_values: Optional[Tuple[torch.Tensor]],
320 ) -> Tuple[torch.Tensor, Tuple[torch.Tensor]]:
321 """
322 Inference method that computes logits and past key values.
323
324 Args:
325 input_ids (torch.Tensor): The input IDs tensor.
326 attention_mask (torch.Tensor): The attention mask tensor.
327 past_key_values (Optional[Tuple[torch.Tensor]]): The past key values tuple.
328
329 Returns:
330 Tuple[torch.Tensor, Tuple[torch.Tensor]]: A tuple containing the logits and past key values.
331 """
332 inputs = {
333 "input_ids": input_ids,
334 "attention_mask": attention_mask,
335 "past_key_values": past_key_values,
336 }
337 with torch.no_grad():
338 outputs: BaseModelOutputWithPast = self.model(**inputs)
339
340 return outputs.logits, outputs.past_key_values
341
342 def __call__(self, input):
343 return self.forward(input)

Callers 1

streaming_topk_searchMethod · 0.95

Calls

no outgoing calls

Tested by

no test coverage detected