Repository: huggingface/diffusers
File: src/diffusers/models/modeling_utils.py (Python)

Code before:
    def compile_repeated_blocks(self, *args, **kwargs):
        """
        Compiles *only* the frequently repeated sub-modules of a model (e.g. the
        Transformer layers) instead of compiling the entire model.  This
        technique—often called **regional compilation** (see the PyTorch recipe
        https://docs.pytorch.org/tutorials/recipes/regional_compilation.html)
        can reduce end-to-end compile time substantially, while preserving the
        runtime speed-ups you would expect from a full `torch.compile`.

        The set of sub-modules to compile is discovered in one of two ways:

        1. **`_repeated_blocks`** – Preferred.  Define this attribute on your
        subclass as a list/tuple of class names (strings).  Every module whose
        class name matches will be compiled.

        2. **`_no_split_modules`** – Fallback.  If the preferred attribute is
        missing or empty, we fall back to the legacy Diffusers attribute
        `_no_split_modules`.

        Once discovered, each matching sub-module is compiled by calling
        ``submodule.compile(*args, **kwargs)``.  Any positional or keyword
        arguments you supply to :meth:`compile_repeated_blocks` are forwarded
        verbatim to `torch.compile`.
        """
        repeated_blocks = getattr(self, "_repeated_blocks", None)

        if not repeated_blocks:
            logger.warning("_repeated_blocks attribute is empty. Using _no_split_modules to find compile regions.")

            repeated_blocks = getattr(self, "_no_split_modules", None)

        if not repeated_blocks:
            raise ValueError(
                "Both _repeated_blocks and _no_split_modules attribute are empty. "
                "Set _repeated_blocks for the model to benefit from faster compilation. "
            )

        has_compiled_region = False
        for submod in self.modules():
            if submod.__class__.__name__ in repeated_blocks:
                has_compiled_region = True
                submod.compile(*args, **kwargs)

        if not has_compiled_region:
            raise ValueError(
                f"Regional compilation failed because {repeated_blocks} classes are not found in the model. "
            )

    @classmethod
    def _load_pretrained_model(
        cls,

Review comment (suggestion):
```suggestion
            raise ValueError(
                "Both `_repeated_blocks` and `_no_split_modules` attribute are empty. "
                "Set `_repeated_blocks` for the model to benefit from faster compilation. "
            )
```

Code after:
    def compile_repeated_blocks(self, *args, **kwargs):
        """
        Compiles *only* the frequently repeated sub-modules of a model (e.g. the Transformer layers) instead of
        compiling the entire model. This technique—often called **regional compilation** (see the PyTorch recipe
        https://docs.pytorch.org/tutorials/recipes/regional_compilation.html) can reduce end-to-end compile time
        substantially, while preserving the runtime speed-ups you would expect from a full `torch.compile`.

        The set of sub-modules to compile is discovered by the presence of **`_repeated_blocks`** attribute in the
        model definition. Define this attribute on your model subclass as a list/tuple of class names (strings). Every
        module whose class name matches will be compiled.

        Once discovered, each matching sub-module is compiled by calling `submodule.compile(*args, **kwargs)`. Any
        positional or keyword arguments you supply to `compile_repeated_blocks` are forwarded verbatim to
        `torch.compile`.
        """
        repeated_blocks = getattr(self, "_repeated_blocks", None)

        if not repeated_blocks:
            raise ValueError(
                "`_repeated_blocks` attribute is empty. "
                f"Set `_repeated_blocks` for the class `{self.__class__.__name__}` to benefit from faster compilation. "
            )
        has_compiled_region = False
        for submod in self.modules():
            if submod.__class__.__name__ in repeated_blocks:
                submod.compile(*args, **kwargs)
                has_compiled_region = True

        if not has_compiled_region:
            raise ValueError(
                f"Regional compilation failed because {repeated_blocks} classes are not found in the model. "
            )

    @classmethod
    def _load_pretrained_model(
        cls,
        model,
        state_dict: OrderedDict,
        resolved_model_file: List[str],
        pretrained_model_name_or_path: Union[str, os.PathLike],
        loaded_keys: List[str],
        ignore_mismatched_sizes: bool = False,
        assign_to_params_buffers: bool = False,
        hf_quantizer: Optional[DiffusersQuantizer] = None,
        low_cpu_mem_usage: bool = True,
        dtype: Optional[Union[str, torch.dtype]] = None,
        keep_in_fp32_modules: Optional[List[str]] = None,
        device_map: Union[str, int, torch.device, Dict[str, Union[int, str, torch.device]]] = None,
        offload_state_dict: Optional[bool] = None,
        offload_folder: Optional[Union[str, os.PathLike]] = None,
        dduf_entries: Optional[Dict[str, DDUFEntry]] = None,