stable / dataset_upload /protocol /jlens_spec.md
LucasLoading's picture
Upload 30 files
6f2ed01 verified
|
Raw
History Blame Contribute Delete
19.7 kB

Engineering Specification for Jacobian-Transported ISS

0. Purpose

This document specifies how to implement the official Internal State Stability metric, abbreviated as ISS, using Jacobian-transported hidden states.

The formal metric remains:

[ z^\ell_{m,f,q}=J^\ell_m h^\ell_{m,f,q}, ]

where no vocabulary unembedding matrix is applied. The implementation may approximate (J^\ell_m), but the approximation must be independently validated and its numerical error must be reported.

Raw-ISS is retained only for debugging and ablation. It is not the official metric.


1. Official Definition

For model (m), fact (f), query (q), and source layer (\ell), extract the query-end residual state:

[ h^\ell_{m,f,q}\in\mathbb R^{d_m}. ]

Define the corpus-averaged input-output Jacobian:

[ J^\ell_m

\mathbb E_{x\sim\mathcal C} \left[ \frac{\partial h^L_m(x)}{\partial h^\ell_m(x)} \right], ]

where (\mathcal C) is an independent calibration corpus.

The transported representation is:

[ \boxed{z^\ell_{m,f,q}=J^\ell_m h^\ell_{m,f,q}} ]

Do not compute:

[ W_UJ^\ell_m h^\ell_{m,f,q}. ]

The official ISS therefore operates in the final-layer residual basis rather than vocabulary-logit space.


2. Formal Metric Versus Practical Estimator

The formal metric uses the exact population average (J^\ell_m). The practical implementation uses a finite-corpus, finite-rank estimator:

[ \widehat J^{\ell,(n,k)}_m. ]

The practical transported state is:

[ \widehat z^\ell_{m,f,q}

\widehat J^{\ell,(n,k)}m h^\ell{m,f,q}. ]

The paper should distinguish:

  • (\operatorname{ISS}): the formal metric;
  • (\widehat{\operatorname{ISS}}_{n,k}): the empirical estimator.

The approximation is acceptable only if it satisfies the validation criteria below.


3. Why Full Jacobians Are Not the General Solution

For hidden dimension (d):

[ J^\ell_m\in\mathbb R^{d\times d}. ]

Materializing this matrix is feasible only for small models. For large models with (d=4096), (5120), or more, exact recovery across many layers and calibration prompts is prohibitively expensive.

Therefore:

  1. full Jacobians are used only for small-model calibration;
  2. large models use a randomized factorized estimator;
  3. approximation quality must be validated for every model rather than inferred from a small model.

4. Overall Engineering Pipeline

Stage A: Full-matrix calibration on a small model
    |
    v
Stage B: Per-model approximation validation
    |
    v
Stage C: Freeze estimator settings
    |
    v
Stage D: Official ISS evaluation

The final test set must not be used to choose estimator hyperparameters.


5. Stage A: Small-Model Full-Matrix Calibration

Use Qwen2.5-0.5B as the primary exact-reference model.

5.1 Exact finite-corpus reference

For a fixed calibration corpus of (n) prompts, compute:

[ J^{\ell,(n)}_{\mathrm{full}}

\frac{1}{n} \sum_{i=1}^{n}J^\ell_{x_i}. ]

This is an exact empirical Jacobian for that finite corpus.

Do not call it the exact population Jacobian or universal ground truth. Use one of the following terms:

  • full empirical Jacobian reference;
  • exact finite-corpus Jacobian.

5.2 Layer coverage

At minimum, compute full references for:

  • one early layer;
  • one middle layer;
  • one late layer.

If feasible on Qwen2.5-0.5B, compute every layer.

5.3 Candidate ranks

Evaluate:

[ k\in{32,64,128,256,512,768}, ]

subject to (k<d).

Use nested random probes so that larger ranks contain the directions used at smaller ranks.

5.4 Required validation statistics

Matrix approximation error

[ E_F(k)

\frac{|J_{\mathrm{full}}-\widehat J_k|F} {|J{\mathrm{full}}|_F}. ]

Transported-vector relative error

For held-out activation vectors (h_i):

[ E_{\mathrm{vec}}(k)

\frac{1}{M} \sum_{i=1}^{M} \frac{|J_{\mathrm{full}}h_i-\widehat J_kh_i|2} {|J{\mathrm{full}}h_i|_2+\epsilon}. ]

