Skip to content

Fix missing streams in l2_norm and scatter VJP - #4818

Merged
zcbenz merged 2 commits into
ml-explore:mainfrom
Augustas11:stream-complex-norm-scatter-vjp
Nov 20, 2026
Merged

zcbenz merged 2 commits into
ml-explore:mainfrom
Augustas11:stream-complex-norm-scatter-vjp

Conversation

@Augustas11

Copy link
Copy Markdown
Contributor
  • I understand it is strictly prohibited to use AI to write PR description

AI usage disclosure: drafted with AI assistance from a stream audit. Both call sites were checked against multiply and equal in mlx/ops.h, which take a stream. The test suite has not been run locally.

Follow-up to #4746. Two call sites still drop the stream the caller passed, and the stream checker misses them because they are operator overloads.

Complex l2_norm did abs(a, s) * abs(a, s). operator* takes no stream, so the product is built on the thread's default stream. Real inputs already go through square(a, s). The complex path now uses multiply(abs(a, s), abs(a, s), s).

Max and min Scatter::vjp did gathered_result == updates inside a multiply that already received stream(). operator== takes no stream. That comparison is now equal(gathered_result, updates, stream()).

This only changes complex l2_norm and the max/min scatter gradient.

The existing cross-thread test in tests/scheduler_tests.cpp now builds both graphs on a thread-unsafe stream and evaluates them from the other thread: a complex linalg::norm, and a scatter_max VJP.

Augustas from Malibu

@Augustas11

Copy link
Copy Markdown
Contributor Author

cc @zcbenz since you reviewed #4746: could you take a look when you have time? It is a small follow-up: two call sites that still drop the caller's stream (complex l2_norm and the max/min scatter VJP), plus a check in the existing cross-thread test. The "Build and Test" run is awaiting approval.

Augustas11 and others added 2 commits November 20, 2026 10:21
operator* and operator== build on the default stream. Complex l2_norm
and the max/min scatter gradient both went through them.
@zcbenz
zcbenz force-pushed the stream-complex-norm-scatter-vjp branch from 0a84d43 to 25ae03c Compare November 20, 2026 01:22
@zcbenz zcbenz changed the title Pass the caller stream through complex l2_norm and scatter max/min VJP Fix missing streams in l2_norm and scatter VJP Nov 20, 2026
@zcbenz
zcbenz merged commit ab5d01b into ml-explore:main Nov 20, 2026
24 checks passed
rcfa pushed a commit to cubiculum-ai/mlx that referenced this pull request Nov 26, 2026
Co-authored-by: Cheng <git@zcbenz.com>
(cherry picked from commit ab5d01b)
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.

2 participants