MCPcopy Create free account
hub / github.com/deepspeedai/DeepSpeed / _generate

Method _generate

deepspeed/inference/engine.py:617–640  ·  view source on GitHub ↗
(self, *inputs, **kwargs)

Source from the content-addressed store, hash-verified

615 return outputs
616
617 def _generate(self, *inputs, **kwargs):
618 # Reset KV-cache at the beginning of generate
619 if hasattr(self.module, 'reset_cache'):
620 self.module.reset_cache()
621 num_beams = 1
622 if "generation_config" in kwargs:
623 gen_config = kwargs["generation_config"]
624 num_beams = getattr(gen_config, "num_beams", 1)
625 if "num_beams" in kwargs:
626 num_beams = kwargs["num_beams"]
627
628 if num_beams > 1:
629 raise NotImplementedError("DeepSpeed does not support `num_beams` > 1, if this is important to you please "
630 "add your request to: https://github.com/deepspeedai/DeepSpeed/issues/2506")
631
632 if ("input_ids" in kwargs) and (kwargs["input_ids"].dim() == 2):
633 for input_tensor in kwargs["input_ids"]:
634 tensor_length = input_tensor.shape[-1]
635 if tensor_length > self._config.max_out_tokens:
636 raise RuntimeError(
637 f"Input with size {tensor_length} exceeds maximum length of {self._config.max_out_tokens}. Please increase max_tokens in the DeepSpeed Inference Config."
638 )
639
640 return self.module.generate(*inputs, **kwargs)
641
642 def compile(self, backend=get_accelerator().get_compile_backend(), compile_kwargs={}) -> None:
643 """

Callers 1

generateMethod · 0.45

Calls 2

reset_cacheMethod · 0.45
generateMethod · 0.45

Tested by

no test coverage detected