Transported-vector cosine agreement

[ C_{\mathrm{vec}}(k)

\frac{1}{M} \sum_{i=1}^{M} \cos(J_{\mathrm{full}}h_i,\widehat J_kh_i). ]

ISS absolute error

[ E_{\mathrm{ISS}}(k)

\left| \operatorname{ISS}_{\mathrm{full}}

\widehat{\operatorname{ISS}}_k \right|. ]

Per-fact ISS rank agreement

[ \rho_{\mathrm{fact}}(k)

\operatorname{Spearman} \left( {\operatorname{ISS}^{\mathrm{full}}_f}, {\widehat{\operatorname{ISS}}^{(k)}_f} \right). ]

A low Frobenius error is not sufficient. The transported vectors and the final ISS must also be stable.


6. Randomized Factorized Jacobian Estimator

The estimator must define a linear operator that can be applied to arbitrary hidden states. Computing only (J\Omega) is not enough.

Use randomized range finding with a two-sided operator estimate.

6.1 Random probe matrix

For target rank (k), draw:

[ \Omega\in\mathbb R^{d\times(k+p)}, ]

where:

  • (p) is an oversampling dimension;
  • recommended (p\in{32,64});
  • (\Omega) uses Gaussian or Rademacher entries;
  • all random seeds are fixed and recorded.

6.2 Estimate the Jacobian output range

Compute:

[ Y

J^\ell\Omega

\mathbb E_x[J^\ell_x\Omega]. ]

Use batched Jacobian-vector products.

Then compute:

[ Q=\operatorname{qr}(Y), ]

with:

[ Q\in\mathbb R^{d\times(k+p)}. ]

6.3 Estimate the reduced operator

Compute:

[ B=Q^\top J^\ell. ]

Equivalently:

[ B^\top=J^{\ell\top}Q. ]

Use batched vector-Jacobian products.

The final estimator is:

[ \boxed{\widehat J^\ell=QB} ]

and:

[ \widehat J^\ell h=Q(Bh). ]

6.4 Storage

Store only:

[ Q\in\mathbb R^{d\times r}, \qquad B\in\mathbb R^{r\times d}, ]

where (r=k+p).

Do not reconstruct and store the complete (d\times d) matrix.

Since (Q) has orthonormal columns:

[ \cos(Qy_1,Qy_2)=\cos(y_1,y_2). ]

Therefore downstream cosine computations may use:

[ y^\ell=Bh ]

directly. Residualization and whitening must then be performed consistently in that reduced coordinate space.


7. Per-Model Validation Is Mandatory

A rank that works for Qwen2.5-0.5B must not be assumed to work for larger models.

Different models can have different:

  • hidden dimensions;
  • Jacobian singular-value decay;
  • effective rank;
  • depth;
  • normalization;
  • architecture;
  • post-training behavior.

The small-model experiment validates the estimator implementation. It does not determine one universal rank.

7.1 Direct action validation

For every evaluated model, select representative:

  • early layers;
  • middle layers;
  • late layers.

For held-out activation vectors (h_i), directly compute:

[ u_i=J^\ell h_i

\frac1n\sum_{x\in\mathcal C}J^\ell_xh_i. ]

This does not require materializing the full Jacobian.

Compare with:

[ \widehat u_i=\widehat J^\ell_kh_i. ]

7.2 Validation activation set

Use a calibration activation set independent of the final ISS test set.

Recommended:

  • 64–128 activation vectors per representative layer;
  • multiple prompt types if benchmark-like prompts are used;
  • or a separate set of held-out natural questions.

7.3 Rank candidates

Use a nested grid such as:

[ k\in{64,128,256,512,1024}, ]

bounded by model dimension and compute resources.

Choose the smallest (k_{m,\ell}) that satisfies the fixed validation criteria.

Recommended initial criteria:

[ \operatorname{median}_i\cos(u_i,\widehat u_i)\ge0.99, ]

[ \operatorname{median}_i \frac{|u_i-\widehat u_i|_2} {|u_i|_2+\epsilon} \le0.05, ]

and:

[ \left| \widehat{\operatorname{ISS}}_{2k}

\widehat{\operatorname{ISS}}_k \right| \le0.01. ]

