r"""Execute forward propagation Arguments: *inputs: Variable length input list **kwargs: variable length keyword arguments
(self, *inputs, **kwargs)
| 3128 | |
| 3129 | @instrument_w_nvtx |
| 3130 | def forward(self, *inputs, **kwargs): |
| 3131 | r"""Execute forward propagation |
| 3132 | Arguments: |
| 3133 | *inputs: Variable length input list |
| 3134 | **kwargs: variable length keyword arguments |
| 3135 | """ |
| 3136 | # Clear the backward seen flag at the start of each forward pass. |
| 3137 | # This is used to track multiple gradient hook phases with reentrant checkpointing. |
| 3138 | if isinstance(self.optimizer, ZeROOptimizer): |
| 3139 | self.optimizer.clear_backward_seen_flag() |
| 3140 | |
| 3141 | if self.autotuning_profile_model_info(): |
| 3142 | ma = get_ma_status() |
| 3143 | |
| 3144 | if self.is_deepcompile_enabled() and not self.is_deepcompile_active() and not self.is_compiled: |
| 3145 | log_dist_once( |
| 3146 | "DeepCompile is enabled but engine.compile() has not been called; executing without DeepCompile until compile() runs.", |
| 3147 | ranks=[0]) |
| 3148 | |
| 3149 | if self.is_deepcompile_active() and hasattr(self, "launch_compile_passes"): |
| 3150 | # We can't have this in forward prologue as the compiler compiles hooks including the forward prologue. |
| 3151 | self.launch_compile_passes(self.global_steps) |
| 3152 | |
| 3153 | with deepcompile_z3_forward_context(self) as z3_eager_fallback, autocast_if_enabled(self): |
| 3154 | loss = self.module(*inputs, **kwargs) |
| 3155 | |
| 3156 | forward_graph_id = None |
| 3157 | |
| 3158 | def backward_prologue(): |
| 3159 | self._backward_prologue() |
| 3160 | if z3_eager_fallback is not None and forward_graph_id is not None: |
| 3161 | z3_eager_fallback.record_backward_start(forward_graph_id) |
| 3162 | |
| 3163 | # Register output backward hooks |
| 3164 | # preprocess_once_fn is called for preprocessing |
| 3165 | # preprocess_per_tensor_fn scales a tensor for gradient accumulation |
| 3166 | hook_manager = register_output_backward_hooks(loss, |
| 3167 | preprocess_once_fn=backward_prologue, |
| 3168 | preprocess_per_tensor_fn=self._backward_prologue_per_tensor) |
| 3169 | if z3_eager_fallback is not None and hook_manager.hook_handles: |
| 3170 | forward_graph_id = z3_eager_fallback.record_forward_graph() |
| 3171 | |
| 3172 | if self.autotuning_profile_model_info(): |
| 3173 | activation_mem = get_ma_status() - ma |
| 3174 | self.autotuning_model_info["activation_mem_per_gpu"] = activation_mem |
| 3175 | print_json_dist(self.autotuning_model_info, [0], path=self.autotuning_model_info_path()) |
| 3176 | exit() |
| 3177 | |
| 3178 | return loss |
| 3179 | |
| 3180 | def _cast_inputs_half(self, inputs): |
| 3181 | if isinstance(inputs, (list, tuple)): |
nothing calls this directly
no test coverage detected