﻿# ONNX Runtime CPU MoE: clearing an aliased output can destroy unread tokens

The 1.32 CPU MoE alias repair preserves tokens before clearing reused output; graph-level allocation conditions belong in the regression.

Author: Retrivium team
Updated: 2026-11-15
Canonical URL: https://retrivium.ai/journal/week46-engine-ort-cpu-moe-input-output-alias-preservation/
Language: en

ONNX Runtime 1.32.0 includes CPU MoE input preservation when output storage aliases token input storage. The linked PR explains how clearing the output destroyed tokens before expert computation consumed them. A direct operator test with independent input and output buffers can therefore pass while an optimized graph using in-place reuse produces wrong results.

## An in-place contract is an implementation obligation

Allowing output to reuse input storage can save memory, but the kernel must preserve input values until their last read. The PR fixes that obligation for CPU MoE. A zeroing step that is safe for a separate output becomes destructive when the two addresses coincide. This is an ownership-and-ordering issue, not a change to expert weights or the model’s routing distribution.

## Graph context decides whether aliasing occurs

Upstream includes computed token inputs and downstream consumers in its reproduction. A graph input may receive different allocation treatment from an intermediate produced by Add or viewed through Reshape. A proposed suite should retain these graph contexts rather than only invoking MoE in isolation. Verify the actual alias condition with instrumentation where available, so a passing test does not merely reflect an allocator choosing separate storage.

## Normalization mode must not control preservation

The PR makes token preservation independent of routing-weight normalization. Those are different semantic concerns: one controls how routing contributions combine, while the other protects unread memory. Test both normalization settings with aliased and independent buffers. Otherwise a mode that happened to copy tokens for another reason can hide the missing preservation path. Distinct input values make premature clearing visible before later activations obscure the original corruption.

## Memory reuse needs numerical coverage

A smaller memory footprint is not a valid optimization if it changes the result through destroyed inputs. Compare complete graph outputs with a no-reuse reference before discussing savings. This article reports the release fix and regression conditions, without claiming a new MoE benchmark or assuming every CPU MoE error has this cause. The relevant evidence links actual aliasing to correct token preservation in the installed build.

## Sources

- [ONNX Runtime v1.32.0 release](https://github.com/microsoft/onnxruntime/releases/tag/v1.32.0)
- [ONNX Runtime pull request #33885](https://github.com/microsoft/onnxruntime/pull/33885)

## Related reading

- [CUDA restrict pointers: an aliasing promise, not a runtime safeguard](/journal/fg2-cuda-restrict-pointer-overlapping-views/)
- [ONNX Runtime I/O binding: a device pointer needs an owner and a valid lifetime](/journal/fg2-onnxruntime-io-binding-device-buffer-lifetime/)