The exact numeric thresholds may be adjusted after Stage A, but they must be frozen before final evaluation.

7.4 Model-specific rank is allowed

Different models and layers may use different ranks:

[ k_{m,\ell}. ]

This is methodologically acceptable because all models use the same approximation-quality standard.

Always report:

  • (k_{m,\ell});
  • (k_{m,\ell}/d_m);
  • validation cosine;
  • validation relative error;
  • rank-stability error.

8. Calibration Corpus Size

Rank error and corpus-sampling error are separate.

The empirical Jacobian is:

[ J^{\ell,(n)}

\frac1n\sum_{i=1}^{n}J^\ell_{x_i}. ]

A large (k) does not compensate for insufficient corpus size (n).

8.1 Corpus requirements

The Jacobian corpus must:

  • be independent of the factual benchmark;
  • contain general pretraining-style or natural text;
  • use the same construction rule for all models;
  • use a fixed sequence-length and position convention;
  • record all sample IDs and random seeds.

8.2 Corpus-size convergence

On representative models, compare:

[ n\in{32,64,128,256,512}. ]

Measure:

[ \cos(\widehat J^{(n)}h,\widehat J^{(2n)}h), ]

and:

[ \left| \widehat{\operatorname{ISS}}_n

\widehat{\operatorname{ISS}}_{2n} \right|. ]

Select (n) using a fixed convergence rule. Do not select (n) based on preferred final benchmark conclusions.


9. Random-Seed Stability

For representative model-layer-rank settings, use at least three sketch seeds.

Report mean and standard deviation for:

  • transported-vector cosine;
  • transported-vector relative error;
  • ISS;
  • KTS if KTS uses the same transported states.

A rank is not considered stable if results vary materially across seeds.

Preferred final reporting:

  • average the result across three validated seeds; or
  • use one preregistered seed after proving seed variance is negligible.

Never choose the seed that gives the preferred scientific result.


10. Official ISS Computation

After freezing the estimator, compute:

[ \widehat z^\ell_{m,f,q}

\widehat J^\ell_m h^\ell_{m,f,q}. ]

Then run the standard ISS pipeline.

10.1 Relation and condition residualization

[ \bar z^\ell_{m,f,q}

z^\ell_{m,f,q}

\mu^\ell_{m,r_f}

\mu^\ell_{m,t(q)} + \mu^\ell_m. ]

10.2 Regularized whitening

[ \tilde z^\ell_{m,f,q}

(\Sigma^\ell_m+\lambda I)^{-1/2} \bar z^\ell_{m,f,q}. ]

If the reduced coordinate (y=Bh) is used directly, estimate (\Sigma) in that coordinate system.

Do not fit a separate whitening transform for each condition family.

10.3 Family centroid

[ v^\ell_{m,f,t}

\operatorname{Normalize} \left( \frac1{|Q_{f,t}|} \sum_{q\in Q_{f,t}} \tilde z^\ell_{m,f,q} \right). ]

10.4 Same-fact cross-condition similarity

[ S^+_{m,f,\ell}

\frac1{|\mathcal P_f|} \sum_{(t,t')\in\mathcal P_f} \cos(v^\ell_{m,f,t},v^\ell_{m,f,t'}). ]

10.5 Relation-matched background

[ S^-_{m,f,\ell}

\mathbb E_{\substack{g\neq f,\ r_g=r_f\t\neq t'}} \cos(v^\ell_{m,f,t},v^\ell_{m,g,t'}). ]

10.6 Official ISS estimator

[ \boxed{ \widehat{\operatorname{ISS}}_{m,f,\ell}

\frac{S^+{m,f,\ell}-S^-{m,f,\ell}} {1-S^-_{m,f,\ell}+\epsilon} } ]

Average over the preregistered layer window:

[ \widehat{\operatorname{ISS}}_{m,f}

\frac1{|\mathcal W_m|} \sum_{\ell\in\mathcal W_m} \widehat{\operatorname{ISS}}_{m,f,\ell}. ]

Then average over the fixed fact set:

[ \widehat{\operatorname{ISS}}_m

\frac1{|\mathcal D|} \sum_{f\in\mathcal D} \widehat{\operatorname{ISS}}_{m,f}. ]


11. Raw-ISS

Raw-ISS uses:

[ z^\ell_{m,f,q}=h^\ell_{m,f,q}. ]

