(module: torch.nn.Module, plan: dict[str, ContextParallelModelPlan])
| 110 | |
| 111 | |
| 112 | def 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 | |
| 129 | class ContextParallelSplitHook(ModelHook): |
nothing calls this directly
no test coverage detected
searching dependent graphs…