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

Method compile

deepspeed/runtime/engine.py:6152–6242  ·  view source on GitHub ↗

Compile the module using the specified backend and kwargs. With ``compile.autoep_non_moe`` enabled in the DeepSpeed config, compile the callable parents of AutoEP layers while keeping routing, token movement, expert compute, and collectives eager. Otherwise, compile the full

(self,
                backend=get_accelerator().get_compile_backend(),
                compile_kwargs={},
                schedule=None,
                compiled_autograd_enabled=False)

Source from the content-addressed store, hash-verified

6150 return resolved_backend, schedule
6151
6152 def compile(self,
6153 backend=get_accelerator().get_compile_backend(),
6154 compile_kwargs={},
6155 schedule=None,
6156 compiled_autograd_enabled=False) -> None:
6157 """Compile the module using the specified backend and kwargs.
6158
6159 With ``compile.autoep_non_moe`` enabled in the DeepSpeed config, compile the
6160 callable parents of AutoEP layers while keeping routing, token movement,
6161 expert compute, and collectives eager. Otherwise, compile the full module.
6162 """
6163 # Avoid graph breaks
6164 deepspeed.utils.nvtx.enable_nvtx = False
6165
6166 if not is_compile_supported():
6167 raise RuntimeError("compile is not supported in your version of PyTorch.")
6168
6169 compile_mode = "autoep_non_moe" if self._config.compile_config.autoep_non_moe else "model"
6170
6171 if self.is_compiled:
6172 if self._compile_mode == compile_mode:
6173 return
6174 raise RuntimeError(
6175 "Engine is already compiled; compile.autoep_non_moe cannot be changed after compilation.")
6176
6177 if 'backend' in compile_kwargs:
6178 logger.warning("The `backend` in `compile_kwargs` will be overridden. Use the `backend` argument instead.")
6179
6180 logger.info(f"Compiling mode={compile_mode} deepcompile={self.is_deepcompile_enabled()} backend={backend}")
6181
6182 if compile_mode == "autoep_non_moe":
6183 if self.is_deepcompile_enabled():
6184 raise ValueError("compile.autoep_non_moe=True uses vanilla torch.compile and cannot be combined "
6185 "with DeepCompile.")
6186 autoep_config = getattr(self._config, "expert_parallel_config", None)
6187 if getattr(autoep_config, "comm_backend", "comm") != "comm":
6188 raise ValueError("compile.autoep_non_moe=True supports only expert_parallel.comm_backend='comm'.")
6189 if self.autotp_size() > 1:
6190 raise ValueError("compile.autoep_non_moe=True does not support AutoEP+AutoTP folding yet.")
6191 if self._autoep_sequence_parallel_world_size() > 1:
6192 raise ValueError("compile.autoep_non_moe=True does not support sequence parallelism yet.")
6193 folding_spec = getattr(self, "_autoep_folding_spec", None)
6194 if getattr(self, "pipeline_parallelism", False) or getattr(folding_spec, "pp_size", 1) > 1:
6195 raise ValueError("compile.autoep_non_moe=True does not support pipeline parallelism yet.")
6196 if self.zero_optimization_partition_weights():
6197 raise ValueError("compile.autoep_non_moe=True does not support ZeRO Stage 3 yet.")
6198 for offload_config in (self.zero_offload_optimizer(), self.zero_offload_param()):
6199 if offload_config is not None and offload_config.device != OffloadDeviceEnum.none:
6200 raise ValueError(
6201 "compile.autoep_non_moe=True does not support optimizer or parameter offload yet.")
6202 if schedule is not None:
6203 raise ValueError("compile.autoep_non_moe=True does not support DeepCompile schedules.")
6204 if compiled_autograd_enabled:
6205 raise ValueError("compile.autoep_non_moe=True does not support compiled autograd yet.")
6206 from .compiler import compile_autoep_non_moe_regions
6207 self._compiled_regions = compile_autoep_non_moe_regions(self.module, backend, compile_kwargs)
6208 self._is_compiled = True
6209 self._compile_mode = compile_mode