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

Method forward

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

3055
3056 @instrument_w_nvtx
3057 def forward(self, *inputs, **kwargs):
3058 r"""Execute forward propagation
3059 Arguments:
3060 *inputs: Variable length input list
3061 **kwargs: variable length keyword arguments
3062 """
3063 # Clear the backward seen flag at the start of each forward pass.
3064 # This is used to track multiple gradient hook phases with reentrant checkpointing.
3065 if isinstance(self.optimizer, ZeROOptimizer):
3066 self.optimizer.clear_backward_seen_flag()
3067
3068 if self.autotuning_profile_model_info():
3069 ma = get_ma_status()
3070
3071 if self.is_deepcompile_enabled() and not self.is_deepcompile_active() and not self.is_compiled:
3072 log_dist_once(
3073 "DeepCompile is enabled but engine.compile() has not been called; executing without DeepCompile until compile() runs.",
3074 ranks=[0])
3075
3076 if self.is_deepcompile_active() and hasattr(self, "launch_compile_passes"):
3077 # We can't have this in forward prologue as the compiler compiles hooks including the forward prologue.
3078 self.launch_compile_passes(self.global_steps)
3079
3080 with deepcompile_z3_forward_context(self) as z3_eager_fallback, autocast_if_enabled(self):
3081 loss = self.module(*inputs, **kwargs)
3082
3083 forward_graph_id = None
3084
3085 def backward_prologue():
3086 self._backward_prologue()
3087 if z3_eager_fallback is not None and forward_graph_id is not None:
3088 z3_eager_fallback.record_backward_start(forward_graph_id)
3089
3090 # Register output backward hooks
3091 # preprocess_once_fn is called for preprocessing
3092 # preprocess_per_tensor_fn scales a tensor for gradient accumulation
3093 hook_manager = register_output_backward_hooks(loss,
3094 preprocess_once_fn=backward_prologue,
3095 preprocess_per_tensor_fn=self._backward_prologue_per_tensor)
3096 if z3_eager_fallback is not None and hook_manager.hook_handles:
3097 forward_graph_id = z3_eager_fallback.record_forward_graph()
3098
3099 if self.autotuning_profile_model_info():
3100 activation_mem = get_ma_status() - ma
3101 self.autotuning_model_info["activation_mem_per_gpu"] = activation_mem
3102 print_json_dist(self.autotuning_model_info, [0], path=self.autotuning_model_info_path())
3103 exit()
3104
3105 return loss
3106
3107 def _cast_inputs_half(self, inputs):
3108 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