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

Method forward

deepspeed/inference/engine.py:588–615  ·  view source on GitHub ↗

Execute forward propagation Arguments: *inputs: Variable length input list **kwargs: variable length keyword arguments

(self, *inputs, **kwargs)

Source from the content-addressed store, hash-verified

586 return sub_module_cuda_graph
587
588 def forward(self, *inputs, **kwargs):
589 """Execute forward propagation
590
591 Arguments:
592 *inputs: Variable length input list
593 **kwargs: variable length keyword arguments
594 """
595 start = None
596 if self.model_profile_enabled and get_accelerator().device_name() == 'cuda' and self._config.enable_cuda_graph:
597 get_accelerator().synchronize()
598 start = time.time()
599
600 if get_accelerator().device_name() == 'cuda' and self._config.enable_cuda_graph and not self.local_cuda_graph:
601 if self.cuda_graph_created:
602 outputs = self._graph_replay(*inputs, **kwargs)
603 else:
604 self._create_cuda_graph(*inputs, **kwargs)
605 outputs = self._graph_replay(*inputs, **kwargs)
606
607 else:
608 outputs = self.module(*inputs, **kwargs)
609
610 if self.model_profile_enabled and self._config.enable_cuda_graph:
611 get_accelerator().synchronize()
612 duration = (time.time() - start) * 1e3 # convert seconds to ms
613 self._model_times.append(duration)
614
615 return outputs
616
617 def _generate(self, *inputs, **kwargs):
618 # Reset KV-cache at the beginning of generate

Callers

nothing calls this directly

Calls 6

_graph_replayMethod · 0.95
_create_cuda_graphMethod · 0.95
get_acceleratorFunction · 0.90
appendMethod · 0.80
device_nameMethod · 0.45
synchronizeMethod · 0.45

Tested by

no test coverage detected