Skip to content

Fork/190 implied bias review fixes - #7

Merged
jeethu merged 4 commits into
prism-0.32.2-fixesfrom
fork/190-implied-bias-review-fixes
Oct 4, 2026
Merged

jeethu merged 4 commits into
prism-0.32.2-fixesfrom
fork/190-implied-bias-review-fixes

Conversation

@jeethu

@jeethu jeethu commented Oct 4, 2026

Copy link
Copy Markdown
Member
  • ☑️ I understand it is strictly prohibited to use AI to write PR description
  • AI usage disclosure:

jeethu added 3 commits October 4, 2026 10:02
Codex review: the comment above implied_bias_kernels_exact ran to 17 lines
and repeated the rounding contract. The contract stays in ops.h, the Python
docstrings and the tests; the code comments keep only the short reason.
Same for the other multi-line implied-bias comments in ops.cpp, the CPU
backend and the Metal host code and kernels. Comment-only change.
Codex review: gather_qmm accepts a 0-d biases factor since 477f91a, but
its docs still said biases must have the batch dimensions of w. State the
scalar form in the ops.h comment and the Python docstring, in the same
words as quantized_matmul and dequantize.
Codex review: where the bias is materialized (fp32 x over fp16 scales,
3/5/6-bit, gather_qmm, CUDA) `scales * f` was a differentiable multiply and
the factor got a nonzero gradient, while the implied-bias kernel path threw
in QuantizedMatmul::vjp. dequantize already gave a nonzero factor gradient
on both paths (its GPU vjp runs the fallback).

The factor is a constant everywhere now:
- materialize_implied_bias applies stop_gradient to the factor, so the
  materialized paths and the dequantize fallback give zero.
- QuantizedMatmul::vjp returns zeros for the factor instead of throwing,
  and jvp gives a zero tangent for it. The scales gradient is unchanged.

A throw on every path would need a custom_vjp, which export cannot
serialize. Documented in ops.h and the quantized_matmul docstring.

Test: test_implied_bias_factor_grad checks vjp and grad wrt the factor
for quantized_matmul, gather_qmm and dequantize (and jvp for
quantized_matmul) on CPU and GPU, on the kernel and materialized paths.
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 4, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-10-04T09:16:23.591485Z 555c386 Manual request
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: d3445fa8c1

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread mlx/primitives.cpp
Comment on lines +3575 to +3577
} else if (arg == 3 && implied) {
// The implied-bias factor is a constant.
vjps.push_back(zeros_like(primals[3], stream()));

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Stop factor gradients in the scale VJP too

When an implied-bias factor uses the direct kernel path, this branch makes its first-order VJP zero, but the scale VJP below still constructs bias_c directly from primals[3]. Consequently, differentiating the scale gradient with respect to the factor produces a nonzero mixed derivative, even though the newly documented contract says no gradient flows to the factor; materialized paths do not have this problem because they apply stop_gradient. Stop the factor before using it to form the scale VJP as well.

Useful? React with 👍 / 👎.

@jeethu

jeethu commented Oct 4, 2026

Copy link
Copy Markdown
Member Author

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. 👍

Reviewed commit: 555c386aa4

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@jeethu
jeethu merged commit a7ed928 into prism-0.32.2-fixes Oct 4, 2026
@jeethu
jeethu deleted the fork/190-implied-bias-review-fixes branch October 4, 2026 09:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant