[WIP] Input-source metadata for module tree definitions (shared-input groundwork) - #3051
Closed
Qubitium wants to merge 6 commits into
Closed
[WIP] Input-source metadata for module tree definitions (shared-input groundwork)#3051Qubitium wants to merge 6 commits into
Qubitium wants to merge 6 commits into
Conversation
Contributor
🤖 Devin AI EngineerI'll be helping with this pull request! Here's what you should know: ✅ I will automatically:
Note: I can only respond to comments from users who have write access to this repository. ⚙️ Control Options:
|
devin-ai-integration
Bot
deleted the
devin/1788500745-input-source-metadata
branch
September 4, 2026 06:12
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.
Summary
Groundwork for deduplicating Hessian / activation-statistic collection across modules that consume the exact same input activation. This PR adds the generic metadata layer + a forward-time validator (no GPTQ math or hook-sharing changes yet):
:Nkeeps meaning "calculation/replay subset":input= this module has its own unique input source:input=<name>= named alternate input shared by same-named modules in the same structural scopeExisting definition strings (
"q_proj:0", roles:q/:k/:v/:gate/:up,:!,:?,:moe) are unchanged andbuild_layer_modules()output is byte-identical (input tokens are metadata-only and never emitted).What Changed
gptqmodel/models/input_source.py(new, GPTQ-agnostic):BaseQModel:_parse_module_spec()(name, flags, input_spec);_parse_module_flags()now hides input tokens from all existing flag consumers._build_layer_modules_for_tree(..., entries_out=)records aModuleTreeEntryper path;build_module_tree_entries()/resolve_module_tree_entry(name)(cached per class;mlp.experts.{expert_index}.up_projmatchesmlp.experts.7.up_projand yields scopemlp.experts.7, so expert 0 and expert 1 never share a source).NamedModulegainstree_scope_id,subset_id,input_spec;ModuleLooper.create_named_modulesfills them from the model definition (tree_scope_id = f"{layer_prefix}.{entry.scope}"). Unknown/lm_head modules resolve to a unique (never-merged) source.SubsetPlan.input_sources: dict[InputSourceId, list[NamedModule]], recomputed byfor_modules()chunks.gptqmodel/looper/input_source_validator.py(new):InputSourceCapture(forward pre-hooks recording each module's input tensor),validate_input_sources(groups, captured) -> InputSourceValidationReport(identity/storage fast path → shape → dtype →torch.equal; reasonscall_count|shape|dtype|value),InputSourceValidationErrornaming source, modules and shapes.QuantizeConfig.validate_input_sources: bool = False(debug mode, serialized likeauto_forward_data_parallel). When on,build_subset_planforces serial forward and_run_single_subset_passcaptures + validates every multi-module input-source group of the subset, logsInput-source validation: layer=… checked_sources=… checked_modules=…and raises on mismatch.q_b_proj/kv_b_projconsume normalized latents →:input; DSAindexer.wq_bshares the Q latent withq_b_proj→:input=q_latenton both. Dense Llama/Qwen definitions untouched.Out of scope (later PRs): shared Hessian accumulator per
InputSourceId, hook dedup (one capture owner per source), lifecycle/ownership, placement optimizations.Tests
All CPU-only, tiny synthetic configs (hidden 32, 1 layer, 4 experts), real transformers modeling code, experts unfused via
defuser.convert_modelexactly as the loader does:tests/module_tree/test_input_source.py— parser cases (q_proj:0,:input,:input=foo, with/without role tags,!/?, error cases), block-output back-compat, entry/scope resolution incl. expert templates,InputSourceIdgrouping on tiny Llama / DeepSeek-V3 / Qwen2-MoE / Qwen3-MoE,SubsetPlan.input_sources+ chunk recomputation.tests/module_tree/test_input_source_validator.py— validator unit tests (identity fast path, equal values, shape/dtype/value/call_count reasons,max_calls, kwargs capture).tests/module_tree/test_input_source_forward.py— full tiny-model forward with capture hooks, asserting every declared group actually receives identical inputs: Llama (q/k/v, gate/up), Qwen2-MoE, Qwen3-MoE, Mixtral (per-expert gate/up + shared expert), DeepSeek-V3, MiniCPM3, DeepSeek-V3.2, GLM-MoE-DSA (q_b_proj+indexer.wq_bshareq_latent,kv_b_projalone), GLM4-MoE-Lite. Negative tests prove the validator catches the pre-annotation groupings (q_b_proj+kv_b_proj, expert0+expert1gate_proj,q_proj+o_proj). DeepSeek-V4 and GLM5-Next are skipped with reason (tiny-config constraints in transformers 5.16).tests/module_tree/test_input_source_quantize.py— end-to-end CPU GPTQ quantize of a tiny Llama withvalidate_input_sources=True; asserts the validation log lines and config round-trip.Review Requirements
Notes
WIP. Semantics are additive; nothing consumes
SubsetPlan.input_sourcesfor Hessian sharing yet — that is the next phase.deepseek_vl_v2annotation follows the DeepSeek-V2 MLA pattern but could not be validated by forward simulation (no modeling code in transformers 5.16).