Skip to content

[BUG] LoRA/EoRA numerics: lora_alpha/rslora scaling ignored, dynamic-rank EoRA export over-scales in PEFT, EoRA covariance geometrically weighted #3975

Closed

Description

@Qubitium

Audit of main @ a16977e.

1. LoRA loader ignores lora_alpha, use_rslora and alpha_pattern (scale is always 1.0)

gptqmodel/adapter/adapter.py:203-227: Lora.apply returns out + (x @ A) @ B with no scaling. post_init (:229-342) only reads r / rank_pattern. LoraConfig parses lora_alpha, use_rslora and alpha_pattern (peft.py:133,142,204), but nothing consumes them.

Impact: any third-party PEFT adapter with alpha≠r is applied at the wrong magnitude, silently. For example, r=8 and alpha=32 gives a delta 4× too small (repro ratio 4.0005). rsLoRA (alpha/sqrt(r)) is ignored too. EoRA's own exports are unaffected only because they save alpha == r.

Fix: per module, resolve alpha (alpha_pattern or lora_alpha) and r (rank_pattern or r). Use scale = alpha/sqrt(r) if use_rslora, else alpha/r. Then either fold the scale into lora_B once at load (not again at save), or multiply in apply.

2. EoRA export with dynamic per-module rank produces wrong PEFT/vLLM scaling

gptqmodel/models/writer.py:1549-1557 (_eora_save) writes r = lora_alpha = global_rank plus a rank_pattern, but no alpha_pattern. PEFT computes lora_alpha / r_module, so a module overridden to a smaller rank gets scale global/module_rank. EoRA's B·A targets W−Wq at scale 1.

Repro: global rank 16, dynamic={"+:.*\.layers\.1\..*": {"adapter": {"rank": 4}}}, save with the real LoraConfig, load with peft 0.21.2:

layer0: r=16 scaling=1.0
layer1: r=4  scaling=4.0

Loaded in PEFT/vLLM, layer 1's correction is applied 4×, which is worse than no adapter. GPTQModel's own loader is only correct because of bug 1, so fixing bug 1 naively breaks this path too.

Fix: also write alpha_pattern mirroring rank_pattern (alpha = module rank).

3. EoRA activation covariance weights calibration batches geometrically

gptqmodel/eora/eora.py:40-56, with sample_size=self.num_batches (looper/eora_processor.py:157) and total = total*scale + contribution (:207-208).

scale = N/(N+b), where N is the fixed batch count (not a running count) and b is the batch dimension. Batch i ends up weighted by ∏_{j>i} N/(N+b_j) instead of uniformly.

Repro: 16 batches × batch_size 8 gives scale 2/3 per step. The first batch is weighted 2.3e-3 versus 1.0 for the last, so EoRA effectively uses only the last 2–3 batches. Even with bs=1 the first/last ratio is ~e⁻¹. On synthetic data, calibration-set relative output error is 0.791 with the repo covariance versus 0.756 with uniform XᵀX. Existing tests (test_eora_merge.py) only check that the segment merge matches sequential order, not that the result is uniform.

Fix: accumulate plain XᵀX and a token/sample count, then normalize once. The overall scale cancels in the S^{1/2}…S^{-1/2} construction anyway. This also makes the segment-merge machinery unnecessary.

🤖 Generated with Claude Code

Activity

  1. added
    bug
    on Nov 14, 2026
  2. Qubitium commented on Nov 14, 2026

    @Qubitium
    CollaboratorAuthor

    Follow-up review of the merged fix found remaining problems; see #4002.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bug

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions