Repository navigation
Conversation
af61a11 to
3ccdffa
Compare
|
Reviewed commit
Validation: Separately, the new |
56e4f44 to
6a43f6f
Compare
Add an inline continuation contract so a downstream processor can run inside the upstream processor's execution frame instead of receiving staged tensors through NamedModule.state. Ownership is explicit: a processor publishes only data it owns. GPTQ publishes wq, w and (for AUTO_NF12) w_packed_source at its POST_QUANTIZE stage; it no longer computes or stages w - wq. EoRA derives the residual itself through the new module_weight_residual() helper, which keeps the fused widening decode. Fusion is opt-in via QuantizeConfig.processor_fusion and off by default: the fused schedule does not replay the corrected upstream weights that the separate EoRA pass installs between its subsets, so the calibration trajectory differs. Consumer forward hooks are composed into the producer's hook, because HookedLinear raises the early-stop exception from inside forward() before ordinary post-forward hooks run. When the producer replaces the wrapped module after the calibration forward, consumers get on_inline_source_replaced() instead of preprocess(), which would discard the segments just collected. Naming: ProcessorStages (not ProcessorLifecycle, which collides with ProcessorLifecycleConfig), ExecutionStage for the plan element, InlineConfig for the fusion declaration.
6a43f6f to
968b1d1
Compare
|
Thanks — all four points are addressed in 1. P1 — inline hook vs. the early stop. Fixed by composing, not registering. 2. P1 — statistics lost on source replacement. Fixed. The post-forward call 3. P2 — parity claim. You are right, and I have withdrawn the claim rather 4. Env-var switch. Also fixed the two Verified here: |
# Conflicts: # gptqmodel/looper/eora_processor.py # gptqmodel/looper/gptq_processor.py # gptqmodel/looper/loop_processor.py # gptqmodel/looper/module_looper.py # gptqmodel/looper/stage_subset.py # tests/test_auto_dtype_cast.py Conflict resolution: - Kept the processor-fusion inline contract (ArtifactScope/InlineConfig/plan) and main's owns_quant_log dedupe. - Kept main's MoE root capture hook; removed GPTQ._w_wq_diff because EoRA derives the residual via module_weight_residual(). - Kept main's AUTO_NF12 NamedModule inventory behavior and added fused-consumer hook composition / on_inline_source_replaced(). - Kept main's layer_modules_for_prefix and threaded inline_processors through subset planning.
main's #4679 replaced the declared-last early stop with a per-subset "members still unseen" countdown, wrapping the producer's pre-hook. This branch composes fused consumers into one `compose_forward_hooks` result before either hook branch, so apply the marker to that composed hook: a fused consumer must also count as captured, and the stop must still fire only after every member ran. tests/module_tree/test_subset.py, tests/test_subset_declared_order_4679.py and tests/test_processor_fusion.py -> 31 passed. ruff clean.
main added `active_padding_mask` to the same import list this branch extended with `ProcessorStages`. Union them; no logic overlap.
gptqmodel/models/base.py: keep main's #4862 try/except around the quantize body (release_failed_run_processors) and pass the branch's processor_fusion kwarg to ModuleLooper inside it.
|
Rebased/merged One conflict, Verified after the merge:
|
# Conflicts: # gptqmodel/looper/eora_processor.py
feat(looper): fuse downstream processors into producers
Summary
Adds an inline continuation contract to
gptqmodel/looperso a downstreamprocessor can execute inside its upstream producer's frame, while the
intermediates are still live, instead of receiving them through
NamedModule.state.First use: GPTQ -> EoRA. GPTQ no longer computes or stages
w - wq; itpublishes the weights it owns (
wqandw), and EoRA derives its own residualat GPTQ's
POST_QUANTIZEstage.Fusion is opt-in and off by default (
QuantizeConfig(processor_fusion=True)).See "Numerical contract" below: the fused schedule is not equivalent to the
separate EoRA pass.
Ownership rule
A processor publishes only data it owns.
w, reconstructionwq, packed dtype-cast sourcewq,w, optionalw_packed_sourcew - wq, adapteradapter(tomodule.state)The subtraction is EoRA's derivation, so
GPTQProcessor._w_wq_diffis gone and"w_wq_diff"is no longer in GPTQ'semits.Flow
Before: two processor passes, precomputed diff
flowchart LR subgraph before["Before: two processor passes"] G0["GPTQ subset 0"] --> G1["GPTQ subset 1"] --> GN["GPTQ subset N"] G0 -.->|"compute + stage w_wq_diff fp32"| ST[("NamedModule.state")] G0 -.->|"stage wq cpu"| ST GN --> E0["EoRA subset 0"] E0 --> E1["EoRA subset 1"] --> EN["EoRA subset N"] ST -.->|"read one layer later"| E0 endAfter: one fused stage, EoRA derives the residual
flowchart LR subgraph after["After: one fused stage"] FWD["producer forward<br/>(hook composed with consumer)"] --> Q["g.quantize()"] Q --> SC["ArtifactScope at POST_QUANTIZE"] SC --> WQ["wq (borrowed)"] SC --> W["w (live source weight)"] SC --> PK["w_packed_source (optional)"] WQ --> EP["EoRA.process() inline"] W --> EP PK --> EP EP --> RES["module_weight_residual(w, wq)"] RES --> AD["adapter -> module.state"] WQ --> FW["install wq"] end AD --> FIN["reverse finalize: EoRA, then GPTQ pack"]What changed
gptqmodel/looper/processor_fusion.pyProcessorStages,InlineConfig,ArtifactScope,ExecutionStage,ProcessorFusionPlan,plan_processor_fusion,compose_forward_hooks,ProcessorFusionErrorgptqmodel/eora/eora.pymodule_weight_residual()— owns the subtraction and the AUTO_NF12 fused decodegptqmodel/looper/loop_processor.pyemits/stages/inline/inline_processors,publish(),dispatch_inline(),on_inline_source_replaced()gptqmodel/looper/gptq_processor.pyemits=("wq", "w"); publisheswq/wand dispatches inline consumers atPOST_QUANTIZE;_w_wq_diffremovedgptqmodel/looper/eora_processor.pyInlineConfig; derives the residual via_resolve_residual(); non-destructiveon_inline_source_replaced()gptqmodel/looper/module_looper.pygptqmodel/looper/stage_layer.pygptqmodel/looper/stage_subset.pygptqmodel/quantization/config.pyprocessor_fusionfield (defaultFalse)tests/test_processor_fusion.pytests/test_auto_dtype_cast.pymodule_weight_residual/ EoRADesign
ProcessorStagesnames points inside a producer:PREPROCESS,POST_QUANTIZE,POST_INSTALL,PRE_RELEASE. It is named "stages" to staydistinct from the existing
ProcessorLifecycleConfig/LoopProcessor.lifecycle.InlineConfigdeclares how a consumer can be fused: allowed producers,injection
stage, whether its forward hook joins the producer's forward, andthe artifacts it consumes/produces.
ArtifactScopeholds recipes, not tensors, until first access. Values areborrowed for the scope's lifetime and invalidated on exit.
detach()is theonly retention path and is counted;
try_get()reads optional artifacts.ExecutionStage/ProcessorFusionPlanare the planned execution order.Fused consumers get no stage of their own.
emits every consumed artifact, opens the requested stage, and the consumer's
can_fuse_with()accepts it. Otherwise the consumer keeps its own stage andthe existing
module.statehandoff.pre_process_fwd_hookinto theproducer's hook (
compose_forward_hooks). A separateregister_forward_hookwould miss the last module of every subset, because
HookedLinear.forward()raises the early-stop exception before ordinary post-forward hooks run.
looper.processorsand are finalized in reverse.
Numerical contract
The fused schedule is not equivalent to the separate EoRA pass, and this PR
does not claim parity:
wq + B @ Abetween its own subsets, so later EoRA subsets see corrected upstream
activations.
exist. Installing them there would change GPTQ's trajectory instead.
Consequently the activation statistics and the resulting adapters differ. That
is why
processor_fusiondefaults toFalseand requires an explicit opt-in.A validated numerical contract for the fused trajectory is a prerequisite for
enabling it by default.
Enabling and safety
Fusion is selected by config only, never by an environment variable:
ModuleLooperadditionally refuses to fuse whendisk_write_expectedis set(checkpoint capture or
offload_to_disk), because those paths still expectseparately staged secondary artifacts.
Consumer compatibility is checked by the consumer itself. EoRA's
can_fuse_with()requires the producer to have prepared the sameCalibrationConfig.datasetobject.Review follow-up
compose_forward_hooks(); regression test modelsHookedLinearrunningforward_hookand then raising the stopinline.preprocess()after module replacement discards collected statisticson_inline_source_replaced(); EoRA refreshes placement only and keeps_segment_accumulatorsAGENTS.mdGPTQMODEL_DISABLE_PROCESSOR_FUSIONdeleted; control moved toQuantizeConfig.processor_fusionVerification
ruff check gptqmodel tests— clean.python3 -m py_compileon every changed file.tests/test_processor_fusion.py: planner selection/fallback, lazy scope,single materialization, replace,
try_get, closed-scope rejection, detachaccounting, hook composition (early-stop ordering, skipped consumers, batch
index copy), and the GPTQ/EoRA contract declarations.
Full GPU numerics/EoRA tests still need to run in CI; this environment has no
torch installed.
Follow-ups
emits = ("wq", "w")in AWQ / QQQ / VPTQ / Paro and drop theirprecomputed
w_wq_diffso EoRA is producer-agnostic.the
disk_write_expectedgate.considering it as a default.