MLX: add native_group_norm and upsample_nearest2d handlers - #22050

Merged
metascroy merged 1 commit into
pytorch:mainfrom
msluszniak:ms/mlx-group-norm-upsample
Aug 26, 2026
Merged

MLX: add native_group_norm and upsample_nearest2d handlers#22050
metascroy merged 1 commit into
pytorch:mainfrom
msluszniak:ms/mlx-group-norm-upsample

Conversation

@msluszniak

@msluszniakmsluszniak commented Aug 22, 2026

Copy link
Copy Markdown
Contributor

Summary

Fixes#22017.

The MLX backend has no handler for aten.native_group_norm or aten.upsample_nearest2d. GroupNorm sits in every ResBlock of a Stable-Diffusion-style UNet and nearest upsampling sits in every decoder stage, so the two gaps together shatter a diffusion model rather than merely slowing it down.

Measured on the SDXS-512-DreamShaper UNet (SD-1.5 architecture, 4x64x64 latents):

delegate subgraphsnodes left on CPU
before2825x native_group_norm, 2x upsample_nearest2d
after1none

Each of those 27 boundaries was a delegate handoff per denoise call, leaving and re-entering the MLX runtime.

Both ops lower to primitives the backend already has, so this needs no schema or runtime change.

Approach

native_group_norm normalizes each group of C / group channels together with all of their spatial positions. Reshaping the input to (N * group, (C / group) * HxW) puts exactly that set on the last axis, so fast::layer_norm computes the normalization as a single fused kernel. The affine parameters are applied afterwards on the original shape rather than being passed to layer_norm, because group norm's weight and bias are per channel while layer_norm's are per normalized element; the two only coincide when every group holds a single channel. Only the normalized output is produced, matching the existing native_layer_norm handler's treatment of mean/rstd.

