Repository navigation
feat(nla): add Bridge-native Qwen activation verbalization and reconstruction - #1889
Closed
janmenjayap wants to merge 10 commits into
Closed
janmenjayap wants to merge 10 commits into
janmenjayap wants to merge 10 commits into
Conversation
Collaborator
|
Closing this to wait for community interest on #1884. If you are interested in a feature like this, please give that issue a read! |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
Add local Natural Language Autoencoder (NLA) inference infrastructure on
TransformerBridge: raw activation extraction, Activation Verbalizer (AV)
generation, Activation Reconstructor (AR) execution with a separate value head,
and directional reconstruction scoring.
Fixes #1884
The implementation remains private. Released-Qwen numerical compatibility has
not been established, the support registry is empty, and the class is not
exported from
transformer_lens.tools.analysis. This PR does not currentlyprovide a verified public pretrained model name. The issue's complete acceptance
criteria remain outstanding as listed below.
Motivation
The authors' reference AV client uses SGLang embedding injection. This work
provides hook-native inference without operating a model server, consuming
released artifacts rather than implementing their training infrastructure.
Changes
checks, normalization-mode checks, and safe bias-free value-head loading.
target, revision, layer, and basis mismatches are rejected before AV loading.
at the original prompt position, with bounded generation and continuation-only
explanation parsing.
normalization and avoiding execution of the unused LM head.
cleanup, and rejection of concurrent operations on one instance.
Explicit runtime dependencies include PyYAML and safetensors; YAML typing stubs
are included in the dev group. No training/server dependencies are added. The
lockfile adds the stubs without changing existing package versions; uv also
regenerated resolution-marker ordering.
Excluded: training, edited steering, corpus execution/FVE, SGLang serving,
additional model pairs, multimodal inputs, quantization, arbitrary device maps,
and cross-model/layer transfer.
Correctness and ownership
The facade lives in
transformer_lens/tools/analysis/_nla.py. Experimental userequires an explicit private pair configuration. Only raw fp32/eager execution
is implemented; that restriction is not a released-artifact compatibility claim.
AV normalization matches the reference client's fp32 norm and division order
on ordinary fp32 inputs. A scale-safe fallback handles extreme inputs but is
not claimed as reference-client equivalence in that regime.
Canonical explanation text is the inner content of exactly one complete region.
Parse failures preserve the raw continuation and return
text=None; malformedresponses are not silently passed to AR. AR uses its recorded raw prompt and
special-token convention, not a chat template.
The AR loader accepts exactly the omitted final norm and LM-head weights,
wraps an owned model, bypasses normalization, and executes only its backbone.
It does not rely on an absent block triggering early-stop behavior.
Results own detached vectors; returned targets belong to callers. Unloading
releases NLA-owned references, not externally held allocations. Loading provenance
is not continuous live-weight integrity. Reconstruction similarity is not proof
of human-readable faithfulness or causal validity. Normalized MSE is
2*(1-cosine), not raw vector MSE or dataset FVE.Validation performed
After review fixes:
make formatandmake check-format: passed.wheel package/analysis imports in an isolated subprocess with network blocked.
Build dependency resolution may access the network; package import may not.
Local tests cover cached/uncached hooks, caller-hook preservation, injected-logit
comparison with direct HF, a local truncated-Qwen checkpoint, raw AR output and
LM-head bypass, metadata/parser errors, metric identities, and lifecycle guards.
A forced deterministic continuation passes through real generation, canonical
parsing, and AR reconstruction with sequential model release checks. That tests
the software boundary, not explanation quality or released-model compatibility.
Reproduction
From the implementation worktree, using the project environment:
Local checks reused an existing uv-managed environment with
--no-syncand--with types-PyYAMLfor mypy. The commands above are normal reproductionequivalents. Sphinx was invoked through
docs.make_docs.build_docsto ensureit built this worktree's sources when reusing an editable environment.
Outstanding validation and completion
Released-Qwen parity
All three slow checks were attempted and stopped at their storage prerequisite,
before model loading or tensor comparison. The full workflow required 38.5 GiB
of missing weights plus 2 GiB reserve, versus 11.8 GiB free at that run.
Use a larger HF cache volume, setting
HF_HOMEbefore starting Python, andsufficient memory for one fp32 model plus loading/forward overhead. Execute
models sequentially:
The CPU fp32 tests initially require exact equality. Any nonzero drift must be
investigated and measured before introducing justified tolerances. Released-model
peak RAM/VRAM, timing, and calibrated tolerances have not been established.
Pinned candidate inputs:
Qwen/Qwen2.5-7B-Instruct:a09a35458c702b33eeacc393d103063234e8bc28.kitft/nla-qwen2.5-7b-L20-av:b88469162777ae6553bc14208eb0cb579336f8f4.kitft/nla-qwen2.5-7b-L20-ar:e2c9e57eac213d37a31612087f645ab6332c1bb6.0577769b55ad4fdd96d159e983361b97fa4e7331.These are test inputs, not registered support claims. The oracle executes local
transparent direct-HF code, not downloaded reference Python.
Full standard suite
make test-prtimed out after 200 seconds during unit tests at approximately 44%.No complete standard-suite pass is claimed. Run it to completion and investigate
all failures before recording final acceptance results.
Public support
Public exports and the pinned Qwen registry entry remain withheld pending parity.
They still need actual
from_pretrainedand public-workflow tests, measuredresource documentation, and final-source format/type/full-suite/docs/build checks.
The completed inference infrastructure alone does not satisfy every criterion
of issue #1884.
Type of change
Checklist
References