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

Method forward

deepspeed/runtime/engine.py:3158–3206  ·  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

3156
3157 @instrument_w_nvtx
3158 def forward(self, *inputs, **kwargs):
3159 r"""Execute forward propagation
3160 Arguments:
3161 *inputs: Variable length input list
3162 **kwargs: variable length keyword arguments
3163 """
3164 # Clear the backward seen flag at the start of each forward pass.
3165 # This is used to track multiple gradient hook phases with reentrant checkpointing.
3166 if isinstance(self.optimizer, ZeROOptimizer):
3167 self.optimizer.clear_backward_seen_flag()
3168
3169 if self.autotuning_profile_model_info():
3170 ma = get_ma_status()
3171
3172 if self.is_deepcompile_enabled() and not self.is_deepcompile_active() and not self.is_compiled:
3173 log_dist_once(
3174 "DeepCompile is enabled but engine.compile() has not been called; executing without DeepCompile until compile() runs.",
3175 ranks=[0])
3176
3177 if self.is_deepcompile_active() and hasattr(self, "launch_compile_passes"):
3178 # We can't have this in forward prologue as the compiler compiles hooks including the forward prologue.
3179 self.launch_compile_passes(self.global_steps)
3180
3181 with deepcompile_z3_forward_context(self) as z3_eager_fallback, autocast_if_enabled(self):
3182 loss = self.module(*inputs, **kwargs)
3183
3184 forward_graph_id = None
3185
3186 def backward_prologue():
3187 self._backward_prologue()
3188 if z3_eager_fallback is not None and forward_graph_id is not None:
3189 z3_eager_fallback.record_backward_start(forward_graph_id)
3190
3191 # Register output backward hooks
3192 # preprocess_once_fn is called for preprocessing
3193 # preprocess_per_tensor_fn scales a tensor for gradient accumulation
3194 hook_manager = register_output_backward_hooks(loss,
3195 preprocess_once_fn=backward_prologue,
3196 preprocess_per_tensor_fn=self._backward_prologue_per_tensor)
3197 if z3_eager_fallback is not None and hook_manager.hook_handles:
3198 forward_graph_id = z3_eager_fallback.record_forward_graph()
3199
3200 if self.autotuning_profile_model_info():
3201 activation_mem = get_ma_status() - ma
3202 self.autotuning_model_info["activation_mem_per_gpu"] = activation_mem
3203 print_json_dist(self.autotuning_model_info, [0], path=self.autotuning_model_info_path())
3204 exit()
3205
3206 return loss
3207
3208 def _cast_inputs_half(self, inputs):
3209 if isinstance(inputs, (list, tuple)):

Callers

nothing calls this directly

Calls 12

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
record_forward_graphMethod · 0.80

Tested by

no test coverage detected