Diff Coverage

Diff: origin/master...HEAD, staged and unstaged changes

Source File Diff Coverage (%) Missing Lines
hyper_parallel/core/activation_checkpoint/swap.py 100%  
hyper_parallel/core/optimizer/swap_optimizer_base.py 100%  
hyper_parallel/core/pipeline_parallel/pipeline_swap.py 100%  
hyper_parallel/distributed/activation_checkpoint.py 100%  
hyper_parallel/distributed/attention_swap.py 13.0% 156-161,166-169,171-175,180,184-187
hyper_parallel/distributed/attention_swap.py
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
            "activation_swap must be one of ('none', 'attention'), "
            f"got {activation_swap!r}"
        )
    attention_targets = _find_attention_targets(model)
    wrapped_attentions: list[nn.Module] = []
    saved_refs: list[tuple[nn.Module, str, nn.Module]] = []
    try:
        for target in attention_targets:
            attention = target.module
            wrapped_attention = swap_wrapper(
                attention,
                policy_fn=attention_swap_policy,
                group_swap=True,
            )
            for parent, child_name in target.references:
                saved_refs.append((parent, child_name, getattr(parent, child_name)))
                setattr(parent, child_name, wrapped_attention)
            wrapped_attentions.append(wrapped_attention)

        swap_manager = SwapManager()
        for current_attention, next_attention in zip(wrapped_attentions, wrapped_attentions[1:]):
            swap_manager.set_forward_prefetch_layer(current_attention, next_attention)
        if wrapped_attentions:
            weakref.finalize(
                model,
                _teardown_wired_swap_layers,
                wrapped_attentions,
            )
    except Exception:
        # Partial failure: restore the original attention modules on every
        # reference already re-pointed, and release any swap wiring registered
        # by the chain loop before it raised (idempotent when none was).
        _teardown_wired_swap_layers(wrapped_attentions)
        for parent, child_name, original in saved_refs:
            setattr(parent, child_name, original)
        raise

    logger.info(
        "Enabled attention activation swap for %d module(s) in %s",
        len(wrapped_attentions),