Repository navigation
Conversation
…ng for diffusion LMs
|
|
||
| pre_handle: Optional[RemovableHandle] = None | ||
| if hasattr(self.original_model, "register_forward_pre_hook"): | ||
| pre_handle = self.original_model.register_forward_pre_hook( |
There was a problem hiding this comment.
A forward pre-hook on original_model only fires through __call__. LLaDA2's and Gidd's released generate call self.forward(...) directly, meaning on those adapters the counter never advances, every caching hook returns early, and return_cache=True returns an empty trajectory with no error. Can we drive the counter by something every sampler passes through, with an error when a cache was requested but no step was observed?
| self._check_hook_fireable(req_name, aliases.get(req_name, req_name)) | ||
| normalized_pos_slice: Optional[Union[Slice, SliceInput]] | ||
| if isinstance(pos_slice, slice): | ||
| wrapped_slice = Slice(None) |
There was a problem hiding this comment.
Slice(pos_slice) already accepts a slice object, so the hand-built instance can go; if the SliceInput alias is what's in the way, a cast or adding slice to the alias is simpler.
| """ | ||
|
|
||
| applicable_phases: list[int] = [] | ||
| applicable_phases: list[int] = [1, 2, 3, 4] |
There was a problem hiding this comment.
This flips LLaDA from skipping verify_models to running all four phases. Can you validate this change by completing a verify_models run on a LLaDA checkpoint to confirm the phases pass? If you do not have access to the necessary compute, I can pull down your branch and run some, just let me know.
There was a problem hiding this comment.
We'd rather not add a demo notebook for this. Most of it rebuilds the tiny LLaDA module the integration test already has, and section 4 is a typed-in results table we cannot reproduce in the repo, so it would be documenting a research claim rather than the feature. Please drop the notebook and its docs/CI registrations (including the test_make_docs.py list). There is one check we'd like to keep, that positions already unmasked before a step are unchanged by a patch at that step. Please move it into the LLaDA integration test file. It would also be good to give the sampler port direct tests of its own (temperature > 0, the random and unsupported remasking paths, a multi-block schedule, and the attention_mask branch), since today it only ever runs with defaults.
Description
Adds step-indexed trajectory activation caching (
DiffusionTrajectoryCache) and step-selective activation patching across denoising steps for diffusion LMs onTransformerBridge.diffusion_generate(), wiresLLaDAArchitectureAdapterintodiffusion_generate(), and addsdemos/Diffusion_Trajectory_Patching_Demo.ipynb.Motivation
Autoregressive$x_0 \to x_1 \to \dots \to x_S$ over $S$ denoising steps:
generate(..., return_cache=True)recovers generation activations from a single post-hocrun_with_cache(output_tokens)pass because causal masking keeps earlier positions invariant as new tokens are appended. Masked discrete-diffusion LMs (LLaDA,Dream,LLaDA-2,GIDD) use bidirectional self-attention (is_causal=False) and iteratively unmask a canvasdiffusion_generate()inadd_caching_hooks()overwritescache[name]on every forward pass, discarding stepscache_steps), position (pos_slice), and offload device (device="cpu").What this PR adds
DiffusionTrajectoryCache(transformer_lens/ActivationCache.py):sto a per-stepActivationCache, plusstep_tokens[s]recording the partially-masked input canvasnum_steps_run.stack(key, steps=None)stackscache[s][key]along dim 0 into[n_steps, ...].make_step_patch_hook(hook_name, steps=..., positions=...)builds a forward hook that readsbridge.current_diffusion_stepand patches activations from a recorded trajectory at selected denoising steps and token positions.TransformerBridge.diffusion_generate(..., return_cache=True)(transformer_lens/model_bridge/transformer_bridge.py):return_cache,names_filter,cache_steps(int, iterable ofint, callable predicate, orNone),pos_slice,device, andremove_batch_dim, plusbridge.current_diffusion_step.cache_steps.LLaDAArchitectureAdaptersampler binding (transformer_lens/model_bridge/supported_architectures/llada.py):diffusion_generate) inprepare_modelwhen not already present on the model and declaresnative_sampler = "diffusion_generate"withDiffusionContractTestscoverage.demos/Diffusion_Trajectory_Patching_Demo.ipynb):cache_steps/pos_slicefiltering, and pre- vs. post-commitment activation patching across denoising steps on a compact CPULLaDAModelLMbridge (runs in ~4s undernbval), alongside measuredLLaDA-8B-InstructandDream-v0-Instruct-7BARC-Challenge commitment-order tables (TL_RUN_RELEASED_LLADA=1section forGSAI-ML/LLaDA-8B-Instruct.Type of change
Checklist: