A task vector is the difference between fine-tuned and pretrained weights. Several task vectors from the same pretrained model can be added, negated and merged. Implement task arithmetic and the TIES-merging procedure on flat weight vectors.
task_vector(theta_ft, theta_pre)
theta_ft - theta_pre as a float array.task_arithmetic(theta_pre, taus, lam)
taus is a list of task vectors. Return .ties_merge(theta_pre, taus, k_frac, lam=1.0)
k_frac fraction (k = max(1, int(round(k_frac * P))) largest |tau|, ties broken by lower index first, i.e. a stable sort on -|tau|), zero the rest.+1 when the sum is zero).0.theta_pre + lam * merged.merge_report(theta_pre, taus, k_frac, decimals=4)
"plain_mean" and "ties": the task-arithmetic result with lam = 1 / len(taus) (a plain average of task vectors) and the TIES result with lam = 1, both as rounded lists.np.argsort(-np.abs(tau), kind="stable")[:k] gives the kept indices with the specified tie-breaking.