Skip to content

Rebasin Methods API

This page is generated from the registered task-vector transport class docstrings and signatures. For defaults, accepted values, and parameter behavior, see the method configuration reference.

Identity

No-op transport: Δ' = Δ (restricted to compatible shared keys).

Optional module_scope ("mlp" | "attn") and exclude_first_last_layer kwargs (settable via a config's method_params) additionally restrict which keys carry the delta -- everything left out simply keeps the target's own weight (see merge/runtime.apply_delta), so e.g. module_scope="mlp" + exclude_first_last_layer=true adds the task vector to nothing but the inner layers' MLP weights.

Orthogonal Shift

Transport that removes the component of Δ along the base-shift direction

s = target_base - source_base Δ' = Δ - beta * proj_s(Δ)

When beta=1.0 this yields a delta orthogonal to s (per-parameter tensor block).

GradFix

GradFix rebase method.

Implements PreparedTransportMethod: - prepare: compute gradient signs from target model + dataloader - apply: mask a delta using precomputed gradient signs - transport: prepare + apply in one call

All model-specific logic is delegated to a gradient recipe (models.grad_recipes). GradFixRebase itself is model-agnostic.

Config knobs (passed via method_params or **kwargs): - mask_mode: "normal" | "force" (default "normal") - vote: "mean" | "majority" | "max" (default "mean")

prepare(*, target_model, target_dataloader, recipe, device='cuda', vote='mean', **kwargs)

Compute gradient signs from target model + data.

Parameters

target_model : The target base model. target_dataloader : Data from the target domain. recipe : A gradient recipe — (model, batch) -> (loss, params). Use clip_contrastive_recipe, causal_lm_recipe, etc. device : Torch device. vote : "mean", "majority", or "max".

apply(prepared, *, delta, mask_mode='normal', **kwargs)

Apply gradient-sign mask to a delta.

transport(*, source_base, target_base, delta, strict=False, target_model=None, target_dataloader=None, recipe=None, device='cuda', mask_mode='normal', vote='mean', gradient_signs=None, prepared=None, **kwargs)

Full pipeline: prepare (if signs not provided) then apply.

You can either
  • pass gradient_signs or prepared directly (if you already called prepare)
  • pass target_model + target_dataloader + recipe and signs will be computed here.

TransFusion

TransFusion: permutation-based task vector transport.

Computes permutations between source and target base models using WeightMatcher, then applies the permutation to the task vector delta so it can be applied to the target model.

Permutations are cached to disk per (source_tag, target_tag, seed).

prepare(*, clf_source, clf_target, source_loaders=None, classnames=None, source_build_cfg=None, device='cuda', seed=42, perm_cache_source='source', perm_cache_target='target', perm_cache_dir='permutations', perm_cache_mode='auto', max_iter=100, layer_iteration_order='random', intra_head=True, sanity_check_functional_equivalent=False, sanity_check_first_n_batches=None, verbose=True, **kwargs)

One-time expensive setup for TransFusion rebase.

  1. Deepcopy + patch models (shortcuts + split QKV)
  2. Extract visual-only base state dicts (patched key space)
  3. Compute or load cached permutations
  4. Optional sanity check: evaluate source model zeroshot before/after permutation
Returns dict with
  • source_model_unpatched, source_model_patched, target_model_patched
  • source_base_sd, target_base_sd (visual-only, patched keys)
  • perm_indices, heads_indices
  • depth, num_heads
  • sanity_check_pre, sanity_check_post (only if sanity_check_functional_equivalent=True)

apply(prepared, *, delta, strict=False, **kwargs)

Apply pre-computed permutations to a task delta.

transport(*, source_base, target_base, delta, strict=False, prepared=None, **kwargs)

Full pipeline: use provided prepared state, or fall back to internal prepare.

You can either
  • pass prepared directly (if you already called prepare)
  • pass clf_source + clf_target and setup will be done here.

load_task_checkpoint(ckpt_path, source_model_unpatched, verbose=True)

Load a fine-tuned checkpoint into an unpatched source model, then patch and extract visual SD.

compute_task_delta(tuned_sd, source_base_sd)

Compute task delta as key-wise subtraction in patched key space.

load_into_target_visual(clf_target, sd, strict=False)

Load state dict into the visual submodule of the patched target model.

BiCo

BiCo (Bilinear Coordinate Alignment) rebase method.

delta_B = R_out^T @ delta_A @ R_in

R_in = Procrustes map from source→target input activations R_out = Procrustes map from source→target output (dL/dy) gradients

Uses GradFix-style gradient objective for the output-side map.

Theseus

Transport matrix task-vector updates with activation-aligned layer maps.

prepare estimates source-to-target coordinate transforms from activations or data-free covariance information. apply reuses those transforms for a compatible delta, making alpha sweeps cheaper than rebuilding alignment.

Theseus GQA

Bases: TheseusRebase

Theseus variant with head-block-aware attention-projection transport.

Standard Theseus computes one dense Procrustes map over a linear layer's entire (concatenated multi-head) output/input vector. That is blind to per-head structure, so whenever source and target disagree on head count -- e.g. a differing GQA ratio, or plain head-count growth -- the resulting transform freely mixes values across head boundaries, which is architecturally incoherent given attention applies RoPE (and, on Qwen3, QK-RMSNorm) independently per head. This variant instead aligns each target head to its corresponding source head(s) -- broadcasting/pooling by the head-count ratio, mirroring how repeat_kv broadcasts GQA key/value heads at attention time -- and assembles a block-structured transform for q_proj/k_proj/v_proj/o_proj, leaving every other transportable key (MLP, layernorms, final norm) on the original whole-vector Theseus path unchanged.

Kept as a separate method (rather than changing theseus in place) so existing method: "theseus" configs and results are unaffected; opt in with method: "theseus_gqa".

Ariadne

Ariadne: fit the target task vector directly from paired activations.

prepare runs the whole fit (it needs live source/target models and calibration loaders); apply returns the fitted task vector, optionally re-scaled to a different strength; transport is not available because Ariadne never transports a source state-dict delta.

prepare(*, source_base_model, source_ft_model, target_model, target_base_sd, source_loader, target_loader, pairing, config, device, family_adapter=None, recorder=None, clf_source=None, clf_target=None, classnames=None, source_build_cfg_task=None, build_cfg_task=None, source_text_features=None, target_text_features=None, task_name=None, native_target_model=None)

Fit Ariadne once; see _fit_body for the pipeline and its brackets.

With recorder=None the fit runs under its own PhaseCostRecorder and timing["cost_phases"] carries its summary; a caller that already owns a recorder passes it and receives only the two fit brackets. family_adapter=None selects the vision (OpenCLIP) paths verbatim.

apply(prepared, *, delta=None, strength=None)

Return the fitted task vector.

The default (strength=None) is exactly what prepare produced (the fit at config.strength). strength=s re-scales the unit-strength vector (s == 0 gives the empty native-target control, like prepare at strength 0). delta exists only for protocol compatibility: Ariadne has no input delta and refuses one.