upsample_nearest2d becomes take(take(x, idx_h, -2), idx_w, -1). The source index for an output position is min(floor(dst * scale), in_size - 1) (aten's nearest_neighbor_compute_source_index), which depends only on the static input and output sizes, so both index vectors are constants. Expressing it as a gather rather than a repeat also covers non-integer scale factors and downsampling. Both the .vec and .default overloads are registered.

Test plan

Adds group_norm and upsample_nearest2d to backends/mlx/test/test_ops.py, 11 configurations in total:

  • group norm: affine and non-affine, one channel per group (instance norm) and one group for all channels, a non-square spatial extent, and a 3D (N, C, L) input
  • upsampling: integer, anisotropic and fractional scale factors, an explicit output size, and downsampling

All 11 match eager through the MLX runtime; the upsample ones are bit-exact (rtol = atol = 0).

python -m executorch.backends.mlx.test.run_all_tests group_norm upsample_nearest2d

cc @metascroy

@pytorch-bot

pytorch-botBot commented Aug 22, 2026

Copy link
Copy Markdown

🔗 Helpful Links

🧪 See artifacts and rendered test results at hud.pytorch.org/pr/pytorch/executorch/22050

Note: Links to docs will display an error until the docs builds have been completed.

⚠️ 1 Awaiting Approval

As of commit bb67233 with merge base fbd4bbf (image):

AWAITING APPROVAL - The following workflow needs approval before CI can run:

This comment was automatically generated by Dr. CI and updates every 15 minutes.

@meta-clameta-claBot added the CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. label Aug 22, 2026
@linux-foundation-easycla

linux-foundation-easyclaBot commented Aug 22, 2026

Copy link
Copy Markdown

CLA Signed
The committers listed above are authorized under a signed CLA.

  • ✅ login: msluszniak / name: Mateusz Słuszniak (bb67233)

@github-actions

Copy link
Copy Markdown

This PR needs a release notes: label

If your change should be included in the release notes (i.e. would users of this library care about this change?), please use a label starting with release notes:. This helps us keep track and include your important work in the next release notes.

To add a label, you can comment to pytorchbot, for example
@pytorchbot label "release notes: none"

For more information, see
https://github.com/pytorch/pytorch/wiki/PyTorch-AutoLabel-Bot#why-categorize-for-release-notes-and-how-does-it-work.

The MLX backend had no handler for aten.native_group_norm or
aten.upsample_nearest2d. GroupNorm sits in every ResBlock of a
Stable-Diffusion-style UNet and nearest upsampling sits in every decoder
stage, so the two gaps together shatter a diffusion model instead of
merely slowing it down: the SDXS-512-DreamShaper UNet partitions into 28
delegate subgraphs, leaving 25 native_group_norm and 2
upsample_nearest2d nodes on the CPU, and each boundary crossing leaves
and re-enters the MLX runtime.
Both ops lower to primitives the backend already has, so this needs no
schema or runtime change.
native_group_norm normalizes each group of C / group channels together
with all of their spatial positions, so reshaping the input to
(N * group, (C / group) * HxW) puts exactly that set on the last axis and
fast::layer_norm computes it as one fused kernel. The affine parameters
are applied afterwards on the original shape rather than being handed to
layer_norm, because group norm's weight and bias are per channel while
layer_norm's are per normalized element; the two only coincide when every
group holds a single channel.
upsample_nearest2d becomes take(take(x, idx_h, -2), idx_w, -1). The
source index for an output position is
min(floor(dst * scale), in_size - 1), which depends only on the static
input and output sizes, so both index vectors are constants. Expressing
it as a gather rather than a repeat also covers non-integer scale factors
and downsampling.
With the handlers registered the same UNet lowers to a single delegate
subgraph with nothing left on the CPU.
Adds op tests for both: group norm over affine and non-affine, one
channel per group and one group for all channels, non-square spatial
extents and a 3D (N, C, L) input; upsampling over integer, anisotropic
and fractional scale factors, explicit output sizes and downsampling.
All 11 configurations match eager through the MLX runtime, the upsample
ones bit-exactly.
Fixespytorch#22017
@msluszniak
msluszniakforce-pushed the ms/mlx-group-norm-upsample branch from 9d8cb4a to bb67233CompareAugust 22, 2026 17:15
@metascroy

Copy link
Copy Markdown
Contributor

@claude review this code

@claude

claudeBot commented Aug 25, 2026

Copy link
Copy Markdown

Claude finished @metascroy's task in 6m 14s —— View job


Code Review

  • Read changed files (ops.py, test_ops.py)
  • Analyze native_group_norm handler
  • Analyze upsample_nearest2d handler
  • Review test coverage

Nice work — this is a clean, well-reasoned pair of handlers, and the commit message / PR description do an excellent job explaining why the decomposition is correct. Both handlers reuse existing primitives and follow the conventions of the surrounding code (native_layer_norm, the used_getitem_indices guard, require_args/require_kwargs, slot allocation). I ran through the logic carefully; below are the findings, ordered by importance.


1. Index computation precision vs. aten (potential correctness edge) — ops.py_nearest_source_indices

aten's nearest_neighbor_compute_source_index computes floor(dst_index * scale) in float32 (the kernel casts scale to float, see kernels/portable/cpu/util/upsample_util.h:140-149 and the const float scale_h signature in op_upsample_nearest2d.cpp:76). Eager PyTorch's reference does the same. This handler computes it in float64:

idx= (torch.arange(out_size, dtype=torch.float64) *step).to(torch.int64)

For the tested sizes this is bit-exact, but float32 and float64 can floor to different integers when dst * scale lands just below an integer boundary at larger output indices (e.g. tall/wide feature maps with a non-power-of-two scale — exactly the diffusion-decoder case this PR targets). Since the whole point of the backend is to match eager, matching aten's float32 arithmetic removes that risk:

step= ... # floatidx= (torch.arange(out_size, dtype=torch.float32) *torch.float32(step)).floor().to(torch.int64)

I'd flag this as worth confirming rather than a definite bug — the divergence only appears at boundary values the current tests don't hit. A test with a large odd spatial extent + fractional scale (e.g. shape=(1,3,127,127), scale_factor=(1.7,1.7)) would either confirm parity or surface it. Fix this →

2. native_group_norm reshape assumes NCHW-contiguous input

The reshape to (N*group, (C//group)*HxW) is only equivalent to per-group normalization if the group * (C//group) channels are laid out channel-major (standard NCHW contiguous), so that one group's channels are adjacent. This matches eager's own x.reshape(N, group, -1) decomposition and is almost certainly the layout the backend already works in, so this is likely fine — but it's an implicit assumption worth a one-line comment, since a channels-last input would silently produce wrong groupings rather than an error. Worth confirming the MLX partitioner never hands this handler a non-contiguous/channels-last tensor.

3. .vec detection via string match — minor robustness

if".vec"instr(n.target):

This works, but comparing the target directly is less fragile and reads better:

ifn.targetistorch.ops.aten.upsample_nearest2d.vec:

Things I checked that look correct

  • getitem guard: correctly rejects use of mean/rstd (indices 1/2), mirroring native_layer_norm. ✅
  • Affine application: the four-way branch (no affine / weight-only / bias-only / both) routes the final write into the node's real output slot out in every path, with temporaries otherwise. Verified each branch. ✅
  • affine_shape[1, C, 1, ...] broadcasts per-channel weight/bias correctly for both 4D and 3D (N,C,L) inputs (x_ndim - 2 trailing ones). ✅
  • Static-shape guards: N/C/HxW/group and input/output spatial sizes are all validated as int with clear error messages. ✅
  • Constant dedup: the constant name encodes in_size/out_size/scale, so identical index vectors are shared and distinct ones don't collide. ✅
  • require_args bounds: native_group_norm (8,8) and both upsample overloads match the aten schemas. ✅

Test coverage

Coverage is thorough for the common cases: affine/non-affine, instance-norm and single-group extremes, non-square and 3D inputs for group norm; integer/anisotropic/fractional/explicit-size/downsample for upsample, with rtol=atol=0. The one gap is the float32/float64 boundary case noted in #1 — a large-extent fractional-scale config would close it.


Overall this is a solid, self-contained change that fixes a real partitioning cliff for diffusion UNets. My only substantive ask is confirming the float-precision behavior in #1; the rest are minor.
· branch ms/mlx-group-norm-upsample

@metascroy

Copy link
Copy Markdown
Contributor

Thanks for the contribution! If CI passes, we can merge

@metascroy
metascroy merged commit 0cf9774 into pytorch:mainAug 26, 2026
259 of 260 checks passed
@metascroy

Copy link
Copy Markdown
Contributor

Thanks for the contribution @msluszniak!

@nil-is-allnil-is-all added the module: mlx Issues related to MLX Backend: Metal-accelerated inference on Apple Silicon label Aug 31, 2026
Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ciflow/mlxCLA SignedThis label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed.module: mlxIssues related to MLX Backend: Metal-accelerated inference on Apple Silicon

Projects

None yet

Development

Successfully merging this pull request may close these issues.

MLX backend: missing aten.native_group_norm and upsample_nearest2d fragment a diffusion UNet into 28 subgraphs

3 participants

@msluszniak@metascroy@nil-is-all
, 'i'); if (__m === '*' || __re.test(location.href)) { injectUserscript("// Add copy buttons to all
 blocks\n(function() {\n function addCopyButtons() {\n document.querySelectorAll('pre code').forEach(function(codeBlock) {\n if (codeBlock.parentElement.hasAttribute('data-copy-added')) return;\n codeBlock.parentElement.setAttribute('data-copy-added', 'true');\n \n var btn = document.createElement('button');\n btn.textContent = 'Copy';\n btn.style.cssText = 'position:absolute;top:4px;right:4px;padding:2px 8px;font-size:11px;background:#4ecdc4;border:none;border-radius:4px;color:#1a1a2e;cursor:pointer;opacity:0.7;transition:opacity 0.2s;';\n btn.onmouseover = function() { this.style.opacity = '1'; };\n btn.onmouseout = function() { this.style.opacity = '0.7'; };\n btn.onclick = function() {\n navigator.clipboard.writeText(codeBlock.textContent).then(function() {\n btn.textContent = 'Copied!';\n setTimeout(function() { btn.textContent = 'Copy'; }, 1500);\n });\n };\n codeBlock.parentElement.style.position = 'relative';\n codeBlock.parentElement.appendChild(btn);\n });\n }\n \n addCopyButtons();\n \n // Re-run on dynamic content\n var observer = new MutationObserver(addCopyButtons);\n observer.observe(document.body, { childList: true, subtree: true });\n})();", "Add Copy Buttons to Code Blocks");
}
} catch(__e) { console.warn('[Userscript:Add Copy Buttons to Code Blocks]', __e); }
})();
(function(){
try {
var __m = "github.com";
var __re = new RegExp('^' + "github\\.com" + '
Skip to content

MLX: add native_group_norm and upsample_nearest2d handlers - #22050

Merged
metascroy merged 1 commit into
pytorch:mainfrom
msluszniak:ms/mlx-group-norm-upsample
Aug 26, 2026
Merged

MLX: add native_group_norm and upsample_nearest2d handlers#22050
metascroy merged 1 commit into
pytorch:mainfrom
msluszniak:ms/mlx-group-norm-upsample

Conversation

@msluszniak

@msluszniakmsluszniak commented Aug 22, 2026

Copy link
Copy Markdown
Contributor

Summary

Fixes#22017.

The MLX backend has no handler for aten.native_group_norm or aten.upsample_nearest2d. GroupNorm sits in every ResBlock of a Stable-Diffusion-style UNet and nearest upsampling sits in every decoder stage, so the two gaps together shatter a diffusion model rather than merely slowing it down.

Measured on the SDXS-512-DreamShaper UNet (SD-1.5 architecture, 4x64x64 latents):

delegate subgraphsnodes left on CPU
before2825x native_group_norm, 2x upsample_nearest2d
after1none

Each of those 27 boundaries was a delegate handoff per denoise call, leaving and re-entering the MLX runtime.

Both ops lower to primitives the backend already has, so this needs no schema or runtime change.

Approach

native_group_norm normalizes each group of C / group channels together with all of their spatial positions. Reshaping the input to (N * group, (C / group) * HxW) puts exactly that set on the last axis, so fast::layer_norm computes the normalization as a single fused kernel. The affine parameters are applied afterwards on the original shape rather than being passed to layer_norm, because group norm's weight and bias are per channel while layer_norm's are per normalized element; the two only coincide when every group holds a single channel. Only the normalized output is produced, matching the existing native_layer_norm handler's treatment of mean/rstd.

upsample_nearest2d becomes take(take(x, idx_h, -2), idx_w, -1). The source index for an output position is min(floor(dst * scale), in_size - 1) (aten's nearest_neighbor_compute_source_index), which depends only on the static input and output sizes, so both index vectors are constants. Expressing it as a gather rather than a repeat also covers non-integer scale factors and downsampling. Both the .vec and .default overloads are registered.

Test plan

Adds group_norm and upsample_nearest2d to backends/mlx/test/test_ops.py, 11 configurations in total:

  • group norm: affine and non-affine, one channel per group (instance norm) and one group for all channels, a non-square spatial extent, and a 3D (N, C, L) input
  • upsampling: integer, anisotropic and fractional scale factors, an explicit output size, and downsampling

All 11 match eager through the MLX runtime; the upsample ones are bit-exact (rtol = atol = 0).

python -m executorch.backends.mlx.test.run_all_tests group_norm upsample_nearest2d

cc @metascroy

@pytorch-bot

pytorch-botBot commented Aug 22, 2026

Copy link
Copy Markdown

🔗 Helpful Links

🧪 See artifacts and rendered test results at hud.pytorch.org/pr/pytorch/executorch/22050

Note: Links to docs will display an error until the docs builds have been completed.

⚠️ 1 Awaiting Approval

As of commit bb67233 with merge base fbd4bbf (image):

AWAITING APPROVAL - The following workflow needs approval before CI can run:

This comment was automatically generated by Dr. CI and updates every 15 minutes.

@meta-clameta-claBot added the CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. label Aug 22, 2026
@linux-foundation-easycla

linux-foundation-easyclaBot commented Aug 22, 2026

Copy link
Copy Markdown

CLA Signed
The committers listed above are authorized under a signed CLA.

  • ✅ login: msluszniak / name: Mateusz Słuszniak (bb67233)

@github-actions

Copy link
Copy Markdown

This PR needs a release notes: label

If your change should be included in the release notes (i.e. would users of this library care about this change?), please use a label starting with release notes:. This helps us keep track and include your important work in the next release notes.

To add a label, you can comment to pytorchbot, for example
@pytorchbot label "release notes: none"

For more information, see
https://github.com/pytorch/pytorch/wiki/PyTorch-AutoLabel-Bot#why-categorize-for-release-notes-and-how-does-it-work.

The MLX backend had no handler for aten.native_group_norm or
aten.upsample_nearest2d. GroupNorm sits in every ResBlock of a
Stable-Diffusion-style UNet and nearest upsampling sits in every decoder
stage, so the two gaps together shatter a diffusion model instead of
merely slowing it down: the SDXS-512-DreamShaper UNet partitions into 28
delegate subgraphs, leaving 25 native_group_norm and 2
upsample_nearest2d nodes on the CPU, and each boundary crossing leaves
and re-enters the MLX runtime.
Both ops lower to primitives the backend already has, so this needs no
schema or runtime change.
native_group_norm normalizes each group of C / group channels together
with all of their spatial positions, so reshaping the input to
(N * group, (C / group) * HxW) puts exactly that set on the last axis and
fast::layer_norm computes it as one fused kernel. The affine parameters
are applied afterwards on the original shape rather than being handed to
layer_norm, because group norm's weight and bias are per channel while
layer_norm's are per normalized element; the two only coincide when every
group holds a single channel.
upsample_nearest2d becomes take(take(x, idx_h, -2), idx_w, -1). The
source index for an output position is
min(floor(dst * scale), in_size - 1), which depends only on the static
input and output sizes, so both index vectors are constants. Expressing
it as a gather rather than a repeat also covers non-integer scale factors
and downsampling.
With the handlers registered the same UNet lowers to a single delegate
subgraph with nothing left on the CPU.
Adds op tests for both: group norm over affine and non-affine, one
channel per group and one group for all channels, non-square spatial
extents and a 3D (N, C, L) input; upsampling over integer, anisotropic
and fractional scale factors, explicit output sizes and downsampling.
All 11 configurations match eager through the MLX runtime, the upsample
ones bit-exactly.
Fixespytorch#22017
@msluszniak
msluszniakforce-pushed the ms/mlx-group-norm-upsample branch from 9d8cb4a to bb67233CompareAugust 22, 2026 17:15
@metascroy

Copy link
Copy Markdown
Contributor

@claude review this code

@claude

claudeBot commented Aug 25, 2026

Copy link
Copy Markdown

Claude finished @metascroy's task in 6m 14s —— View job


Code Review

  • Read changed files (ops.py, test_ops.py)
  • Analyze native_group_norm handler
  • Analyze upsample_nearest2d handler
  • Review test coverage

Nice work — this is a clean, well-reasoned pair of handlers, and the commit message / PR description do an excellent job explaining why the decomposition is correct. Both handlers reuse existing primitives and follow the conventions of the surrounding code (native_layer_norm, the used_getitem_indices guard, require_args/require_kwargs, slot allocation). I ran through the logic carefully; below are the findings, ordered by importance.


1. Index computation precision vs. aten (potential correctness edge) — ops.py_nearest_source_indices

aten's nearest_neighbor_compute_source_index computes floor(dst_index * scale) in float32 (the kernel casts scale to float, see kernels/portable/cpu/util/upsample_util.h:140-149 and the const float scale_h signature in op_upsample_nearest2d.cpp:76). Eager PyTorch's reference does the same. This handler computes it in float64:

idx= (torch.arange(out_size, dtype=torch.float64) *step).to(torch.int64)

For the tested sizes this is bit-exact, but float32 and float64 can floor to different integers when dst * scale lands just below an integer boundary at larger output indices (e.g. tall/wide feature maps with a non-power-of-two scale — exactly the diffusion-decoder case this PR targets). Since the whole point of the backend is to match eager, matching aten's float32 arithmetic removes that risk:

step= ... # floatidx= (torch.arange(out_size, dtype=torch.float32) *torch.float32(step)).floor().to(torch.int64)

I'd flag this as worth confirming rather than a definite bug — the divergence only appears at boundary values the current tests don't hit. A test with a large odd spatial extent + fractional scale (e.g. shape=(1,3,127,127), scale_factor=(1.7,1.7)) would either confirm parity or surface it. Fix this →

2. native_group_norm reshape assumes NCHW-contiguous input

The reshape to (N*group, (C//group)*HxW) is only equivalent to per-group normalization if the group * (C//group) channels are laid out channel-major (standard NCHW contiguous), so that one group's channels are adjacent. This matches eager's own x.reshape(N, group, -1) decomposition and is almost certainly the layout the backend already works in, so this is likely fine — but it's an implicit assumption worth a one-line comment, since a channels-last input would silently produce wrong groupings rather than an error. Worth confirming the MLX partitioner never hands this handler a non-contiguous/channels-last tensor.

3. .vec detection via string match — minor robustness

if".vec"instr(n.target):

This works, but comparing the target directly is less fragile and reads better:

ifn.targetistorch.ops.aten.upsample_nearest2d.vec:

Things I checked that look correct

  • getitem guard: correctly rejects use of mean/rstd (indices 1/2), mirroring native_layer_norm. ✅
  • Affine application: the four-way branch (no affine / weight-only / bias-only / both) routes the final write into the node's real output slot out in every path, with temporaries otherwise. Verified each branch. ✅
  • affine_shape[1, C, 1, ...] broadcasts per-channel weight/bias correctly for both 4D and 3D (N,C,L) inputs (x_ndim - 2 trailing ones). ✅
  • Static-shape guards: N/C/HxW/group and input/output spatial sizes are all validated as int with clear error messages. ✅
  • Constant dedup: the constant name encodes in_size/out_size/scale, so identical index vectors are shared and distinct ones don't collide. ✅
  • require_args bounds: native_group_norm (8,8) and both upsample overloads match the aten schemas. ✅

Test coverage

Coverage is thorough for the common cases: affine/non-affine, instance-norm and single-group extremes, non-square and 3D inputs for group norm; integer/anisotropic/fractional/explicit-size/downsample for upsample, with rtol=atol=0. The one gap is the float32/float64 boundary case noted in #1 — a large-extent fractional-scale config would close it.


Overall this is a solid, self-contained change that fixes a real partitioning cliff for diffusion UNets. My only substantive ask is confirming the float-precision behavior in #1; the rest are minor.
· branch ms/mlx-group-norm-upsample

@metascroy

Copy link
Copy Markdown
Contributor

Thanks for the contribution! If CI passes, we can merge

@metascroy
metascroy merged commit 0cf9774 into pytorch:mainAug 26, 2026
259 of 260 checks passed
@metascroy

Copy link
Copy Markdown
Contributor

Thanks for the contribution @msluszniak!

@nil-is-allnil-is-all added the module: mlx Issues related to MLX Backend: Metal-accelerated inference on Apple Silicon label Aug 31, 2026
Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ciflow/mlxCLA SignedThis label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed.module: mlxIssues related to MLX Backend: Metal-accelerated inference on Apple Silicon

Projects

None yet

Development

Successfully merging this pull request may close these issues.

MLX backend: missing aten.native_group_norm and upsample_nearest2d fragment a diffusion UNet into 28 subgraphs

3 participants

@msluszniak@metascroy@nil-is-all
, 'i'); if (__m === '*' || __re.test(location.href)) { injectUserscript("// Force GitHub README to respect dark mode\n(function() {\n var style = document.createElement('style');\n style.textContent = '\n .markdown-body {\n color-scheme: dark light;\n }\n .markdown-body pre { background: #161b22 !important; }\n .markdown-body code { background: rgba(110, 118, 129, 0.4) !important; }\n .markdown-body table th, .markdown-body table td { border-color: #30363d !important; }\n .markdown-body img { background: #0d1117; }\n .markdown-body blockquote { border-left-color: #8b949e; }\n .markdown-body hr { border-color: #30363d; }\n ';\n document.head.appendChild(style);\n})();", "GitHub Dark Mode README Fix"); } } catch(__e) { console.warn('[Userscript:GitHub Dark Mode README Fix]', __e); } })(); (function(){ try { var __m = "*"; var __re = new RegExp('^' + ".*" + '
Skip to content

MLX: add native_group_norm and upsample_nearest2d handlers - #22050

Merged
metascroy merged 1 commit into
pytorch:mainfrom
msluszniak:ms/mlx-group-norm-upsample
Aug 26, 2026
Merged

MLX: add native_group_norm and upsample_nearest2d handlers#22050
metascroy merged 1 commit into
pytorch:mainfrom
msluszniak:ms/mlx-group-norm-upsample

Conversation

@msluszniak

@msluszniakmsluszniak commented Aug 22, 2026

Copy link
Copy Markdown
Contributor

Summary

Fixes#22017.

The MLX backend has no handler for aten.native_group_norm or aten.upsample_nearest2d. GroupNorm sits in every ResBlock of a Stable-Diffusion-style UNet and nearest upsampling sits in every decoder stage, so the two gaps together shatter a diffusion model rather than merely slowing it down.

Measured on the SDXS-512-DreamShaper UNet (SD-1.5 architecture, 4x64x64 latents):

delegate subgraphsnodes left on CPU
before2825x native_group_norm, 2x upsample_nearest2d
after1none

Each of those 27 boundaries was a delegate handoff per denoise call, leaving and re-entering the MLX runtime.

Both ops lower to primitives the backend already has, so this needs no schema or runtime change.

Approach

native_group_norm normalizes each group of C / group channels together with all of their spatial positions. Reshaping the input to (N * group, (C / group) * HxW) puts exactly that set on the last axis, so fast::layer_norm computes the normalization as a single fused kernel. The affine parameters are applied afterwards on the original shape rather than being passed to layer_norm, because group norm's weight and bias are per channel while layer_norm's are per normalized element; the two only coincide when every group holds a single channel. Only the normalized output is produced, matching the existing native_layer_norm handler's treatment of mean/rstd.

upsample_nearest2d becomes take(take(x, idx_h, -2), idx_w, -1). The source index for an output position is min(floor(dst * scale), in_size - 1) (aten's nearest_neighbor_compute_source_index), which depends only on the static input and output sizes, so both index vectors are constants. Expressing it as a gather rather than a repeat also covers non-integer scale factors and downsampling. Both the .vec and .default overloads are registered.

Test plan

Adds group_norm and upsample_nearest2d to backends/mlx/test/test_ops.py, 11 configurations in total:

  • group norm: affine and non-affine, one channel per group (instance norm) and one group for all channels, a non-square spatial extent, and a 3D (N, C, L) input
  • upsampling: integer, anisotropic and fractional scale factors, an explicit output size, and downsampling

All 11 match eager through the MLX runtime; the upsample ones are bit-exact (rtol = atol = 0).

python -m executorch.backends.mlx.test.run_all_tests group_norm upsample_nearest2d

cc @metascroy

@pytorch-bot

pytorch-botBot commented Aug 22, 2026

Copy link
Copy Markdown

🔗 Helpful Links

🧪 See artifacts and rendered test results at hud.pytorch.org/pr/pytorch/executorch/22050

Note: Links to docs will display an error until the docs builds have been completed.

⚠️ 1 Awaiting Approval

As of commit bb67233 with merge base fbd4bbf (image):

AWAITING APPROVAL - The following workflow needs approval before CI can run:

This comment was automatically generated by Dr. CI and updates every 15 minutes.

@meta-clameta-claBot added the CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. label Aug 22, 2026
@linux-foundation-easycla

linux-foundation-easyclaBot commented Aug 22, 2026

Copy link
Copy Markdown

CLA Signed
The committers listed above are authorized under a signed CLA.

  • ✅ login: msluszniak / name: Mateusz Słuszniak (bb67233)

@github-actions

Copy link
Copy Markdown

This PR needs a release notes: label

If your change should be included in the release notes (i.e. would users of this library care about this change?), please use a label starting with release notes:. This helps us keep track and include your important work in the next release notes.

To add a label, you can comment to pytorchbot, for example
@pytorchbot label "release notes: none"

For more information, see
https://github.com/pytorch/pytorch/wiki/PyTorch-AutoLabel-Bot#why-categorize-for-release-notes-and-how-does-it-work.

The MLX backend had no handler for aten.native_group_norm or
aten.upsample_nearest2d. GroupNorm sits in every ResBlock of a
Stable-Diffusion-style UNet and nearest upsampling sits in every decoder
stage, so the two gaps together shatter a diffusion model instead of
merely slowing it down: the SDXS-512-DreamShaper UNet partitions into 28
delegate subgraphs, leaving 25 native_group_norm and 2
upsample_nearest2d nodes on the CPU, and each boundary crossing leaves
and re-enters the MLX runtime.
Both ops lower to primitives the backend already has, so this needs no
schema or runtime change.
native_group_norm normalizes each group of C / group channels together
with all of their spatial positions, so reshaping the input to
(N * group, (C / group) * HxW) puts exactly that set on the last axis and
fast::layer_norm computes it as one fused kernel. The affine parameters
are applied afterwards on the original shape rather than being handed to
layer_norm, because group norm's weight and bias are per channel while
layer_norm's are per normalized element; the two only coincide when every
group holds a single channel.
upsample_nearest2d becomes take(take(x, idx_h, -2), idx_w, -1). The
source index for an output position is
min(floor(dst * scale), in_size - 1), which depends only on the static
input and output sizes, so both index vectors are constants. Expressing
it as a gather rather than a repeat also covers non-integer scale factors
and downsampling.
With the handlers registered the same UNet lowers to a single delegate
subgraph with nothing left on the CPU.
Adds op tests for both: group norm over affine and non-affine, one
channel per group and one group for all channels, non-square spatial
extents and a 3D (N, C, L) input; upsampling over integer, anisotropic
and fractional scale factors, explicit output sizes and downsampling.
All 11 configurations match eager through the MLX runtime, the upsample
ones bit-exactly.
Fixespytorch#22017
@msluszniak
msluszniakforce-pushed the ms/mlx-group-norm-upsample branch from 9d8cb4a to bb67233CompareAugust 22, 2026 17:15
@metascroy

Copy link
Copy Markdown
Contributor

@claude review this code

@claude

claudeBot commented Aug 25, 2026

Copy link
Copy Markdown

Claude finished @metascroy's task in 6m 14s —— View job


Code Review

  • Read changed files (ops.py, test_ops.py)
  • Analyze native_group_norm handler
  • Analyze upsample_nearest2d handler
  • Review test coverage

Nice work — this is a clean, well-reasoned pair of handlers, and the commit message / PR description do an excellent job explaining why the decomposition is correct. Both handlers reuse existing primitives and follow the conventions of the surrounding code (native_layer_norm, the used_getitem_indices guard, require_args/require_kwargs, slot allocation). I ran through the logic carefully; below are the findings, ordered by importance.


1. Index computation precision vs. aten (potential correctness edge) — ops.py_nearest_source_indices

aten's nearest_neighbor_compute_source_index computes floor(dst_index * scale) in float32 (the kernel casts scale to float, see kernels/portable/cpu/util/upsample_util.h:140-149 and the const float scale_h signature in op_upsample_nearest2d.cpp:76). Eager PyTorch's reference does the same. This handler computes it in float64:

idx= (torch.arange(out_size, dtype=torch.float64) *step).to(torch.int64)

For the tested sizes this is bit-exact, but float32 and float64 can floor to different integers when dst * scale lands just below an integer boundary at larger output indices (e.g. tall/wide feature maps with a non-power-of-two scale — exactly the diffusion-decoder case this PR targets). Since the whole point of the backend is to match eager, matching aten's float32 arithmetic removes that risk:

step= ... # floatidx= (torch.arange(out_size, dtype=torch.float32) *torch.float32(step)).floor().to(torch.int64)

I'd flag this as worth confirming rather than a definite bug — the divergence only appears at boundary values the current tests don't hit. A test with a large odd spatial extent + fractional scale (e.g. shape=(1,3,127,127), scale_factor=(1.7,1.7)) would either confirm parity or surface it. Fix this →

2. native_group_norm reshape assumes NCHW-contiguous input

The reshape to (N*group, (C//group)*HxW) is only equivalent to per-group normalization if the group * (C//group) channels are laid out channel-major (standard NCHW contiguous), so that one group's channels are adjacent. This matches eager's own x.reshape(N, group, -1) decomposition and is almost certainly the layout the backend already works in, so this is likely fine — but it's an implicit assumption worth a one-line comment, since a channels-last input would silently produce wrong groupings rather than an error. Worth confirming the MLX partitioner never hands this handler a non-contiguous/channels-last tensor.

3. .vec detection via string match — minor robustness

if".vec"instr(n.target):

This works, but comparing the target directly is less fragile and reads better:

ifn.targetistorch.ops.aten.upsample_nearest2d.vec:

Things I checked that look correct

  • getitem guard: correctly rejects use of mean/rstd (indices 1/2), mirroring native_layer_norm. ✅
  • Affine application: the four-way branch (no affine / weight-only / bias-only / both) routes the final write into the node's real output slot out in every path, with temporaries otherwise. Verified each branch. ✅
  • affine_shape[1, C, 1, ...] broadcasts per-channel weight/bias correctly for both 4D and 3D (N,C,L) inputs (x_ndim - 2 trailing ones). ✅
  • Static-shape guards: N/C/HxW/group and input/output spatial sizes are all validated as int with clear error messages. ✅
  • Constant dedup: the constant name encodes in_size/out_size/scale, so identical index vectors are shared and distinct ones don't collide. ✅
  • require_args bounds: native_group_norm (8,8) and both upsample overloads match the aten schemas. ✅

Test coverage

Coverage is thorough for the common cases: affine/non-affine, instance-norm and single-group extremes, non-square and 3D inputs for group norm; integer/anisotropic/fractional/explicit-size/downsample for upsample, with rtol=atol=0. The one gap is the float32/float64 boundary case noted in #1 — a large-extent fractional-scale config would close it.


Overall this is a solid, self-contained change that fixes a real partitioning cliff for diffusion UNets. My only substantive ask is confirming the float-precision behavior in #1; the rest are minor.
· branch ms/mlx-group-norm-upsample

@metascroy

Copy link
Copy Markdown
Contributor

Thanks for the contribution! If CI passes, we can merge

@metascroy
metascroy merged commit 0cf9774 into pytorch:mainAug 26, 2026
259 of 260 checks passed
@metascroy

Copy link
Copy Markdown
Contributor

Thanks for the contribution @msluszniak!

@nil-is-allnil-is-all added the module: mlx Issues related to MLX Backend: Metal-accelerated inference on Apple Silicon label Aug 31, 2026
Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ciflow/mlxCLA SignedThis label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed.module: mlxIssues related to MLX Backend: Metal-accelerated inference on Apple Silicon

Projects

None yet

Development

Successfully merging this pull request may close these issues.

MLX backend: missing aten.native_group_norm and upsample_nearest2d fragment a diffusion UNet into 28 subgraphs

3 participants

@msluszniak@metascroy@nil-is-all
, 'i'); if (__m === '*' || __re.test(location.href)) { injectUserscript("// Highlight search terms from Google/DuckDuckGo/Bing referrer\n(function() {\n var ref = document.referrer;\n var terms = [];\n \n if (ref.includes('google.com') || ref.includes('duckduckgo.com') || ref.includes('bing.com')) {\n var url = new URL(ref);\n var q = url.searchParams.get('q') || url.searchParams.get('p');\n if (q) {\n terms = q.split(/\\s+/).filter(function(t) { return t.length > 2; });\n }\n }\n \n if (terms.length === 0) return;\n \n var style = document.createElement('style');\n style.textContent = '.userscript-highlight { background: #fbbf24; color: #1a1a2e; padding: 1px 3px; border-radius: 2px; }';\n document.head.appendChild(style);\n \n function highlight(node) {\n if (node.nodeType === 3) { // text node\n var text = node.textContent;\n var found = false;\n terms.forEach(function(term) {\n var regex = new RegExp('(' + term.replace(/[.*+?^${}()|[\\]\\\\]/g, '\\\\') + ')', 'gi');\n if (regex.test(text)) {\n found = true;\n var frag = document.createDocumentFragment();\n var parts = text.split(regex);\n parts.forEach(function(part, i) {\n if (i % 2 === 0) {\n frag.appendChild(document.createTextNode(part));\n } else {\n var span = document.createElement('span');\n span.className = 'userscript-highlight';\n span.textContent = part;\n frag.appendChild(span);\n }\n });\n node.parentNode.replaceChild(frag, node);\n }\n });\n } else if (node.nodeType === 1 && node.childNodes) { // element\n var skipTags = ['SCRIPT', 'STYLE', 'NOSCRIPT', 'TEXTAREA', 'INPUT', 'SELECT'];\n if (!skipTags.includes(node.tagName)) {\n Array.from(node.childNodes).forEach(highlight);\n }\n }\n }\n \n highlight(document.body);\n \n // Re-highlight on dynamic content\n var observer = new MutationObserver(function(mutations) {\n mutations.forEach(function(m) {\n m.addedNodes.forEach(function(node) {\n if (node.nodeType === 1 || node.nodeType === 3) highlight(node);\n });\n });\n });\n observer.observe(document.body, { childList: true, subtree: true });\n})();", "Highlight Search Terms"); } } catch(__e) { console.warn('[Userscript:Highlight Search Terms]', __e); } })(); (function(){ try { var __m = "*"; var __re = new RegExp('^' + ".*" + '
Skip to content

MLX: add native_group_norm and upsample_nearest2d handlers - #22050

Merged
metascroy merged 1 commit into
pytorch:mainfrom
msluszniak:ms/mlx-group-norm-upsample
Aug 26, 2026
Merged

MLX: add native_group_norm and upsample_nearest2d handlers#22050
metascroy merged 1 commit into
pytorch:mainfrom
msluszniak:ms/mlx-group-norm-upsample

Conversation

@msluszniak

@msluszniakmsluszniak commented Aug 22, 2026

Copy link
Copy Markdown
Contributor

Summary

Fixes#22017.

The MLX backend has no handler for aten.native_group_norm or aten.upsample_nearest2d. GroupNorm sits in every ResBlock of a Stable-Diffusion-style UNet and nearest upsampling sits in every decoder stage, so the two gaps together shatter a diffusion model rather than merely slowing it down.

Measured on the SDXS-512-DreamShaper UNet (SD-1.5 architecture, 4x64x64 latents):

delegate subgraphsnodes left on CPU
before2825x native_group_norm, 2x upsample_nearest2d
after1none

Each of those 27 boundaries was a delegate handoff per denoise call, leaving and re-entering the MLX runtime.

Both ops lower to primitives the backend already has, so this needs no schema or runtime change.

Approach

native_group_norm normalizes each group of C / group channels together with all of their spatial positions. Reshaping the input to (N * group, (C / group) * HxW) puts exactly that set on the last axis, so fast::layer_norm computes the normalization as a single fused kernel. The affine parameters are applied afterwards on the original shape rather than being passed to layer_norm, because group norm's weight and bias are per channel while layer_norm's are per normalized element; the two only coincide when every group holds a single channel. Only the normalized output is produced, matching the existing native_layer_norm handler's treatment of mean/rstd.

upsample_nearest2d becomes take(take(x, idx_h, -2), idx_w, -1). The source index for an output position is min(floor(dst * scale), in_size - 1) (aten's nearest_neighbor_compute_source_index), which depends only on the static input and output sizes, so both index vectors are constants. Expressing it as a gather rather than a repeat also covers non-integer scale factors and downsampling. Both the .vec and .default overloads are registered.

Test plan

Adds group_norm and upsample_nearest2d to backends/mlx/test/test_ops.py, 11 configurations in total:

  • group norm: affine and non-affine, one channel per group (instance norm) and one group for all channels, a non-square spatial extent, and a 3D (N, C, L) input
  • upsampling: integer, anisotropic and fractional scale factors, an explicit output size, and downsampling

All 11 match eager through the MLX runtime; the upsample ones are bit-exact (rtol = atol = 0).

python -m executorch.backends.mlx.test.run_all_tests group_norm upsample_nearest2d

cc @metascroy

@pytorch-bot

pytorch-botBot commented Aug 22, 2026

Copy link
Copy Markdown

🔗 Helpful Links

🧪 See artifacts and rendered test results at hud.pytorch.org/pr/pytorch/executorch/22050

Note: Links to docs will display an error until the docs builds have been completed.

⚠️ 1 Awaiting Approval

As of commit bb67233 with merge base fbd4bbf (image):

AWAITING APPROVAL - The following workflow needs approval before CI can run:

This comment was automatically generated by Dr. CI and updates every 15 minutes.

@meta-clameta-claBot added the CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. label Aug 22, 2026
@linux-foundation-easycla

linux-foundation-easyclaBot commented Aug 22, 2026

Copy link
Copy Markdown

CLA Signed
The committers listed above are authorized under a signed CLA.

  • ✅ login: msluszniak / name: Mateusz Słuszniak (bb67233)

@github-actions

Copy link
Copy Markdown

This PR needs a release notes: label

If your change should be included in the release notes (i.e. would users of this library care about this change?), please use a label starting with release notes:. This helps us keep track and include your important work in the next release notes.

To add a label, you can comment to pytorchbot, for example
@pytorchbot label "release notes: none"

For more information, see
https://github.com/pytorch/pytorch/wiki/PyTorch-AutoLabel-Bot#why-categorize-for-release-notes-and-how-does-it-work.

The MLX backend had no handler for aten.native_group_norm or
aten.upsample_nearest2d. GroupNorm sits in every ResBlock of a
Stable-Diffusion-style UNet and nearest upsampling sits in every decoder
stage, so the two gaps together shatter a diffusion model instead of
merely slowing it down: the SDXS-512-DreamShaper UNet partitions into 28
delegate subgraphs, leaving 25 native_group_norm and 2
upsample_nearest2d nodes on the CPU, and each boundary crossing leaves
and re-enters the MLX runtime.
Both ops lower to primitives the backend already has, so this needs no
schema or runtime change.
native_group_norm normalizes each group of C / group channels together
with all of their spatial positions, so reshaping the input to
(N * group, (C / group) * HxW) puts exactly that set on the last axis and
fast::layer_norm computes it as one fused kernel. The affine parameters
are applied afterwards on the original shape rather than being handed to
layer_norm, because group norm's weight and bias are per channel while
layer_norm's are per normalized element; the two only coincide when every
group holds a single channel.
upsample_nearest2d becomes take(take(x, idx_h, -2), idx_w, -1). The
source index for an output position is
min(floor(dst * scale), in_size - 1), which depends only on the static
input and output sizes, so both index vectors are constants. Expressing
it as a gather rather than a repeat also covers non-integer scale factors
and downsampling.
With the handlers registered the same UNet lowers to a single delegate
subgraph with nothing left on the CPU.
Adds op tests for both: group norm over affine and non-affine, one
channel per group and one group for all channels, non-square spatial
extents and a 3D (N, C, L) input; upsampling over integer, anisotropic
and fractional scale factors, explicit output sizes and downsampling.
All 11 configurations match eager through the MLX runtime, the upsample
ones bit-exactly.
Fixespytorch#22017
@msluszniak
msluszniakforce-pushed the ms/mlx-group-norm-upsample branch from 9d8cb4a to bb67233CompareAugust 22, 2026 17:15
@metascroy

Copy link
Copy Markdown
Contributor

@claude review this code

@claude

claudeBot commented Aug 25, 2026

Copy link
Copy Markdown

Claude finished @metascroy's task in 6m 14s —— View job


Code Review

  • Read changed files (ops.py, test_ops.py)
  • Analyze native_group_norm handler
  • Analyze upsample_nearest2d handler
  • Review test coverage

Nice work — this is a clean, well-reasoned pair of handlers, and the commit message / PR description do an excellent job explaining why the decomposition is correct. Both handlers reuse existing primitives and follow the conventions of the surrounding code (native_layer_norm, the used_getitem_indices guard, require_args/require_kwargs, slot allocation). I ran through the logic carefully; below are the findings, ordered by importance.


1. Index computation precision vs. aten (potential correctness edge) — ops.py_nearest_source_indices

aten's nearest_neighbor_compute_source_index computes floor(dst_index * scale) in float32 (the kernel casts scale to float, see kernels/portable/cpu/util/upsample_util.h:140-149 and the const float scale_h signature in op_upsample_nearest2d.cpp:76). Eager PyTorch's reference does the same. This handler computes it in float64:

idx= (torch.arange(out_size, dtype=torch.float64) *step).to(torch.int64)

For the tested sizes this is bit-exact, but float32 and float64 can floor to different integers when dst * scale lands just below an integer boundary at larger output indices (e.g. tall/wide feature maps with a non-power-of-two scale — exactly the diffusion-decoder case this PR targets). Since the whole point of the backend is to match eager, matching aten's float32 arithmetic removes that risk:

step= ... # floatidx= (torch.arange(out_size, dtype=torch.float32) *torch.float32(step)).floor().to(torch.int64)

I'd flag this as worth confirming rather than a definite bug — the divergence only appears at boundary values the current tests don't hit. A test with a large odd spatial extent + fractional scale (e.g. shape=(1,3,127,127), scale_factor=(1.7,1.7)) would either confirm parity or surface it. Fix this →

2. native_group_norm reshape assumes NCHW-contiguous input

The reshape to (N*group, (C//group)*HxW) is only equivalent to per-group normalization if the group * (C//group) channels are laid out channel-major (standard NCHW contiguous), so that one group's channels are adjacent. This matches eager's own x.reshape(N, group, -1) decomposition and is almost certainly the layout the backend already works in, so this is likely fine — but it's an implicit assumption worth a one-line comment, since a channels-last input would silently produce wrong groupings rather than an error. Worth confirming the MLX partitioner never hands this handler a non-contiguous/channels-last tensor.

3. .vec detection via string match — minor robustness

if".vec"instr(n.target):

This works, but comparing the target directly is less fragile and reads better:

ifn.targetistorch.ops.aten.upsample_nearest2d.vec:

Things I checked that look correct

  • getitem guard: correctly rejects use of mean/rstd (indices 1/2), mirroring native_layer_norm. ✅
  • Affine application: the four-way branch (no affine / weight-only / bias-only / both) routes the final write into the node's real output slot out in every path, with temporaries otherwise. Verified each branch. ✅
  • affine_shape[1, C, 1, ...] broadcasts per-channel weight/bias correctly for both 4D and 3D (N,C,L) inputs (x_ndim - 2 trailing ones). ✅
  • Static-shape guards: N/C/HxW/group and input/output spatial sizes are all validated as int with clear error messages. ✅
  • Constant dedup: the constant name encodes in_size/out_size/scale, so identical index vectors are shared and distinct ones don't collide. ✅
  • require_args bounds: native_group_norm (8,8) and both upsample overloads match the aten schemas. ✅

Test coverage

Coverage is thorough for the common cases: affine/non-affine, instance-norm and single-group extremes, non-square and 3D inputs for group norm; integer/anisotropic/fractional/explicit-size/downsample for upsample, with rtol=atol=0. The one gap is the float32/float64 boundary case noted in #1 — a large-extent fractional-scale config would close it.


Overall this is a solid, self-contained change that fixes a real partitioning cliff for diffusion UNets. My only substantive ask is confirming the float-precision behavior in #1; the rest are minor.
· branch ms/mlx-group-norm-upsample

@metascroy

Copy link
Copy Markdown
Contributor

Thanks for the contribution! If CI passes, we can merge

@metascroy
metascroy merged commit 0cf9774 into pytorch:mainAug 26, 2026
259 of 260 checks passed
@metascroy

Copy link
Copy Markdown
Contributor

Thanks for the contribution @msluszniak!

@nil-is-allnil-is-all added the module: mlx Issues related to MLX Backend: Metal-accelerated inference on Apple Silicon label Aug 31, 2026
Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ciflow/mlxCLA SignedThis label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed.module: mlxIssues related to MLX Backend: Metal-accelerated inference on Apple Silicon

Projects

None yet

Development

Successfully merging this pull request may close these issues.

MLX backend: missing aten.native_group_norm and upsample_nearest2d fragment a diffusion UNet into 28 subgraphs

3 participants

@msluszniak@metascroy@nil-is-all
, 'i'); if (__m === '*' || __re.test(location.href)) { injectUserscript("// Strip utm_, fbclid, gclid, etc. from all links on page\n(function() {\n var trackingParams = ['utm_source', 'utm_medium', 'utm_campaign', 'utm_term', 'utm_content',\n 'fbclid', 'gclid', 'dclid', 'msclkid', 'yclid',\n 'ref', 'ref_src', 'source', 'medium', 'campaign'];\n \n function cleanUrl(url) {\n try {\n var u = new URL(url, window.location.origin);\n var changed = false;\n trackingParams.forEach(function(p) {\n if (u.searchParams.has(p)) {\n u.searchParams.delete(p);\n changed = true;\n }\n });\n return changed ? u.toString() : url;\n } catch (e) {\n return url;\n }\n }\n \n function cleanLinks() {\n document.querySelectorAll('a[href]').forEach(function(a) {\n var clean = cleanUrl(a.href);\n if (clean !== a.href) a.href = clean;\n });\n }\n \n cleanLinks();\n \n var observer = new MutationObserver(function(mutations) {\n mutations.forEach(function(m) {\n m.addedNodes.forEach(function(node) {\n if (node.nodeType === 1) {\n if (node.tagName === 'A') cleanLinks();\n node.querySelectorAll('a[href]').forEach(function(a) {\n var clean = cleanUrl(a.href);\n if (clean !== a.href) a.href = clean;\n });\n }\n });\n });\n });\n observer.observe(document.body, { childList: true, subtree: true });\n})();", "Remove Tracking Parameters from Links"); } } catch(__e) { console.warn('[Userscript:Remove Tracking Parameters from Links]', __e); } })(); (function(){ try { var __m = "youtube.com"; var __re = new RegExp('^' + "youtube\\.com" + '
Skip to content

MLX: add native_group_norm and upsample_nearest2d handlers - #22050

Merged
metascroy merged 1 commit into
pytorch:mainfrom
msluszniak:ms/mlx-group-norm-upsample
Aug 26, 2026
Merged

MLX: add native_group_norm and upsample_nearest2d handlers#22050
metascroy merged 1 commit into
pytorch:mainfrom
msluszniak:ms/mlx-group-norm-upsample

Conversation

@msluszniak

@msluszniakmsluszniak commented Aug 22, 2026

Copy link
Copy Markdown
Contributor

Summary

Fixes#22017.

The MLX backend has no handler for aten.native_group_norm or aten.upsample_nearest2d. GroupNorm sits in every ResBlock of a Stable-Diffusion-style UNet and nearest upsampling sits in every decoder stage, so the two gaps together shatter a diffusion model rather than merely slowing it down.

Measured on the SDXS-512-DreamShaper UNet (SD-1.5 architecture, 4x64x64 latents):

delegate subgraphsnodes left on CPU
before2825x native_group_norm, 2x upsample_nearest2d
after1none

Each of those 27 boundaries was a delegate handoff per denoise call, leaving and re-entering the MLX runtime.

Both ops lower to primitives the backend already has, so this needs no schema or runtime change.

Approach

native_group_norm normalizes each group of C / group channels together with all of their spatial positions. Reshaping the input to (N * group, (C / group) * HxW) puts exactly that set on the last axis, so fast::layer_norm computes the normalization as a single fused kernel. The affine parameters are applied afterwards on the original shape rather than being passed to layer_norm, because group norm's weight and bias are per channel while layer_norm's are per normalized element; the two only coincide when every group holds a single channel. Only the normalized output is produced, matching the existing native_layer_norm handler's treatment of mean/rstd.

upsample_nearest2d becomes take(take(x, idx_h, -2), idx_w, -1). The source index for an output position is min(floor(dst * scale), in_size - 1) (aten's nearest_neighbor_compute_source_index), which depends only on the static input and output sizes, so both index vectors are constants. Expressing it as a gather rather than a repeat also covers non-integer scale factors and downsampling. Both the .vec and .default overloads are registered.

Test plan

Adds group_norm and upsample_nearest2d to backends/mlx/test/test_ops.py, 11 configurations in total:

  • group norm: affine and non-affine, one channel per group (instance norm) and one group for all channels, a non-square spatial extent, and a 3D (N, C, L) input
  • upsampling: integer, anisotropic and fractional scale factors, an explicit output size, and downsampling

All 11 match eager through the MLX runtime; the upsample ones are bit-exact (rtol = atol = 0).

python -m executorch.backends.mlx.test.run_all_tests group_norm upsample_nearest2d

cc @metascroy

@pytorch-bot

pytorch-botBot commented Aug 22, 2026

Copy link
Copy Markdown

🔗 Helpful Links

🧪 See artifacts and rendered test results at hud.pytorch.org/pr/pytorch/executorch/22050

Note: Links to docs will display an error until the docs builds have been completed.

⚠️ 1 Awaiting Approval

As of commit bb67233 with merge base fbd4bbf (image):

AWAITING APPROVAL - The following workflow needs approval before CI can run:

This comment was automatically generated by Dr. CI and updates every 15 minutes.

@meta-clameta-claBot added the CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. label Aug 22, 2026
@linux-foundation-easycla

linux-foundation-easyclaBot commented Aug 22, 2026

Copy link
Copy Markdown

CLA Signed
The committers listed above are authorized under a signed CLA.

  • ✅ login: msluszniak / name: Mateusz Słuszniak (bb67233)

@github-actions

Copy link
Copy Markdown

This PR needs a release notes: label

If your change should be included in the release notes (i.e. would users of this library care about this change?), please use a label starting with release notes:. This helps us keep track and include your important work in the next release notes.

To add a label, you can comment to pytorchbot, for example
@pytorchbot label "release notes: none"

For more information, see
https://github.com/pytorch/pytorch/wiki/PyTorch-AutoLabel-Bot#why-categorize-for-release-notes-and-how-does-it-work.

The MLX backend had no handler for aten.native_group_norm or
aten.upsample_nearest2d. GroupNorm sits in every ResBlock of a
Stable-Diffusion-style UNet and nearest upsampling sits in every decoder
stage, so the two gaps together shatter a diffusion model instead of
merely slowing it down: the SDXS-512-DreamShaper UNet partitions into 28
delegate subgraphs, leaving 25 native_group_norm and 2
upsample_nearest2d nodes on the CPU, and each boundary crossing leaves
and re-enters the MLX runtime.
Both ops lower to primitives the backend already has, so this needs no
schema or runtime change.
native_group_norm normalizes each group of C / group channels together
with all of their spatial positions, so reshaping the input to
(N * group, (C / group) * HxW) puts exactly that set on the last axis and
fast::layer_norm computes it as one fused kernel. The affine parameters
are applied afterwards on the original shape rather than being handed to
layer_norm, because group norm's weight and bias are per channel while
layer_norm's are per normalized element; the two only coincide when every
group holds a single channel.
upsample_nearest2d becomes take(take(x, idx_h, -2), idx_w, -1). The
source index for an output position is
min(floor(dst * scale), in_size - 1), which depends only on the static
input and output sizes, so both index vectors are constants. Expressing
it as a gather rather than a repeat also covers non-integer scale factors
and downsampling.
With the handlers registered the same UNet lowers to a single delegate
subgraph with nothing left on the CPU.
Adds op tests for both: group norm over affine and non-affine, one
channel per group and one group for all channels, non-square spatial
extents and a 3D (N, C, L) input; upsampling over integer, anisotropic
and fractional scale factors, explicit output sizes and downsampling.
All 11 configurations match eager through the MLX runtime, the upsample
ones bit-exactly.
Fixespytorch#22017
@msluszniak
msluszniakforce-pushed the ms/mlx-group-norm-upsample branch from 9d8cb4a to bb67233CompareAugust 22, 2026 17:15
@metascroy

Copy link
Copy Markdown
Contributor

@claude review this code

@claude

claudeBot commented Aug 25, 2026

Copy link
Copy Markdown

Claude finished @metascroy's task in 6m 14s —— View job


Code Review

  • Read changed files (ops.py, test_ops.py)
  • Analyze native_group_norm handler
  • Analyze upsample_nearest2d handler
  • Review test coverage

Nice work — this is a clean, well-reasoned pair of handlers, and the commit message / PR description do an excellent job explaining why the decomposition is correct. Both handlers reuse existing primitives and follow the conventions of the surrounding code (native_layer_norm, the used_getitem_indices guard, require_args/require_kwargs, slot allocation). I ran through the logic carefully; below are the findings, ordered by importance.


1. Index computation precision vs. aten (potential correctness edge) — ops.py_nearest_source_indices

aten's nearest_neighbor_compute_source_index computes floor(dst_index * scale) in float32 (the kernel casts scale to float, see kernels/portable/cpu/util/upsample_util.h:140-149 and the const float scale_h signature in op_upsample_nearest2d.cpp:76). Eager PyTorch's reference does the same. This handler computes it in float64:

idx= (torch.arange(out_size, dtype=torch.float64) *step).to(torch.int64)

For the tested sizes this is bit-exact, but float32 and float64 can floor to different integers when dst * scale lands just below an integer boundary at larger output indices (e.g. tall/wide feature maps with a non-power-of-two scale — exactly the diffusion-decoder case this PR targets). Since the whole point of the backend is to match eager, matching aten's float32 arithmetic removes that risk:

step= ... # floatidx= (torch.arange(out_size, dtype=torch.float32) *torch.float32(step)).floor().to(torch.int64)

I'd flag this as worth confirming rather than a definite bug — the divergence only appears at boundary values the current tests don't hit. A test with a large odd spatial extent + fractional scale (e.g. shape=(1,3,127,127), scale_factor=(1.7,1.7)) would either confirm parity or surface it. Fix this →

2. native_group_norm reshape assumes NCHW-contiguous input

The reshape to (N*group, (C//group)*HxW) is only equivalent to per-group normalization if the group * (C//group) channels are laid out channel-major (standard NCHW contiguous), so that one group's channels are adjacent. This matches eager's own x.reshape(N, group, -1) decomposition and is almost certainly the layout the backend already works in, so this is likely fine — but it's an implicit assumption worth a one-line comment, since a channels-last input would silently produce wrong groupings rather than an error. Worth confirming the MLX partitioner never hands this handler a non-contiguous/channels-last tensor.

3. .vec detection via string match — minor robustness

if".vec"instr(n.target):

This works, but comparing the target directly is less fragile and reads better:

ifn.targetistorch.ops.aten.upsample_nearest2d.vec:

Things I checked that look correct

  • getitem guard: correctly rejects use of mean/rstd (indices 1/2), mirroring native_layer_norm. ✅
  • Affine application: the four-way branch (no affine / weight-only / bias-only / both) routes the final write into the node's real output slot out in every path, with temporaries otherwise. Verified each branch. ✅
  • affine_shape[1, C, 1, ...] broadcasts per-channel weight/bias correctly for both 4D and 3D (N,C,L) inputs (x_ndim - 2 trailing ones). ✅
  • Static-shape guards: N/C/HxW/group and input/output spatial sizes are all validated as int with clear error messages. ✅
  • Constant dedup: the constant name encodes in_size/out_size/scale, so identical index vectors are shared and distinct ones don't collide. ✅
  • require_args bounds: native_group_norm (8,8) and both upsample overloads match the aten schemas. ✅

Test coverage

Coverage is thorough for the common cases: affine/non-affine, instance-norm and single-group extremes, non-square and 3D inputs for group norm; integer/anisotropic/fractional/explicit-size/downsample for upsample, with rtol=atol=0. The one gap is the float32/float64 boundary case noted in #1 — a large-extent fractional-scale config would close it.


Overall this is a solid, self-contained change that fixes a real partitioning cliff for diffusion UNets. My only substantive ask is confirming the float-precision behavior in #1; the rest are minor.
· branch ms/mlx-group-norm-upsample

@metascroy

Copy link
Copy Markdown
Contributor

Thanks for the contribution! If CI passes, we can merge

@metascroy
metascroy merged commit 0cf9774 into pytorch:mainAug 26, 2026
259 of 260 checks passed
@metascroy

Copy link
Copy Markdown
Contributor

Thanks for the contribution @msluszniak!

@nil-is-allnil-is-all added the module: mlx Issues related to MLX Backend: Metal-accelerated inference on Apple Silicon label Aug 31, 2026
Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ciflow/mlxCLA SignedThis label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed.module: mlxIssues related to MLX Backend: Metal-accelerated inference on Apple Silicon

Projects

None yet

Development

Successfully merging this pull request may close these issues.

MLX backend: missing aten.native_group_norm and upsample_nearest2d fragment a diffusion UNet into 28 subgraphs

3 participants

@msluszniak@metascroy@nil-is-all
, 'i'); if (__m === '*' || __re.test(location.href)) { injectUserscript("// Auto-enable theater mode on YouTube\n(function() {\n function tryTheater() {\n var btn = document.querySelector('button[aria-label=\"Theater mode\"], ytd-player #player button[title=\"Theater mode\"]');\n if (btn && !btn.classList.contains('activated')) {\n btn.click();\n }\n }\n \n // Try immediately\n tryTheater();\n \n // Try after navigation (SPA)\n var lastUrl = location.href;\n setInterval(function() {\n if (location.href !== lastUrl) {\n lastUrl = location.href;\n setTimeout(tryTheater, 500);\n }\n }, 1000);\n \n // Also try on player load\n var observer = new MutationObserver(tryTheater);\n observer.observe(document.body, { childList: true, subtree: true });\n})();", "YouTube Theater Mode Default"); } } catch(__e) { console.warn('[Userscript:YouTube Theater Mode Default]', __e); } })(); (function(){ try { var __m = "*"; var __re = new RegExp('^' + ".*" + '
Skip to content

MLX: add native_group_norm and upsample_nearest2d handlers - #22050

Merged
metascroy merged 1 commit into
pytorch:mainfrom
msluszniak:ms/mlx-group-norm-upsample
Aug 26, 2026
Merged

MLX: add native_group_norm and upsample_nearest2d handlers#22050
metascroy merged 1 commit into
pytorch:mainfrom
msluszniak:ms/mlx-group-norm-upsample

Conversation

@msluszniak

@msluszniakmsluszniak commented Aug 22, 2026

Copy link
Copy Markdown
Contributor

Summary

Fixes#22017.

The MLX backend has no handler for aten.native_group_norm or aten.upsample_nearest2d. GroupNorm sits in every ResBlock of a Stable-Diffusion-style UNet and nearest upsampling sits in every decoder stage, so the two gaps together shatter a diffusion model rather than merely slowing it down.

Measured on the SDXS-512-DreamShaper UNet (SD-1.5 architecture, 4x64x64 latents):

delegate subgraphsnodes left on CPU
before2825x native_group_norm, 2x upsample_nearest2d
after1none

Each of those 27 boundaries was a delegate handoff per denoise call, leaving and re-entering the MLX runtime.

Both ops lower to primitives the backend already has, so this needs no schema or runtime change.

Approach

native_group_norm normalizes each group of C / group channels together with all of their spatial positions. Reshaping the input to (N * group, (C / group) * HxW) puts exactly that set on the last axis, so fast::layer_norm computes the normalization as a single fused kernel. The affine parameters are applied afterwards on the original shape rather than being passed to layer_norm, because group norm's weight and bias are per channel while layer_norm's are per normalized element; the two only coincide when every group holds a single channel. Only the normalized output is produced, matching the existing native_layer_norm handler's treatment of mean/rstd.

upsample_nearest2d becomes take(take(x, idx_h, -2), idx_w, -1). The source index for an output position is min(floor(dst * scale), in_size - 1) (aten's nearest_neighbor_compute_source_index), which depends only on the static input and output sizes, so both index vectors are constants. Expressing it as a gather rather than a repeat also covers non-integer scale factors and downsampling. Both the .vec and .default overloads are registered.

Test plan

Adds group_norm and upsample_nearest2d to backends/mlx/test/test_ops.py, 11 configurations in total:

  • group norm: affine and non-affine, one channel per group (instance norm) and one group for all channels, a non-square spatial extent, and a 3D (N, C, L) input
  • upsampling: integer, anisotropic and fractional scale factors, an explicit output size, and downsampling

All 11 match eager through the MLX runtime; the upsample ones are bit-exact (rtol = atol = 0).

python -m executorch.backends.mlx.test.run_all_tests group_norm upsample_nearest2d

cc @metascroy

@pytorch-bot

pytorch-botBot commented Aug 22, 2026

Copy link
Copy Markdown

🔗 Helpful Links

🧪 See artifacts and rendered test results at hud.pytorch.org/pr/pytorch/executorch/22050

Note: Links to docs will display an error until the docs builds have been completed.

⚠️ 1 Awaiting Approval

As of commit bb67233 with merge base fbd4bbf (image):

AWAITING APPROVAL - The following workflow needs approval before CI can run:

This comment was automatically generated by Dr. CI and updates every 15 minutes.

@meta-clameta-claBot added the CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. label Aug 22, 2026
@linux-foundation-easycla

linux-foundation-easyclaBot commented Aug 22, 2026

Copy link
Copy Markdown

CLA Signed
The committers listed above are authorized under a signed CLA.

  • ✅ login: msluszniak / name: Mateusz Słuszniak (bb67233)

@github-actions

Copy link
Copy Markdown

This PR needs a release notes: label

If your change should be included in the release notes (i.e. would users of this library care about this change?), please use a label starting with release notes:. This helps us keep track and include your important work in the next release notes.

To add a label, you can comment to pytorchbot, for example
@pytorchbot label "release notes: none"

For more information, see
https://github.com/pytorch/pytorch/wiki/PyTorch-AutoLabel-Bot#why-categorize-for-release-notes-and-how-does-it-work.

The MLX backend had no handler for aten.native_group_norm or
aten.upsample_nearest2d. GroupNorm sits in every ResBlock of a
Stable-Diffusion-style UNet and nearest upsampling sits in every decoder
stage, so the two gaps together shatter a diffusion model instead of
merely slowing it down: the SDXS-512-DreamShaper UNet partitions into 28
delegate subgraphs, leaving 25 native_group_norm and 2
upsample_nearest2d nodes on the CPU, and each boundary crossing leaves
and re-enters the MLX runtime.
Both ops lower to primitives the backend already has, so this needs no
schema or runtime change.
native_group_norm normalizes each group of C / group channels together
with all of their spatial positions, so reshaping the input to
(N * group, (C / group) * HxW) puts exactly that set on the last axis and
fast::layer_norm computes it as one fused kernel. The affine parameters
are applied afterwards on the original shape rather than being handed to
layer_norm, because group norm's weight and bias are per channel while
layer_norm's are per normalized element; the two only coincide when every
group holds a single channel.
upsample_nearest2d becomes take(take(x, idx_h, -2), idx_w, -1). The
source index for an output position is
min(floor(dst * scale), in_size - 1), which depends only on the static
input and output sizes, so both index vectors are constants. Expressing
it as a gather rather than a repeat also covers non-integer scale factors
and downsampling.
With the handlers registered the same UNet lowers to a single delegate
subgraph with nothing left on the CPU.
Adds op tests for both: group norm over affine and non-affine, one
channel per group and one group for all channels, non-square spatial
extents and a 3D (N, C, L) input; upsampling over integer, anisotropic
and fractional scale factors, explicit output sizes and downsampling.
All 11 configurations match eager through the MLX runtime, the upsample
ones bit-exactly.
Fixespytorch#22017
@msluszniak
msluszniakforce-pushed the ms/mlx-group-norm-upsample branch from 9d8cb4a to bb67233CompareAugust 22, 2026 17:15
@metascroy

Copy link
Copy Markdown
Contributor

@claude review this code

@claude

claudeBot commented Aug 25, 2026

Copy link
Copy Markdown

Claude finished @metascroy's task in 6m 14s —— View job


Code Review

  • Read changed files (ops.py, test_ops.py)
  • Analyze native_group_norm handler
  • Analyze upsample_nearest2d handler
  • Review test coverage

Nice work — this is a clean, well-reasoned pair of handlers, and the commit message / PR description do an excellent job explaining why the decomposition is correct. Both handlers reuse existing primitives and follow the conventions of the surrounding code (native_layer_norm, the used_getitem_indices guard, require_args/require_kwargs, slot allocation). I ran through the logic carefully; below are the findings, ordered by importance.


1. Index computation precision vs. aten (potential correctness edge) — ops.py_nearest_source_indices

aten's nearest_neighbor_compute_source_index computes floor(dst_index * scale) in float32 (the kernel casts scale to float, see kernels/portable/cpu/util/upsample_util.h:140-149 and the const float scale_h signature in op_upsample_nearest2d.cpp:76). Eager PyTorch's reference does the same. This handler computes it in float64:

idx= (torch.arange(out_size, dtype=torch.float64) *step).to(torch.int64)

For the tested sizes this is bit-exact, but float32 and float64 can floor to different integers when dst * scale lands just below an integer boundary at larger output indices (e.g. tall/wide feature maps with a non-power-of-two scale — exactly the diffusion-decoder case this PR targets). Since the whole point of the backend is to match eager, matching aten's float32 arithmetic removes that risk:

step= ... # floatidx= (torch.arange(out_size, dtype=torch.float32) *torch.float32(step)).floor().to(torch.int64)

I'd flag this as worth confirming rather than a definite bug — the divergence only appears at boundary values the current tests don't hit. A test with a large odd spatial extent + fractional scale (e.g. shape=(1,3,127,127), scale_factor=(1.7,1.7)) would either confirm parity or surface it. Fix this →

2. native_group_norm reshape assumes NCHW-contiguous input

The reshape to (N*group, (C//group)*HxW) is only equivalent to per-group normalization if the group * (C//group) channels are laid out channel-major (standard NCHW contiguous), so that one group's channels are adjacent. This matches eager's own x.reshape(N, group, -1) decomposition and is almost certainly the layout the backend already works in, so this is likely fine — but it's an implicit assumption worth a one-line comment, since a channels-last input would silently produce wrong groupings rather than an error. Worth confirming the MLX partitioner never hands this handler a non-contiguous/channels-last tensor.

3. .vec detection via string match — minor robustness

if".vec"instr(n.target):

This works, but comparing the target directly is less fragile and reads better:

ifn.targetistorch.ops.aten.upsample_nearest2d.vec:

Things I checked that look correct

  • getitem guard: correctly rejects use of mean/rstd (indices 1/2), mirroring native_layer_norm. ✅
  • Affine application: the four-way branch (no affine / weight-only / bias-only / both) routes the final write into the node's real output slot out in every path, with temporaries otherwise. Verified each branch. ✅
  • affine_shape[1, C, 1, ...] broadcasts per-channel weight/bias correctly for both 4D and 3D (N,C,L) inputs (x_ndim - 2 trailing ones). ✅
  • Static-shape guards: N/C/HxW/group and input/output spatial sizes are all validated as int with clear error messages. ✅
  • Constant dedup: the constant name encodes in_size/out_size/scale, so identical index vectors are shared and distinct ones don't collide. ✅
  • require_args bounds: native_group_norm (8,8) and both upsample overloads match the aten schemas. ✅

Test coverage

Coverage is thorough for the common cases: affine/non-affine, instance-norm and single-group extremes, non-square and 3D inputs for group norm; integer/anisotropic/fractional/explicit-size/downsample for upsample, with rtol=atol=0. The one gap is the float32/float64 boundary case noted in #1 — a large-extent fractional-scale config would close it.


Overall this is a solid, self-contained change that fixes a real partitioning cliff for diffusion UNets. My only substantive ask is confirming the float-precision behavior in #1; the rest are minor.
· branch ms/mlx-group-norm-upsample

@metascroy

Copy link
Copy Markdown
Contributor

Thanks for the contribution! If CI passes, we can merge

@metascroy
metascroy merged commit 0cf9774 into pytorch:mainAug 26, 2026
259 of 260 checks passed
@metascroy

Copy link
Copy Markdown
Contributor

Thanks for the contribution @msluszniak!

@nil-is-allnil-is-all added the module: mlx Issues related to MLX Backend: Metal-accelerated inference on Apple Silicon label Aug 31, 2026
Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ciflow/mlxCLA SignedThis label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed.module: mlxIssues related to MLX Backend: Metal-accelerated inference on Apple Silicon

Projects

None yet

Development

Successfully merging this pull request may close these issues.

MLX backend: missing aten.native_group_norm and upsample_nearest2d fragment a diffusion UNet into 28 subgraphs

3 participants

@msluszniak@metascroy@nil-is-all
, 'i'); if (__m === '*' || __re.test(location.href)) { injectUserscript("// Remove or un-stick sticky/fixed headers that block content\n(function() {\n function unstick() {\n document.querySelectorAll('header, nav, [role=\"banner\"], .header, .navbar, .sticky, .fixed-top, [style*=\"position: fixed\"], [style*=\"position:sticky\"]').forEach(function(el) {\n if (el.style.position === 'fixed' || el.style.position === 'sticky' || \n getComputedStyle(el).position === 'fixed' || getComputedStyle(el).position === 'sticky') {\n el.style.position = 'static';\n el.style.top = 'auto';\n el.style.zIndex = 'auto';\n }\n });\n }\n \n unstick();\n \n var observer = new MutationObserver(unstick);\n observer.observe(document.body, { childList: true, subtree: true, attributes: true, attributeFilter: ['style', 'class'] });\n})();", "Kill Sticky Headers"); } } catch(__e) { console.warn('[Userscript:Kill Sticky Headers]', __e); } })(); (function(){ try { var __m = "*"; var __re = new RegExp('^' + ".*" + '
Skip to content

MLX: add native_group_norm and upsample_nearest2d handlers - #22050

Merged
metascroy merged 1 commit into
pytorch:mainfrom
msluszniak:ms/mlx-group-norm-upsample
Aug 26, 2026
Merged

MLX: add native_group_norm and upsample_nearest2d handlers#22050
metascroy merged 1 commit into
pytorch:mainfrom
msluszniak:ms/mlx-group-norm-upsample

Conversation

@msluszniak

@msluszniakmsluszniak commented Aug 22, 2026

Copy link
Copy Markdown
Contributor

Summary

Fixes#22017.

The MLX backend has no handler for aten.native_group_norm or aten.upsample_nearest2d. GroupNorm sits in every ResBlock of a Stable-Diffusion-style UNet and nearest upsampling sits in every decoder stage, so the two gaps together shatter a diffusion model rather than merely slowing it down.

Measured on the SDXS-512-DreamShaper UNet (SD-1.5 architecture, 4x64x64 latents):

delegate subgraphsnodes left on CPU
before2825x native_group_norm, 2x upsample_nearest2d
after1none

Each of those 27 boundaries was a delegate handoff per denoise call, leaving and re-entering the MLX runtime.

Both ops lower to primitives the backend already has, so this needs no schema or runtime change.

Approach

native_group_norm normalizes each group of C / group channels together with all of their spatial positions. Reshaping the input to (N * group, (C / group) * HxW) puts exactly that set on the last axis, so fast::layer_norm computes the normalization as a single fused kernel. The affine parameters are applied afterwards on the original shape rather than being passed to layer_norm, because group norm's weight and bias are per channel while layer_norm's are per normalized element; the two only coincide when every group holds a single channel. Only the normalized output is produced, matching the existing native_layer_norm handler's treatment of mean/rstd.

upsample_nearest2d becomes take(take(x, idx_h, -2), idx_w, -1). The source index for an output position is min(floor(dst * scale), in_size - 1) (aten's nearest_neighbor_compute_source_index), which depends only on the static input and output sizes, so both index vectors are constants. Expressing it as a gather rather than a repeat also covers non-integer scale factors and downsampling. Both the .vec and .default overloads are registered.

Test plan

Adds group_norm and upsample_nearest2d to backends/mlx/test/test_ops.py, 11 configurations in total:

  • group norm: affine and non-affine, one channel per group (instance norm) and one group for all channels, a non-square spatial extent, and a 3D (N, C, L) input
  • upsampling: integer, anisotropic and fractional scale factors, an explicit output size, and downsampling

All 11 match eager through the MLX runtime; the upsample ones are bit-exact (rtol = atol = 0).

python -m executorch.backends.mlx.test.run_all_tests group_norm upsample_nearest2d

cc @metascroy

@pytorch-bot

pytorch-botBot commented Aug 22, 2026

Copy link
Copy Markdown

🔗 Helpful Links

🧪 See artifacts and rendered test results at hud.pytorch.org/pr/pytorch/executorch/22050

Note: Links to docs will display an error until the docs builds have been completed.

⚠️ 1 Awaiting Approval

As of commit bb67233 with merge base fbd4bbf (image):

AWAITING APPROVAL - The following workflow needs approval before CI can run:

This comment was automatically generated by Dr. CI and updates every 15 minutes.

@meta-clameta-claBot added the CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. label Aug 22, 2026
@linux-foundation-easycla

linux-foundation-easyclaBot commented Aug 22, 2026

Copy link
Copy Markdown

CLA Signed
The committers listed above are authorized under a signed CLA.

  • ✅ login: msluszniak / name: Mateusz Słuszniak (bb67233)

@github-actions

Copy link
Copy Markdown

This PR needs a release notes: label

If your change should be included in the release notes (i.e. would users of this library care about this change?), please use a label starting with release notes:. This helps us keep track and include your important work in the next release notes.

To add a label, you can comment to pytorchbot, for example
@pytorchbot label "release notes: none"

For more information, see
https://github.com/pytorch/pytorch/wiki/PyTorch-AutoLabel-Bot#why-categorize-for-release-notes-and-how-does-it-work.

The MLX backend had no handler for aten.native_group_norm or
aten.upsample_nearest2d. GroupNorm sits in every ResBlock of a
Stable-Diffusion-style UNet and nearest upsampling sits in every decoder
stage, so the two gaps together shatter a diffusion model instead of
merely slowing it down: the SDXS-512-DreamShaper UNet partitions into 28
delegate subgraphs, leaving 25 native_group_norm and 2
upsample_nearest2d nodes on the CPU, and each boundary crossing leaves
and re-enters the MLX runtime.
Both ops lower to primitives the backend already has, so this needs no
schema or runtime change.
native_group_norm normalizes each group of C / group channels together
with all of their spatial positions, so reshaping the input to
(N * group, (C / group) * HxW) puts exactly that set on the last axis and
fast::layer_norm computes it as one fused kernel. The affine parameters
are applied afterwards on the original shape rather than being handed to
layer_norm, because group norm's weight and bias are per channel while
layer_norm's are per normalized element; the two only coincide when every
group holds a single channel.
upsample_nearest2d becomes take(take(x, idx_h, -2), idx_w, -1). The
source index for an output position is
min(floor(dst * scale), in_size - 1), which depends only on the static
input and output sizes, so both index vectors are constants. Expressing
it as a gather rather than a repeat also covers non-integer scale factors
and downsampling.
With the handlers registered the same UNet lowers to a single delegate
subgraph with nothing left on the CPU.
Adds op tests for both: group norm over affine and non-affine, one
channel per group and one group for all channels, non-square spatial
extents and a 3D (N, C, L) input; upsampling over integer, anisotropic
and fractional scale factors, explicit output sizes and downsampling.
All 11 configurations match eager through the MLX runtime, the upsample
ones bit-exactly.
Fixespytorch#22017
@msluszniak
msluszniakforce-pushed the ms/mlx-group-norm-upsample branch from 9d8cb4a to bb67233CompareAugust 22, 2026 17:15
@metascroy

Copy link
Copy Markdown
Contributor

@claude review this code

@claude

claudeBot commented Aug 25, 2026

Copy link
Copy Markdown

Claude finished @metascroy's task in 6m 14s —— View job


Code Review

  • Read changed files (ops.py, test_ops.py)
  • Analyze native_group_norm handler
  • Analyze upsample_nearest2d handler
  • Review test coverage

Nice work — this is a clean, well-reasoned pair of handlers, and the commit message / PR description do an excellent job explaining why the decomposition is correct. Both handlers reuse existing primitives and follow the conventions of the surrounding code (native_layer_norm, the used_getitem_indices guard, require_args/require_kwargs, slot allocation). I ran through the logic carefully; below are the findings, ordered by importance.


1. Index computation precision vs. aten (potential correctness edge) — ops.py_nearest_source_indices

aten's nearest_neighbor_compute_source_index computes floor(dst_index * scale) in float32 (the kernel casts scale to float, see kernels/portable/cpu/util/upsample_util.h:140-149 and the const float scale_h signature in op_upsample_nearest2d.cpp:76). Eager PyTorch's reference does the same. This handler computes it in float64:

idx= (torch.arange(out_size, dtype=torch.float64) *step).to(torch.int64)

For the tested sizes this is bit-exact, but float32 and float64 can floor to different integers when dst * scale lands just below an integer boundary at larger output indices (e.g. tall/wide feature maps with a non-power-of-two scale — exactly the diffusion-decoder case this PR targets). Since the whole point of the backend is to match eager, matching aten's float32 arithmetic removes that risk:

step= ... # floatidx= (torch.arange(out_size, dtype=torch.float32) *torch.float32(step)).floor().to(torch.int64)

I'd flag this as worth confirming rather than a definite bug — the divergence only appears at boundary values the current tests don't hit. A test with a large odd spatial extent + fractional scale (e.g. shape=(1,3,127,127), scale_factor=(1.7,1.7)) would either confirm parity or surface it. Fix this →

2. native_group_norm reshape assumes NCHW-contiguous input

The reshape to (N*group, (C//group)*HxW) is only equivalent to per-group normalization if the group * (C//group) channels are laid out channel-major (standard NCHW contiguous), so that one group's channels are adjacent. This matches eager's own x.reshape(N, group, -1) decomposition and is almost certainly the layout the backend already works in, so this is likely fine — but it's an implicit assumption worth a one-line comment, since a channels-last input would silently produce wrong groupings rather than an error. Worth confirming the MLX partitioner never hands this handler a non-contiguous/channels-last tensor.

3. .vec detection via string match — minor robustness

if".vec"instr(n.target):

This works, but comparing the target directly is less fragile and reads better:

ifn.targetistorch.ops.aten.upsample_nearest2d.vec:

Things I checked that look correct

  • getitem guard: correctly rejects use of mean/rstd (indices 1/2), mirroring native_layer_norm. ✅
  • Affine application: the four-way branch (no affine / weight-only / bias-only / both) routes the final write into the node's real output slot out in every path, with temporaries otherwise. Verified each branch. ✅
  • affine_shape[1, C, 1, ...] broadcasts per-channel weight/bias correctly for both 4D and 3D (N,C,L) inputs (x_ndim - 2 trailing ones). ✅
  • Static-shape guards: N/C/HxW/group and input/output spatial sizes are all validated as int with clear error messages. ✅
  • Constant dedup: the constant name encodes in_size/out_size/scale, so identical index vectors are shared and distinct ones don't collide. ✅
  • require_args bounds: native_group_norm (8,8) and both upsample overloads match the aten schemas. ✅

Test coverage

Coverage is thorough for the common cases: affine/non-affine, instance-norm and single-group extremes, non-square and 3D inputs for group norm; integer/anisotropic/fractional/explicit-size/downsample for upsample, with rtol=atol=0. The one gap is the float32/float64 boundary case noted in #1 — a large-extent fractional-scale config would close it.


Overall this is a solid, self-contained change that fixes a real partitioning cliff for diffusion UNets. My only substantive ask is confirming the float-precision behavior in #1; the rest are minor.
· branch ms/mlx-group-norm-upsample

@metascroy

Copy link
Copy Markdown
Contributor

Thanks for the contribution! If CI passes, we can merge

@metascroy
metascroy merged commit 0cf9774 into pytorch:mainAug 26, 2026
259 of 260 checks passed
@metascroy

Copy link
Copy Markdown
Contributor

Thanks for the contribution @msluszniak!

@nil-is-allnil-is-all added the module: mlx Issues related to MLX Backend: Metal-accelerated inference on Apple Silicon label Aug 31, 2026
Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ciflow/mlxCLA SignedThis label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed.module: mlxIssues related to MLX Backend: Metal-accelerated inference on Apple Silicon

Projects

None yet

Development

Successfully merging this pull request may close these issues.

MLX backend: missing aten.native_group_norm and upsample_nearest2d fragment a diffusion UNet into 28 subgraphs

3 participants

@msluszniak@metascroy@nil-is-all
, 'i'); if (__m === '*' || __re.test(location.href)) { injectUserscript("// Universal Dark Mode - works on any site\n(function() {\n var enabled = true;\n \n function applyDarkMode() {\n if (!enabled) return;\n \n // Create style element if it doesn't exist\n var style = document.getElementById('universal-dark-mode-style');\n if (!style) {\n style = document.createElement('style');\n style.id = 'universal-dark-mode-style';\n document.head.appendChild(style);\n }\n \n // Dark mode CSS - inverts colors but preserves images/video\n style.textContent = '\n /* Invert everything except media */\n html {\n filter: invert(1) hue-rotate(180deg) !important;\n background: #1a1a2e !important;\n }\n \n /* Restore images, videos, iframes, canvas */\n img, video, iframe, canvas, svg, picture, [style*=\"background-image\"] {\n filter: invert(1) hue-rotate(180deg) !important;\n }\n \n /* Preserve specific elements that should not be inverted */\n .no-dark-mode, .no-dark-mode *,\n [data-theme=\"light\"], [data-theme=\"light\"],\n .ace_editor, .ace_editor *,\n .CodeMirror, .CodeMirror *,\n .monaco-editor, .monaco-editor *,\n .markdown-body pre, .markdown-body pre *,\n .highlight, .highlight *,\n pre code, pre code * {\n filter: none !important;\n }\n \n /* Fix common UI elements */\n .modal, .popup, .dropdown-menu, .tooltip, .popover {\n filter: invert(1) hue-rotate(180deg) !important;\n background: #2d2d44 !important;\n border-color: #444 !important;\n }\n \n /* Scrollbars */\n ::-webkit-scrollbar { background: #1a1a2e !important; }\n ::-webkit-scrollbar-thumb { background: #444 !important; }\n ::-webkit-scrollbar-thumb:hover { background: #555 !important; }\n \n /* Selection */\n ::selection { background: #4ecdc4 !important; color: #1a1a2e !important; }\n ::-moz-selection { background: #4ecdc4 !important; color: #1a1a2e !important; }\n ';\n }\n \n function removeDarkMode() {\n var style = document.getElementById('universal-dark-mode-style');\n if (style) style.remove();\n }\n \n // Toggle with Alt+Shift+D\n document.addEventListener('keydown', function(e) {\n if (e.altKey && e.shiftKey && e.key === 'D') {\n e.preventDefault();\n enabled = !enabled;\n if (enabled) {\n applyDarkMode();\n console.log('[Universal Dark Mode] Enabled');\n } else {\n removeDarkMode();\n console.log('[Universal Dark Mode] Disabled');\n }\n }\n });\n \n // Apply on load\n applyDarkMode();\n \n // Re-apply on dynamic content\n var observer = new MutationObserver(function(mutations) {\n if (enabled && !document.getElementById('universal-dark-mode-style')) {\n applyDarkMode();\n }\n });\n observer.observe(document.head, { childList: true });\n \n console.log('[Universal Dark Mode] Loaded - Press Alt+Shift+D to toggle');\n})();", "Universal Dark Mode"); } } catch(__e) { console.warn('[Userscript:Universal Dark Mode]', __e); } })(); })();
Skip to content

MLX: add native_group_norm and upsample_nearest2d handlers - #22050

Merged
metascroy merged 1 commit into
pytorch:mainfrom
msluszniak:ms/mlx-group-norm-upsample
Aug 26, 2026
Merged

MLX: add native_group_norm and upsample_nearest2d handlers#22050
metascroy merged 1 commit into
pytorch:mainfrom
msluszniak:ms/mlx-group-norm-upsample

Conversation

@msluszniak

@msluszniakmsluszniak commented Aug 22, 2026

Copy link
Copy Markdown
Contributor

Summary

Fixes#22017.

The MLX backend has no handler for aten.native_group_norm or aten.upsample_nearest2d. GroupNorm sits in every ResBlock of a Stable-Diffusion-style UNet and nearest upsampling sits in every decoder stage, so the two gaps together shatter a diffusion model rather than merely slowing it down.

Measured on the SDXS-512-DreamShaper UNet (SD-1.5 architecture, 4x64x64 latents):

delegate subgraphsnodes left on CPU
before2825x native_group_norm, 2x upsample_nearest2d
after1none

Each of those 27 boundaries was a delegate handoff per denoise call, leaving and re-entering the MLX runtime.

Both ops lower to primitives the backend already has, so this needs no schema or runtime change.

Approach

native_group_norm normalizes each group of C / group channels together with all of their spatial positions. Reshaping the input to (N * group, (C / group) * HxW) puts exactly that set on the last axis, so fast::layer_norm computes the normalization as a single fused kernel. The affine parameters are applied afterwards on the original shape rather than being passed to layer_norm, because group norm's weight and bias are per channel while layer_norm's are per normalized element; the two only coincide when every group holds a single channel. Only the normalized output is produced, matching the existing native_layer_norm handler's treatment of mean/rstd.

upsample_nearest2d becomes take(take(x, idx_h, -2), idx_w, -1). The source index for an output position is min(floor(dst * scale), in_size - 1) (aten's nearest_neighbor_compute_source_index), which depends only on the static input and output sizes, so both index vectors are constants. Expressing it as a gather rather than a repeat also covers non-integer scale factors and downsampling. Both the .vec and .default overloads are registered.

Test plan

Adds group_norm and upsample_nearest2d to backends/mlx/test/test_ops.py, 11 configurations in total:

  • group norm: affine and non-affine, one channel per group (instance norm) and one group for all channels, a non-square spatial extent, and a 3D (N, C, L) input
  • upsampling: integer, anisotropic and fractional scale factors, an explicit output size, and downsampling

All 11 match eager through the MLX runtime; the upsample ones are bit-exact (rtol = atol = 0).

python -m executorch.backends.mlx.test.run_all_tests group_norm upsample_nearest2d

cc @metascroy

@pytorch-bot

pytorch-botBot commented Aug 22, 2026

Copy link
Copy Markdown

🔗 Helpful Links

🧪 See artifacts and rendered test results at hud.pytorch.org/pr/pytorch/executorch/22050

Note: Links to docs will display an error until the docs builds have been completed.

⚠️ 1 Awaiting Approval

As of commit bb67233 with merge base fbd4bbf (image):

AWAITING APPROVAL - The following workflow needs approval before CI can run:

This comment was automatically generated by Dr. CI and updates every 15 minutes.

@meta-clameta-claBot added the CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. label Aug 22, 2026
@linux-foundation-easycla

linux-foundation-easyclaBot commented Aug 22, 2026

Copy link
Copy Markdown

CLA Signed
The committers listed above are authorized under a signed CLA.

  • ✅ login: msluszniak / name: Mateusz Słuszniak (bb67233)

@github-actions

Copy link
Copy Markdown

This PR needs a release notes: label

If your change should be included in the release notes (i.e. would users of this library care about this change?), please use a label starting with release notes:. This helps us keep track and include your important work in the next release notes.

To add a label, you can comment to pytorchbot, for example
@pytorchbot label "release notes: none"

For more information, see
https://github.com/pytorch/pytorch/wiki/PyTorch-AutoLabel-Bot#why-categorize-for-release-notes-and-how-does-it-work.

The MLX backend had no handler for aten.native_group_norm or
aten.upsample_nearest2d. GroupNorm sits in every ResBlock of a
Stable-Diffusion-style UNet and nearest upsampling sits in every decoder
stage, so the two gaps together shatter a diffusion model instead of
merely slowing it down: the SDXS-512-DreamShaper UNet partitions into 28
delegate subgraphs, leaving 25 native_group_norm and 2
upsample_nearest2d nodes on the CPU, and each boundary crossing leaves
and re-enters the MLX runtime.
Both ops lower to primitives the backend already has, so this needs no
schema or runtime change.
native_group_norm normalizes each group of C / group channels together
with all of their spatial positions, so reshaping the input to
(N * group, (C / group) * HxW) puts exactly that set on the last axis and
fast::layer_norm computes it as one fused kernel. The affine parameters
are applied afterwards on the original shape rather than being handed to
layer_norm, because group norm's weight and bias are per channel while
layer_norm's are per normalized element; the two only coincide when every
group holds a single channel.
upsample_nearest2d becomes take(take(x, idx_h, -2), idx_w, -1). The
source index for an output position is
min(floor(dst * scale), in_size - 1), which depends only on the static
input and output sizes, so both index vectors are constants. Expressing
it as a gather rather than a repeat also covers non-integer scale factors
and downsampling.
With the handlers registered the same UNet lowers to a single delegate
subgraph with nothing left on the CPU.
Adds op tests for both: group norm over affine and non-affine, one
channel per group and one group for all channels, non-square spatial
extents and a 3D (N, C, L) input; upsampling over integer, anisotropic
and fractional scale factors, explicit output sizes and downsampling.
All 11 configurations match eager through the MLX runtime, the upsample
ones bit-exactly.
Fixespytorch#22017
@msluszniak
msluszniakforce-pushed the ms/mlx-group-norm-upsample branch from 9d8cb4a to bb67233CompareAugust 22, 2026 17:15
@metascroy

Copy link
Copy Markdown
Contributor

@claude review this code

@claude

claudeBot commented Aug 25, 2026

Copy link
Copy Markdown

Claude finished @metascroy's task in 6m 14s —— View job


Code Review

  • Read changed files (ops.py, test_ops.py)
  • Analyze native_group_norm handler
  • Analyze upsample_nearest2d handler
  • Review test coverage

Nice work — this is a clean, well-reasoned pair of handlers, and the commit message / PR description do an excellent job explaining why the decomposition is correct. Both handlers reuse existing primitives and follow the conventions of the surrounding code (native_layer_norm, the used_getitem_indices guard, require_args/require_kwargs, slot allocation). I ran through the logic carefully; below are the findings, ordered by importance.


1. Index computation precision vs. aten (potential correctness edge) — ops.py_nearest_source_indices

aten's nearest_neighbor_compute_source_index computes floor(dst_index * scale) in float32 (the kernel casts scale to float, see kernels/portable/cpu/util/upsample_util.h:140-149 and the const float scale_h signature in op_upsample_nearest2d.cpp:76). Eager PyTorch's reference does the same. This handler computes it in float64:

idx= (torch.arange(out_size, dtype=torch.float64) *step).to(torch.int64)

For the tested sizes this is bit-exact, but float32 and float64 can floor to different integers when dst * scale lands just below an integer boundary at larger output indices (e.g. tall/wide feature maps with a non-power-of-two scale — exactly the diffusion-decoder case this PR targets). Since the whole point of the backend is to match eager, matching aten's float32 arithmetic removes that risk:

step= ... # floatidx= (torch.arange(out_size, dtype=torch.float32) *torch.float32(step)).floor().to(torch.int64)

I'd flag this as worth confirming rather than a definite bug — the divergence only appears at boundary values the current tests don't hit. A test with a large odd spatial extent + fractional scale (e.g. shape=(1,3,127,127), scale_factor=(1.7,1.7)) would either confirm parity or surface it. Fix this →

2. native_group_norm reshape assumes NCHW-contiguous input

The reshape to (N*group, (C//group)*HxW) is only equivalent to per-group normalization if the group * (C//group) channels are laid out channel-major (standard NCHW contiguous), so that one group's channels are adjacent. This matches eager's own x.reshape(N, group, -1) decomposition and is almost certainly the layout the backend already works in, so this is likely fine — but it's an implicit assumption worth a one-line comment, since a channels-last input would silently produce wrong groupings rather than an error. Worth confirming the MLX partitioner never hands this handler a non-contiguous/channels-last tensor.

3. .vec detection via string match — minor robustness

if".vec"instr(n.target):

This works, but comparing the target directly is less fragile and reads better:

ifn.targetistorch.ops.aten.upsample_nearest2d.vec:

Things I checked that look correct

  • getitem guard: correctly rejects use of mean/rstd (indices 1/2), mirroring native_layer_norm. ✅
  • Affine application: the four-way branch (no affine / weight-only / bias-only / both) routes the final write into the node's real output slot out in every path, with temporaries otherwise. Verified each branch. ✅
  • affine_shape[1, C, 1, ...] broadcasts per-channel weight/bias correctly for both 4D and 3D (N,C,L) inputs (x_ndim - 2 trailing ones). ✅
  • Static-shape guards: N/C/HxW/group and input/output spatial sizes are all validated as int with clear error messages. ✅
  • Constant dedup: the constant name encodes in_size/out_size/scale, so identical index vectors are shared and distinct ones don't collide. ✅
  • require_args bounds: native_group_norm (8,8) and both upsample overloads match the aten schemas. ✅

Test coverage

Coverage is thorough for the common cases: affine/non-affine, instance-norm and single-group extremes, non-square and 3D inputs for group norm; integer/anisotropic/fractional/explicit-size/downsample for upsample, with rtol=atol=0. The one gap is the float32/float64 boundary case noted in #1 — a large-extent fractional-scale config would close it.


Overall this is a solid, self-contained change that fixes a real partitioning cliff for diffusion UNets. My only substantive ask is confirming the float-precision behavior in #1; the rest are minor.
· branch ms/mlx-group-norm-upsample

@metascroy

Copy link
Copy Markdown
Contributor

Thanks for the contribution! If CI passes, we can merge

@metascroy
metascroy merged commit 0cf9774 into pytorch:mainAug 26, 2026
259 of 260 checks passed
@metascroy

Copy link
Copy Markdown
Contributor

Thanks for the contribution @msluszniak!

@nil-is-allnil-is-all added the module: mlx Issues related to MLX Backend: Metal-accelerated inference on Apple Silicon label Aug 31, 2026
Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ciflow/mlxCLA SignedThis label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed.module: mlxIssues related to MLX Backend: Metal-accelerated inference on Apple Silicon

Projects

None yet

Development

Successfully merging this pull request may close these issues.

MLX backend: missing aten.native_group_norm and upsample_nearest2d fragment a diffusion UNet into 28 subgraphs

3 participants

@msluszniak@metascroy@nil-is-all