lorapop / code /RESEARCH_PLAN.md
bryan7264's picture
Add files using upload-large-folder tool
abdd6f5 verified
|
Raw History Blame Contribute Delete
15.7 kB
# RESEARCH PLAN (frozen 2026-11-23; changes after this date are deviations, logged in DECISIONS.md)
## 1. Scope and populations
1.1 Primary population (all pre-registered primary analyses): public LoRA adapters of Qwen/Qwen2.5-0.5B-Instruct
(HF index 2026-11-20; 955 downloaded safetensors adapters before checks). Full fine-tunes (1,195) and merges (47) of the
same base enter as secondary members via rank-64 randomized SVD of weight differences (section 2.4).
1.2 Replication populations, in order, sized to the queue (section 15): TinyLlama-1.1B-Chat-v1.0; Qwen2.5-1.5B-Instruct;
Qwen2.5-7B-Instruct; Mistral-7B-Instruct-v0.2 wild adapters plus the Lots-of-LoRAs collection; Phi-3-mini-4k-instruct.
Llama-3.1-8B-Instruct is excluded (gated, no access).
1.3 Controlled populations trained here: seed-sibling families (section 6.1), opposite fine-tunes (6.2), trait-targeted
fine-tunes (6.3).
## 2. Data pipeline (src/data)
2.1 Enumeration: src/data/hf_enumerate.py (done; data/raw/hf_index).
2.2 Download: src/data/fetch_adapters.py, safetensors only (adapter_model.safetensors + adapter_config.json + README.md),
root or shallowest subfolder; pickle files never fetched.
2.3 Checks (src/lorapop/adapters.py + src/data/qc.py): finite weights; non-zero update; module shapes match the base;
layer indices within depth; declared base recorded; base match tested by perplexity of base+adapter on 64 reference
texts vs base (reject if adapter perplexity > 3x base or non-finite); peft_type LORA only (others recorded, excluded);
rsLoRA, rank_pattern, alpha_pattern handled; DoRA converted to the effective difference then rank-64 SVD; adapters with
modules_to_save (lm_head/embeddings) keep their LoRA part and are flagged (covariate "format").
2.4 Full fine-tunes and merges: streamed shard by shard; Delta = W_ft - W_base per adapted linear module; randomized SVD
(rank 64, 2 power iterations, seed 0) stored as factors; tensors deleted after reduction. Same checks as 2.3.
2.5 Duplicates: pairs with raw similarity > 0.999 and equal ranks are near duplicates; kept in the population, removed in
the "duplicates removed + author FE" estimator (7.1).
2.6 Metadata stored for audit and splits: author, createdAt, tags, datasets in tags, model card text.
## 3. Base covariances and genotypes (src/lorapop/basecov.py, genotype.py)
3.1 Reference corpus: 1,500 sequences, equal thirds of wikitext-103 train paragraphs (> 1,000 chars), no_robots full chats
(chat template), no_robots first-turn prompts with generation prompt; max 512 tokens; seed 0. Disjoint from battery.
3.2 C_m per input (attn_in for q/k/v, o_in, mlp_in for gate/up, down_in) per layer; top-512 eigenpairs; k = min(k99, 512).
3.3 Expressed Grams from factors; loci per module: leading eigenvectors holding 90 percent of centred expressed variance,
up to 32; presence loci per module type. Genotypes g = sqrt(lambda) u. Alleles Delta* built on demand (dense p x q, then
exact low-rank factors keeping 99.99 percent energy).
3.4 Sensitivity variants (section 14.6): k cap 128/256/512, var_frac 0.8/0.9/0.95, reference corpus thirds swapped for
a single-domain corpus.
## 4. Phenotyping (src/lorapop/battery.py)
4.1 Battery (fixed; item lists frozen by seed 0):
refusal_harm: HarmBench standard + contextual text behaviors (300); refusal_xs_safe: XSTest safe (250);
refusal_xs_unsafe: XSTest unsafe (200); score = teacher-forced log P over 12 refusal openers minus over 12
compliance openers (lists in battery.py).
tqa_mc1: TruthfulQA MC1, all items, letters, prefill "The answer is (" -> P(correct), accuracy.
mmlu: 40 items per subject (57 subjects), same format; accuracy overall and by 4 groups; ECE over 10 bins.
mwe_*: 11 model-written-eval sets, 300 items each (or all if fewer), P(answer matching behavior).
gen_general: 200 AlpacaEval instructions, greedy, 256 new tokens: log length, markdown, list, code, hedge, persona,
emoji, language shares (en, zh, other).
gen_json: 60 JSON-request prompts, 256 tokens: JSON validity.
gen_ifeval: 541 IFEval prompts, 512 tokens: prompt-level strict accuracy and the same form traits.
4.2 Execution: base model in bf16 on GPU; updates applied on a separate low-rank path (src/lorapop/deltas.py), never merged.
Full fine-tunes are phenotyped with their actual weights (not the rank-64 reduction) by loading their state dict.
4.3 Reliability: every trait computed on two fixed item halves; split-half reliability across the population with
Spearman-Brown correction. Primary traits = traits with reliability >= 0.7 on the primary population (decided once,
after phenotyping and before any association scan; the list is written to results/phenotypes/primary_traits.json).
4.4 Transform: rank-based inverse normal transform fitted on the population per trait; interventional measurements are
mapped through the same transform (monotone interpolation of the population's empirical CDF).
4.5 Intervention battery: identical to 4.1 (no subsetting) unless the measured cost exceeds the budget in 15.3, in which
case generation traits use fixed halves h0 (logged as a deviation).
## 5. Relatedness and families (E1; src/lorapop/kinship.py, src/analysis/families.py)
5.1 K_desc (raw cosine from factors, summed over modules) and K_func (expressed cosine).
5.2 Descent relation: K_desc_ij > 3 x law(r_i, r_j, d = q_m) averaged over shared modules; families = connected components.
5.3 Recipe families: average-linkage clustering of K_func among descent-unrelated adapters, cut at the K_func value equal to
the 99th percentile of K_func between random pairs of different-task seed siblings (6.1) on the same base.
5.4 Reports: family sizes, spectra, share with a relative, agreement with metadata (adjusted Rand index vs author and vs
shared training-dataset tag), n_eff per layer.
5.5 Merges: non-negative least squares of each merge's expressed delta on candidate parents in the population (parents =
top-20 by K_func), admixture proportions and residual.
## 6. Controlled training (src/train)
6.1 Seed siblings (H1): Qwen2.5-0.5B-Instruct; 8 tasks (no_robots categories: open QA, brainstorm, summarize, rewrite,
classify, coding, chat, generation), ranks {4, 8, 16, 32, 64}, 3 seeds; independent A init and shared A init (same A
seed); 1 epoch, 1,000 examples, lr 2e-4, alpha = 2r, all 7 modules. 240 runs. Law prediction per pair from d estimated
on the gradient at B = 0 (raw: d = q; expressed: d from C and the first-step gradient).
Mistral (replication): 10 Lots-of-LoRAs tasks x 2 seeds with the released data and the collection's recipe.
6.2 Opposite fine-tunes (spike-in directions, benign traits): answer in French vs English; one sentence vs long; markdown
vs plain; formal vs casual; 3 seeds each, rank 16; direction = expressed difference of the pair.
6.3 Trait-targeted fine-tunes (H6): one adapter per targeted benign trait (French, concise, markdown, JSON-only, hedging,
persona statements, over-refusal on safe prompts, sycophantic agreement, truthfulness, one MMLU domain), 3 seeds x ranks
{8, 32} x 2 data sources where available.
## 7. Association scans (E2; src/analysis/scan.py)
7.1 Estimators: naive OLS; PC (10 leading eigenvectors of K_func); MM-f (function layer, leave out the layer block of the
tested module: blocks = 4 contiguous layer groups x {attention, MLP}); MM-fd (adds K_desc); WF-d and WF-r (within descent
and recipe families, families of size >= 2); DUP-AFE (near duplicates removed, author fixed effects).
7.2 Covariates: intercept, log rank (max), log update norm, target-module pattern (one-hot of the 8 most common), format
flags, base quantisation in training (from config/name: 4-bit / 8-bit / none).
7.3 REML (variance components) once per trait and left-out block; GLS per locus with Wald test.
7.4 Module kernel tests (score test, K_m = expressed Gram of module m), SuSiE (L = 10) in significant modules and their
neighbours on the relatedness-adjusted residual.
7.5 Diagnostics: lambda_GC with family-block bootstrap (1,000); QQ; linkage-score regression; negative-control trait.
7.6 Multiple testing: Bonferroni over M_eff (eigenvalues of the locus correlation matrix, Li-Ji); discovery FDR 0.05.
7.7 Split: descent families assigned to discovery (D) or estimation (E) by sorted SHA-1 of the family's lowest repo id,
alternating, so that D and E have equal numbers of adapters within 5 percent; selection on D, effect estimation on E.
## 8. Interventions (E3; src/analysis/intervene.py)
8.1 Loci tested: union over estimators and primary traits of loci selected on D (FDR 0.05), capped at 150 by smallest
p-value per estimator in round-robin; plus three controls per locus (random direction matched in norm and module;
high-variance non-associated locus of the same module; same axis in another layer of the same module type).
8.2 Backgrounds: base plus 24 adapters from E families, stratified over recipe clusters (seed 0).
8.3 Doses c in {-3, -2, -1, 0, 1, 2, 3} x sigma_l; full battery per dose and background.
8.4 gamma_do = mean over adapter backgrounds of the OLS slope over c in {-1, 0, 1}; base-background slope reported apart.
8.5 Knockouts in all E carriers with |g - gbar| > 1 SD (up to 24): change toward the population mean.
## 9. Crosses (E4; src/analysis/cross.py)
9.1 Parents: 30 adapters from different descent families, all 7 modules adapted, spanning the primary traits (greedy
max-min distance on the primary trait vector, seed 0) + the base as zero parent.
9.2 Layer resolution: 24 segments x 31 parents -> 24 x 30 additive parameters; 5,760 offspring (8 per parameter).
9.3 Module resolution: the 4 layers with the largest layer-level additive variance, 7 modules each (28 segments): 28 x 30 x 8
= 6,720 offspring. Direction resolution: within the 4 modules with largest module-level variance, each parent's update
split into its top-4 expressed directions plus remainder (5 segments per module): 20 x 30 x 8 = 4,800 offspring.
9.4 Model: ridge-free OLS of the additive model on 80 percent of offspring; held-out R^2 on 20 percent relative to the
trait's reliability in offspring (split-half); interaction terms for adjacent layers and attention/MLP pairs; gradient
boosting on parent indicators as flexible learner. Degenerate offspring (reference-corpus perplexity > 3x base) reported.
9.5 Segment calibration: measured alpha_{s,p} vs alpha_obs_{s,p} from each estimator; errors-in-variables slope.
## 10. Spike-ins (E5; src/analysis/spikein.py)
Directions from 6.2, from validated loci (8), and random low-rank directions (rank 4, norm matched to median locus) whose
effect is measured on the base. Carriers at 1, 5, 20 percent (random) or whole families; doses 0.5, 1, 2 SD; trait =
change caused by the spike (spiked minus unspiked phenotype of each carrier on the intervention battery; non-carriers 0).
Scores: precision and recall of the spiked locus at FDR 0.05, bias of its effect, per estimator; 5 seeds.
## 11. Architecture, genetic correlations, forecasts (E6)
11.1 Variance components: descent kernel + 8 function kernels (4 layer blocks x attn/MLP); LRT vs descent-only; BLUP
(function layer) on held-out descent families (5-fold by family).
11.2 Bivariate REML for all pairs of primary traits under each layer -> G; P from phenotypes; G_do from validated loci.
11.3 Forecasts: trait-targeted fine-tunes (6.3); predicted side-effect vector G beta vs observed; competitors P, cross-base
spillover (same targeted fine-tunes on TinyLlama), gradient kernel of the base (cosine of per-trait loss gradients),
representation-based forecast (difference-of-means activation directions per trait, cosine), and zero.
## 12. Prediction and portability (E7)
Predictors (equal tuning budget: 20 configurations each, selected on validation families): ridge on raw sketches; ridge on
expressed coordinates; spectral features; kNN in K_func; BLUP-f; mixed-model score; causal score (validated loci with
gamma_do only). Splits: random, descent-disjoint, recipe-disjoint, author-disjoint (5 folds each), cross-collection
(Lots-of-LoRAs <-> wild Mistral). Accuracy (Pearson r on transformed traits) vs maximum K_desc and K_func to the training
set in 5 bins. Merges: predicted from admixture x parents' phenotype and from loci.
## 13. Audit and repair (E8)
Carriers of validated safety directions (refusal, XSTest, model-written-eval propensities) identified from weights in each
population; carrier rates; relation to measured behavior; disclosure in model cards by keyword classes. Repair: knockout
in carriers vs random-direction knockout of equal norm vs uniform shrinkage matched for the safety gain vs base;
specificity = safety gain / RMS change of other traits. Aggregates only.
## 14. Statistics
14.1 Calibration slope: Deming / errors-in-variables regression through the origin with per-locus bootstrap variances
(200 resamples of backgrounds for gamma_do; family bootstrap for observational effects); CI by 2,000 bootstrap
resamples of loci (block bootstrap by module).
14.2 Estimator comparison: paired bootstrap of |kappa_X - 1| - |kappa_naive - 1| on the common locus set.
14.3 Meta-analysis across traits and bases: DerSimonian-Laird random effects, I^2 reported.
14.4 Multiple testing across traits: BH over the union of discoveries.
14.5 Seeds: sketches, spike-in carrier sets and cross designs use seeds 0-4.
14.6 Sensitivity: number of PCs (5/10/20), k cap, loci per module, family threshold (2x/3x/5x law), reference corpus.
14.7 Ablations: raw coordinates instead of expressed (whole pipeline); no left-out block; no function layer; no descent
layer; selection and estimation on the same families.
## 15. Compute schedule
15.1 Lanes: gpu_devel (1 job, 6 h, 2 GPUs) for development and pilots; gpu_rtx6000 for bulk (array jobs of 3-6 h chunks,
resumable: each work unit writes results/<stage>/<id>.json and is skipped if present); gpu / gpu_h100 as backfill.
15.2 Order: phenotype primary population -> seed siblings + opposite fine-tunes (training) -> genotypes/relatedness ->
scans -> interventions -> spike-ins -> crosses -> E6/E7/E8 -> replications.
15.3 Budget targets (GPU-hours, RTX Pro 6000 class): phenotyping 0.5B population <= 120; training <= 40; interventions
<= 250; crosses <= 400; replications as queue allows.
## 16. Pre-registration
16.1 Primary population: Qwen2.5-0.5B-Instruct public LoRA adapters passing 2.3.
16.2 Primary traits: battery traits with split-half reliability >= 0.7 (4.3), decided before any scan.
16.3 Primary metric: calibration slope kappa (14.1) of each estimator on the common locus set (8.1), traits pooled by
standardising effects within trait.
16.4 Primary comparison: MM-fd vs naive: Delta = |kappa_MMfd - 1| - |kappa_naive - 1|, paired bootstrap (14.2), 2,000
resamples, 95 percent CI. Secondary: WF-d vs naive, MM-f vs naive, PC vs naive (Holm across the four).
16.5 Success thresholds: H2 supported if lambda_GC(naive) > 1.1 on any primary trait or kappa_naive outside [0.8, 1.2];
H3 supported if kappa_MMfd in [0.8, 1.2] and the CI of Delta lies below 0; H4 supported if held-out additive R^2 /
reliability >= 0.5 and segment slope in [0.8, 1.2]; H1 per PROPOSAL.md.
16.6 Seeds 0-4 (14.5); split rule 7.7; intervention backgrounds 8.2; cross design 9.1-9.3.
16.7 Analyses not listed here are exploratory and labelled as such.
## 17. Deviations
Any change to sections 4.1, 4.3, 7.1, 7.7, 8.1-8.4, 9.1-9.4, 14.1-14.2 or 16 after the freeze is logged in DECISIONS.md with
date and reason and reported in the paper.