Skip to content

[BUG] FOEM block-boundary beta fix (#4046) applied only to the Torch path; auto-selected MLX path still skips it (Apple Silicon results diverge) #4548

Closed

Description

@devin-ai-integration

Component: gptqmodel/quantization/foem.py L302-404, MLX dispatch (_should_use_mlx_foem_quantization -> _quantize_foem_weight_mlx_to_torch -> mlx_foem.foem_quantize_weight_mlx). Test oracle: tests/test_mlx_foem_quantization.py::_torch_foem_oracle.
Fix it is incomplete for: 9a53541fb (#4037/#4046). Scanned HEAD: 2195761.

Problem: #4046 made the Torch FOEM loop apply the beta correction to the first column of every block after the first: W[:, i2] -= beta * (W[:, i2] - W_raw[:, i2]). The native MLX kernel, which FOEM.quantize selects automatically, applies the correction only inside a group (if (k + 1 < G)). Its host loop carries the next group forward as remaining[:, G:] - error @ hinv[...] and never corrects that group's first column.

FOEM.quantize (alpha=0, desc_act=False, static_groups=False, mse=0, blocksize == group_size in {16..128}, darwin/arm64)
  -> _should_use_mlx_foem_quantization() == True
  -> foem_quantize_weight_mlx(): no beta correction on column 0 of groups 2..n
(Torch path for the same input: beta correction applied at every block boundary)

Trigger: FOEM with alpha=0 on Apple Silicon, for a weight that spans more than one block. No flag opts in: the default group_size=128 with blocksize=128 passes the gate.

Expected: MLX and Torch paths give the same quantized weights, both with the #4046 boundary correction.

Actual (from code reading): The MLX path keeps the pre-#4046 behaviour. _torch_foem_oracle was not updated either. test_foem_processor_mlx_matches_torch_oracle (128 columns, group 64, two blocks) should now fail on macOS, but the module skips on non-macOS hosts (pytest.skip("Metal kernels require macOS")), so Linux CI cannot catch it.

Impact:

Fix:

  • In foem_quantize_weight_mlx, after remaining = remaining[:, group_size:] - error @ hinv[start:end, end:], apply remaining[:, 0] -= beta * (remaining[:, 0] - raw[:, end]).
  • Update _torch_foem_oracle the same way and run test_foem_processor_mlx_matches_torch_oracle on macOS.
  • Alternatively, until the kernel is fixed, disable MLX dispatch for inputs with more than one block.

Validation status: inconclusive (not run). The validation host was Linux x86_64, where the MLX gate cannot pass. Evidence is static only. To validate on macOS arm64 with mlx: run tests/test_mlx_foem_quantization.py::test_foem_processor_mlx_matches_torch_oracle and compare FOEM(alpha=0) MLX output with the Torch-path output on a weight that spans more than one block.

Activity

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

    @Qubitium
    Collaborator

    Claimed. This issue is now owned by a dedicated worker; a fix PR referencing it will follow.

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