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)
| 5948 | return resolved_backend, schedule |
| 5949 | |
| 5950 | def compile(self, |
| 5951 | backend=get_accelerator().get_compile_backend(), |
| 5952 | compile_kwargs={}, |
| 5953 | schedule=None, |
| 5954 | compiled_autograd_enabled=False) -> None: |
| 5955 | """Compile the module using the specified backend and kwargs. |
| 5956 | |
| 5957 | With ``compile.autoep_non_moe`` enabled in the DeepSpeed config, compile the |
| 5958 | callable parents of AutoEP layers while keeping routing, token movement, |
| 5959 | expert compute, and collectives eager. Otherwise, compile the full module. |
| 5960 | """ |
| 5961 | # Avoid graph breaks |
| 5962 | deepspeed.utils.nvtx.enable_nvtx = False |
| 5963 | |
| 5964 | if not is_compile_supported(): |
| 5965 | raise RuntimeError("compile is not supported in your version of PyTorch.") |
| 5966 | |
| 5967 | compile_mode = "autoep_non_moe" if self._config.compile_config.autoep_non_moe else "model" |
| 5968 | |
| 5969 | if self.is_compiled: |
| 5970 | if self._compile_mode == compile_mode: |
| 5971 | return |
| 5972 | raise RuntimeError( |
| 5973 | "Engine is already compiled; compile.autoep_non_moe cannot be changed after compilation.") |
| 5974 | |
| 5975 | if 'backend' in compile_kwargs: |
| 5976 | logger.warning("The `backend` in `compile_kwargs` will be overridden. Use the `backend` argument instead.") |
| 5977 | |
| 5978 | logger.info(f"Compiling mode={compile_mode} deepcompile={self.is_deepcompile_enabled()} backend={backend}") |
| 5979 | |
| 5980 | if compile_mode == "autoep_non_moe": |
| 5981 | if self.is_deepcompile_enabled(): |
| 5982 | raise ValueError("compile.autoep_non_moe=True uses vanilla torch.compile and cannot be combined " |
| 5983 | "with DeepCompile.") |
| 5984 | autoep_config = getattr(self._config, "expert_parallel_config", None) |
| 5985 | if getattr(autoep_config, "comm_backend", "comm") != "comm": |
| 5986 | raise ValueError("compile.autoep_non_moe=True supports only expert_parallel.comm_backend='comm'.") |
| 5987 | if self.autotp_size() > 1: |
| 5988 | raise ValueError("compile.autoep_non_moe=True does not support AutoEP+AutoTP folding yet.") |
| 5989 | if self._autoep_sequence_parallel_world_size() > 1: |
| 5990 | raise ValueError("compile.autoep_non_moe=True does not support sequence parallelism yet.") |
| 5991 | folding_spec = getattr(self, "_autoep_folding_spec", None) |
| 5992 | if getattr(self, "pipeline_parallelism", False) or getattr(folding_spec, "pp_size", 1) > 1: |
| 5993 | raise ValueError("compile.autoep_non_moe=True does not support pipeline parallelism yet.") |
| 5994 | if self.zero_optimization_partition_weights(): |
| 5995 | raise ValueError("compile.autoep_non_moe=True does not support ZeRO Stage 3 yet.") |
| 5996 | for offload_config in (self.zero_offload_optimizer(), self.zero_offload_param()): |
| 5997 | if offload_config is not None and offload_config.device != OffloadDeviceEnum.none: |
| 5998 | raise ValueError( |
| 5999 | "compile.autoep_non_moe=True does not support optimizer or parameter offload yet.") |
| 6000 | if schedule is not None: |
| 6001 | raise ValueError("compile.autoep_non_moe=True does not support DeepCompile schedules.") |
| 6002 | if compiled_autograd_enabled: |
| 6003 | raise ValueError("compile.autoep_non_moe=True does not support compiled autograd yet.") |
| 6004 | from .compiler import compile_autoep_non_moe_regions |
| 6005 | self._compiled_regions = compile_autoep_non_moe_regions(self.module, backend, compile_kwargs) |
| 6006 | self._is_compiled = True |
| 6007 | self._compile_mode = compile_mode |