It should be computed because it is inexpensive and useful for:

  • debugging hidden-state extraction;
  • validating family aggregation;
  • validating negative sampling;
  • checking whitening and residualization;
  • ablation;
  • testing whether Jacobian transport changes the conclusion.

However:

[ \boxed{\text{Raw-ISS is not the official ISS result.}} ]

Recommended table terminology:

Metric Representation Role
Raw-ISS (h^\ell) Identity-transport ablation
ISS (\widehat J^\ell h^\ell) Official metric
Token readout (W_U\widehat J^\ell h^\ell) Not used

12. Failure Policy

Do not silently report an unvalidated approximation.

A model-layer estimator fails validation if:

  • rank convergence is not achieved;
  • action-vector cosine remains below threshold;
  • relative action error remains above threshold;
  • ISS changes materially across ranks;
  • ISS changes materially across random seeds.

12.1 Allowed responses

In order:

  1. increase (k);
  2. increase oversampling (p);
  3. increase corpus size (n);
  4. add power iterations;
  5. restrict official ISS to validated layers;
  6. mark the model-layer estimator as unresolved.

Raw-ISS may still be reported as an ablation, but it must not be relabeled as official ISS.

12.2 Optional fallback estimator

If low-rank reconstruction consistently fails, consider a geometry-preserving output sketch:

[ RJ^\ell h, ]

where:

[ R\in\mathbb R^{k\times d}. ]

This avoids assuming that (J^\ell) itself is low rank. However, it is a different estimator and must be separately validated against the full small-model reference.

Do not switch to this estimator silently.


13. Data Separation

Use three disjoint resources.

13.1 Jacobian corpus

Used to estimate (J^\ell_m). It must contain independent general text.

13.2 Estimator calibration set

Used to select:

  • corpus size (n);
  • rank (k);
  • sketch seed;
  • oversampling;
  • power iterations;
  • approximation thresholds.

It must not overlap with the final benchmark evaluation facts.

13.3 Final ISS benchmark

Used only after all estimator settings are frozen.

Do not tune (n), (k), seeds, layer windows, or whitening choices on the final benchmark.


14. Required Output Files

jacobian_iss/
β”œβ”€β”€ configs/
β”‚   β”œβ”€β”€ corpus_config.yaml
β”‚   β”œβ”€β”€ estimator_config.yaml
β”‚   β”œβ”€β”€ validation_thresholds.yaml
β”‚   └── layer_windows.yaml
β”œβ”€β”€ full_reference/
β”‚   └── qwen2.5_0.5b/
β”œβ”€β”€ low_rank_factors/
β”‚   └── {model}/{layer}/
β”‚       β”œβ”€β”€ Q.pt
β”‚       β”œβ”€β”€ B.pt
β”‚       └── metadata.json
β”œβ”€β”€ validation/
β”‚   β”œβ”€β”€ small_model_full_comparison.json
β”‚   β”œβ”€β”€ per_model_action_validation.jsonl
β”‚   β”œβ”€β”€ rank_convergence.jsonl
β”‚   β”œβ”€β”€ corpus_convergence.jsonl
β”‚   └── seed_stability.jsonl
β”œβ”€β”€ transported_states/
β”œβ”€β”€ iss_per_fact_layer.jsonl
β”œβ”€β”€ iss_per_fact.jsonl
β”œβ”€β”€ iss_model_summary.json
└── raw_iss_ablation.json

15. Required Metadata

For every estimator, store:

{
  "model": "model_name",
  "model_revision": "revision",
  "tokenizer_revision": "revision",
  "layer": 16,
  "hidden_dimension": 4096,
  "rank": 512,
  "oversampling": 64,
  "power_iterations": 0,
  "calibration_corpus_size": 256,
  "calibration_sequence_length": 128,
  "random_seed": 42,
  "validation_cosine_median": 0.993,
  "validation_relative_error_median": 0.041,
  "iss_rank_difference": 0.006,
  "validated": true
}

16. Minimum Required Experiments

Experiment A: Full-reference calibration

Model:

Qwen2.5-0.5B

Compare:

full empirical Jacobian
vs.
rank 32/64/128/256/512/768 approximations

Report:

  • Frobenius error;
  • transported-vector error;
  • transported-vector cosine;
  • ISS absolute error;
  • per-fact ISS Spearman correlation.

