support loading fit checkpoints in JacobianLens.load() - #1574
support loading fit checkpoints in JacobianLens.load()#1574priyanka25aug wants to merge 2 commits into
Conversation
|
Hi @jlarson4 — all format, type, docstring, and benchmark checks are passing. The remaining long-running jobs (compatibility across Python 3.10/3.11/3.12 and full coverage) are still in progress but looking clean so far. Would you mind taking a look when you get a chance? Happy to make any changes based on your feedback. |
jlarson4
left a comment
There was a problem hiding this comment.
Hi @priyanka25aug! Thanks for taking this on. Checkpoint import is a genuinely useful capability, and the conversion math, artifact-path safety, and merge sentinel are all done right.
A couple comments below that we should address before merging
| fields, and marks the result as converted so :meth:`merge` refuses to | ||
| mix it with natively TL-fitted lenses. | ||
| """ | ||
| n_prompts = int(payload.get("n_prompts", 0)) |
There was a problem hiding this comment.
The reference package's write_checkpoint() stores the count as n_done, so genuine checkpoints are rejected here with n_prompts=0. Could the loader read the key set that writer actually emits, as the pre-existing fixture does (tests/unit/tools/test_jacobian_lens.py:507)?
|
|
||
| # Keys written by fit() that must not appear in converted-lens metadata so that | ||
| # merge() can refuse to mix TL-fitted lenses with externally converted ones. | ||
| _FIT_RESERVED_KEYS: frozenset = frozenset( |
There was a problem hiding this comment.
Real checkpoints can record a non-final target_layer, but this conversion discards the key, so the target-convention refusal in validate_model silently passes (jacobian_lens.py:605). Could the conversion preserve target_layer, or refuse checkpoints recording a non-final target?
| *n_prompts_override* lets callers inject a bad value without changing the | ||
| sums (useful for zero/negative n_prompts tests). | ||
| """ | ||
| payload = { |
There was a problem hiding this comment.
These fixtures encode the loader's own invented schema, so the suite continues to pass while real reference checkpoints fail to load. Once the schema is fixed, could one fixture mirror the reference write_checkpoint() payload key-for-key so format drift causes a failure?
|
|
||
| ### Note on tuned-lens | ||
|
|
||
| Tuned-lens checkpoints are not currently supported. The tuned-lens format has no |
There was a problem hiding this comment.
Tuned-lens translators are affine and carry the bias. It is the Jacobian artifact format that has no bias slot to receive it. Can we ensure this detail is included as part of this note?
What this does
Extends
JacobianLens.load()to accept fit checkpoints (files saved by the fitting pipeline with ajacobian_sumkey) in addition to the existing artifact format (files with aJkey).The conversion lives in a new
_from_checkpoint_payload()classmethod:n_promptsto recover the per-prompt meanmodel_name,model_revision,corpus) from the flat payload namespace intometadatatransformer_lens_fit,transformer_lens_version,model_system, etc.) so they don't leak into the converted lensweights_only=Truereload, recording their names and shapes indropped_fieldsfor transparencyconverted_from: "jacobian_lens_checkpoint"somerge()naturally refuses to mix converted and natively TL-fitted lenses (provenance keys differ)Raises
ValueErrorwith a clear message if the file has neither key, or ifn_prompts <= 0. Tuned-lens support deferred.Files changed
transformer_lens/tools/analysis/jacobian_lens.py— new_FIT_RESERVED_KEYSand_CHECKPOINT_FLAT_PROVENANCEfrozensets; updatedload(); new_from_checkpoint_payload()tests/unit/tools/test_jacobian_lens_import.py— unit tests on synthetic fixtures covering artifact regression, checkpoint round-trip, dtype preservation,n_prompts=0guard, tensor field dropping, fit-key stripping, and merge provenance rejection; no model/oracle dependencydocs/source/content/jacobian_lens_fitting.md— "Importing an existing lens" section addedType of change
Checklist
Testing