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)
| 6051 | return resolved_backend, schedule |
| 6052 | |
| 6053 | def compile(self, |
| 6054 | backend=get_accelerator().get_compile_backend(), |
| 6055 | compile_kwargs={}, |
| 6056 | schedule=None, |
| 6057 | compiled_autograd_enabled=False) -> None: |
| 6058 | """Compile the module using the specified backend and kwargs. |
| 6059 | |
| 6060 | With ``compile.autoep_non_moe`` enabled in the DeepSpeed config, compile the |
| 6061 | callable parents of AutoEP layers while keeping routing, token movement, |
| 6062 | expert compute, and collectives eager. Otherwise, compile the full module. |
| 6063 | """ |
| 6064 | # Avoid graph breaks |
| 6065 | deepspeed.utils.nvtx.enable_nvtx = False |
| 6066 | |
| 6067 | if not is_compile_supported(): |
| 6068 | raise RuntimeError("compile is not supported in your version of PyTorch.") |
| 6069 | |
| 6070 | compile_mode = "autoep_non_moe" if self._config.compile_config.autoep_non_moe else "model" |
| 6071 | |
| 6072 | if self.is_compiled: |
| 6073 | if self._compile_mode == compile_mode: |
| 6074 | return |
| 6075 | raise RuntimeError( |
| 6076 | "Engine is already compiled; compile.autoep_non_moe cannot be changed after compilation.") |
| 6077 | |
| 6078 | if 'backend' in compile_kwargs: |
| 6079 | logger.warning("The `backend` in `compile_kwargs` will be overridden. Use the `backend` argument instead.") |
| 6080 | |
| 6081 | logger.info(f"Compiling mode={compile_mode} deepcompile={self.is_deepcompile_enabled()} backend={backend}") |
| 6082 | |
| 6083 | if compile_mode == "autoep_non_moe": |
| 6084 | if self.is_deepcompile_enabled(): |
| 6085 | raise ValueError("compile.autoep_non_moe=True uses vanilla torch.compile and cannot be combined " |
| 6086 | "with DeepCompile.") |
| 6087 | autoep_config = getattr(self._config, "expert_parallel_config", None) |
| 6088 | if getattr(autoep_config, "comm_backend", "comm") != "comm": |
| 6089 | raise ValueError("compile.autoep_non_moe=True supports only expert_parallel.comm_backend='comm'.") |
| 6090 | if self.autotp_size() > 1: |
| 6091 | raise ValueError("compile.autoep_non_moe=True does not support AutoEP+AutoTP folding yet.") |
| 6092 | if self._autoep_sequence_parallel_world_size() > 1: |
| 6093 | raise ValueError("compile.autoep_non_moe=True does not support sequence parallelism yet.") |
| 6094 | folding_spec = getattr(self, "_autoep_folding_spec", None) |
| 6095 | if getattr(self, "pipeline_parallelism", False) or getattr(folding_spec, "pp_size", 1) > 1: |
| 6096 | raise ValueError("compile.autoep_non_moe=True does not support pipeline parallelism yet.") |
| 6097 | if self.zero_optimization_partition_weights(): |
| 6098 | raise ValueError("compile.autoep_non_moe=True does not support ZeRO Stage 3 yet.") |
| 6099 | for offload_config in (self.zero_offload_optimizer(), self.zero_offload_param()): |
| 6100 | if offload_config is not None and offload_config.device != OffloadDeviceEnum.none: |
| 6101 | raise ValueError( |
| 6102 | "compile.autoep_non_moe=True does not support optimizer or parameter offload yet.") |
| 6103 | if schedule is not None: |
| 6104 | raise ValueError("compile.autoep_non_moe=True does not support DeepCompile schedules.") |
| 6105 | if compiled_autograd_enabled: |
| 6106 | raise ValueError("compile.autoep_non_moe=True does not support compiled autograd yet.") |
| 6107 | from .compiler import compile_autoep_non_moe_regions |
| 6108 | self._compiled_regions = compile_autoep_non_moe_regions(self.module, backend, compile_kwargs) |
| 6109 | self._is_compiled = True |
| 6110 | self._compile_mode = compile_mode |