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)
| 174 | |
| 175 | |
| 176 | def 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 | |
| 199 | def _apply_layer_skip_hook(module: torch.nn.Module, config: LayerSkipConfig, name: str | None = None) -> None: |
nothing calls this directly
no test coverage detected
searching dependent graphs…