Experiment B: Medium-scale transfer check

Use at least one medium-sized model.

At representative layers:

  • compute high-accuracy direct (Jh) actions;
  • validate rank behavior;
  • confirm that the small-model rank does not automatically transfer.

Experiment C: Per-model validation

For every evaluated model:

  • representative early, middle, and late layers;
  • 64–128 held-out activation vectors;
  • nested candidate ranks;
  • fixed validation thresholds;
  • at least three random seeds on representative settings.

Experiment D: Official evaluation

Only after freezing all estimator choices:

  • compute transported states;
  • compute official ISS;
  • compute Raw-ISS;
  • compare trends;
  • report approximation uncertainty.

17. Recommended Decision Rule

Do not use:

k = 512 for every model

Use:

Choose the smallest k for each model-layer that satisfies
one fixed approximation-quality standard.

Recommended initial rule:

median action cosine >= 0.99
median relative action error <= 0.05
|ISS(2k) - ISS(k)| <= 0.01
seed standard deviation of ISS <= 0.005

The exact thresholds may be refined after the small-model calibration, but they must be frozen before final evaluation.


18. Uncertainty Reporting

Separate the following sources of uncertainty:

  1. finite Jacobian-corpus error;
  2. low-rank approximation error;
  3. random-sketch error;
  4. benchmark sampling uncertainty;
  5. relation-level heterogeneity.

At minimum, report:

  • rank sensitivity;
  • corpus-size sensitivity;
  • random-seed sensitivity;
  • per-model action validation;
  • relation-clustered bootstrap confidence intervals for final ISS.

Do not present one confidence interval that silently mixes all uncertainty sources.


19. Paper-Ready Method Description

We define Internal State Stability on Jacobian-transported residual states (z^\ell=J^\ell h^\ell), where (J^\ell) is the corpus-averaged input-output Jacobian from layer (\ell) to the final residual stream. We do not apply the vocabulary unembedding matrix, thereby retaining a continuous hidden representation compatible with multi-token and multilingual answers. Since explicitly materializing (J^\ell\in\mathbb R^{d\times d}) is prohibitive for large models, we estimate it using randomized range finding, yielding a factorized operator (\widehat J^\ell=Q^\ell B^\ell). We validate this approximation against full empirical Jacobians on Qwen2.5-0.5B and against directly computed Jacobian-vector products on held-out activations for every evaluated model. The sketch rank is selected independently for each model and layer using a fixed preregistered approximation-error tolerance rather than a universal rank or final benchmark performance.

Continuation:

We separately evaluate calibration-corpus convergence, rank convergence, and random-seed stability. Raw hidden-state ISS is reported only as an identity-transport ablation.


20. Final Engineering Decisions

Official ISS:
    Jacobian-transported hidden-state ISS

Transport:
    z = J h

Unembedding:
    Do not multiply by W_U

Small-model full Jacobian:
    Finite-corpus exact reference only

Large-model implementation:
    Randomized factorized operator estimate

Rank selection:
    Per model and per layer

Rank criterion:
    Shared fixed approximation-quality threshold

Validation:
    Full matrix comparison on Qwen2.5-0.5B
    Direct J h comparison on every evaluated model

Raw-ISS:
    Debugging and ablation only

Final test set:
    Never used to tune n, k, seeds, layers, or estimator settings

Failure:
    Do not report unvalidated Jacobian ISS

21. Immediate Implementation Order for Claude

  1. Finish Raw-ISS to validate data loading and metric aggregation.
  2. Implement exact finite-corpus Jacobian recovery on Qwen2.5-0.5B.
  3. Implement the randomized factorized estimator (\widehat J=QB).
  4. Compare candidate ranks against the full small-model reference.
  5. Measure matrix, vector-action, ISS-value, and fact-ranking errors.
  6. Freeze approximation-quality thresholds.
  7. Implement direct (Jh) validation for large models.
  8. Select (k_{m,\ell}) using the fixed thresholds.
  9. Run corpus-size and seed-stability checks.
  10. Freeze all estimator configurations.
  11. Compute official ISS on the final benchmark.
  12. Report Raw-ISS only as an ablation.
  13. Save all factors, configurations, validation logs, and checksums.

The objective is not to recover every Jacobian entry exactly. The objective is to guarantee that the transported representations and the resulting ISS remain within a preregistered numerical tolerance.