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

Method forward

deepspeed/runtime/engine.py:2675–2714  ·  view source on GitHub ↗

r"""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

2673
2674 @instrument_w_nvtx
2675 def forward(self, *inputs, **kwargs):
2676 r"""Execute forward propagation
2677 Arguments:
2678 *inputs: Variable length input list
2679 **kwargs: variable length keyword arguments
2680 """
2681 # Clear the backward seen flag at the start of each forward pass.
2682 # This is used to track multiple gradient hook phases with reentrant checkpointing.
2683 if isinstance(self.optimizer, ZeROOptimizer):
2684 self.optimizer.clear_backward_seen_flag()
2685
2686 if self.autotuning_profile_model_info():
2687 ma = get_ma_status()
2688
2689 if self.is_deepcompile_enabled() and not self.is_deepcompile_active() and not self.is_compiled:
2690 log_dist_once(
2691 "DeepCompile is enabled but engine.compile() has not been called; executing without DeepCompile until compile() runs.",
2692 ranks=[0])
2693
2694 if self.is_deepcompile_active() and hasattr(self, "launch_compile_passes"):
2695 # We can't have this in forward prologue as the compiler compiles hooks including the forward prologue.
2696 self.launch_compile_passes(self.global_steps)
2697
2698 with deepcompile_z3_forward_context(self), autocast_if_enabled(self):
2699 loss = self.module(*inputs, **kwargs)
2700
2701 # Register output backward hooks
2702 # preprocess_once_fn is called for preprocessing
2703 # preprocess_per_tensor_fn scales a tensor for gradient accumulation
2704 register_output_backward_hooks(loss,
2705 preprocess_once_fn=self._backward_prologue,
2706 preprocess_per_tensor_fn=self._backward_prologue_per_tensor)
2707
2708 if self.autotuning_profile_model_info():
2709 activation_mem = get_ma_status() - ma
2710 self.autotuning_model_info["activation_mem_per_gpu"] = activation_mem
2711 print_json_dist(self.autotuning_model_info, [0], path=self.autotuning_model_info_path())
2712 exit()
2713
2714 return loss
2715
2716 def _cast_inputs_half(self, inputs):
2717 if isinstance(inputs, (list, tuple)):

Callers

nothing calls this directly

Calls 11

is_deepcompile_activeMethod · 0.95
log_dist_onceFunction · 0.90
autocast_if_enabledFunction · 0.90
print_json_distFunction · 0.90
get_ma_statusFunction · 0.85

Tested by

no test coverage detected