MCPcopy Index your code
hub / github.com/huggingface/diffusers / remove_context_parallel

Function remove_context_parallel

src/diffusers/hooks/context_parallel.py:112–126  ·  view source on GitHub ↗
(module: torch.nn.Module, plan: dict[str, ContextParallelModelPlan])

Source from the content-addressed store, hash-verified

110
111
112def remove_context_parallel(module: torch.nn.Module, plan: dict[str, ContextParallelModelPlan]) -> None:
113 for module_id, cp_model_plan in plan.items():
114 submodule = _get_submodule_by_name(module, module_id)
115 if not isinstance(submodule, list):
116 submodule = [submodule]
117
118 for m in submodule:
119 registry = HookRegistry.check_if_exists_or_initialize(m)
120 if isinstance(cp_model_plan, dict):
121 hook_name = _CONTEXT_PARALLEL_INPUT_HOOK_TEMPLATE.format(module_id)
122 elif isinstance(cp_model_plan, (ContextParallelOutput, list, tuple)):
123 hook_name = _CONTEXT_PARALLEL_OUTPUT_HOOK_TEMPLATE.format(module_id)
124 else:
125 raise ValueError(f"Unsupported context parallel model plan type: {type(cp_model_plan)}")
126 registry.remove_hook(hook_name)
127
128
129class ContextParallelSplitHook(ModelHook):

Callers

nothing calls this directly

Calls 3

_get_submodule_by_nameFunction · 0.85
remove_hookMethod · 0.80

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…