MCPcopy Create free account
hub / github.com/huggingface/diffusers / apply_layer_skip

Function apply_layer_skip

src/diffusers/hooks/layer_skip.py:176–196  ·  view source on GitHub ↗

r""" Apply layer skipping to internal layers of a transformer. Args: module (`torch.nn.Module`): The transformer model to which the layer skip hook should be applied. config (`LayerSkipConfig`): The configuration for the layer skip hook. Example:

(module: torch.nn.Module, config: LayerSkipConfig)

Source from the content-addressed store, hash-verified

174
175
176def apply_layer_skip(module: torch.nn.Module, config: LayerSkipConfig) -> None:
177 r"""
178 Apply layer skipping to internal layers of a transformer.
179
180 Args:
181 module (`torch.nn.Module`):
182 The transformer model to which the layer skip hook should be applied.
183 config (`LayerSkipConfig`):
184 The configuration for the layer skip hook.
185
186 Example:
187
188 ```python
189 >>> from diffusers import apply_layer_skip_hook, CogVideoXTransformer3DModel, LayerSkipConfig
190
191 >>> transformer = CogVideoXTransformer3DModel.from_pretrained("THUDM/CogVideoX-5b", torch_dtype=torch.bfloat16)
192 >>> config = LayerSkipConfig(layer_index=[10, 20], fqn="transformer_blocks")
193 >>> apply_layer_skip_hook(transformer, config)
194 ```
195 """
196 _apply_layer_skip_hook(module, config)
197
198
199def _apply_layer_skip_hook(module: torch.nn.Module, config: LayerSkipConfig, name: str | None = None) -> None:

Callers

nothing calls this directly

Calls 1

_apply_layer_skip_hookFunction · 0.85

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…