Register BFloat16 LayerNorm/RMSNorm kernels on the CPU EP (#31974)
### What this adds
BFloat16 registration on the CPU EP for five LayerNorm/RMSNorm op
families already permitted by their schemas:
- `LayerNormalization` (core, opset 17)
- `LayerNormalization` (contrib, opsets 1–16)
- `SimplifiedLayerNormalization`
- `SkipLayerNormalization`
- `SkipSimplifiedLayerNormalization`
The CPU implementations widen narrow-float inputs to float for
arithmetic and narrow only output tensors. No native BF16 instruction or
new ISA-specific path is added.
### Statistics and type contracts
The contrib `LayerNormalization` and `SimplifiedLayerNormalization` CPU
registrations now consistently declare `U = tensor(float)` for every
`T`, including `double`; runtime dispatch uniformly uses `ComputeImpl<T,
float>`. This corrects the generated operator documentation and matches
the kernel registrations.
This is a compatibility change for contrib models that set `stash_type =
DOUBLE`: shape inference may produce double statistic outputs, but no
CPU kernel now matches that signature. Such models fail kernel matching
during session initialization (for example, “Could not find an
implementation for LayerNormalization(1)”), rather than producing
different statistic values at runtime.
`SkipLayerNormalization` now materializes its optional CPU `mean` and
`inv_std_var` outputs for all registered input types. It uses Welford
accumulation for stable variance. `SkipSimplifiedLayerNormalization`
materializes a zero centering mean, the inverse RMS used by its
simplified normalization, and the optional residual output. This follows
the existing CUDA forward/gradient contract: simplified gradients use
inverse RMS and have no centering term.
CUDA and WebGPU SkipLayerNorm kernels are unchanged by this PR and do
not currently materialize optional statistic outputs 1/2. This PR scopes
the correction to the CPU kernels and covers the CPU behavior directly.
### Implementation cleanup
- Consolidated the MLFloat16 and BFloat16 narrow-float LayerNorm fast
paths behind one helper with thin forwarders.
- Centralized narrow-float tensor prepack conversion in
`core/util/narrow_float_utils.h`, including identical empty-tensor
behavior.
- Avoided allocating the full-size FP32 SkipLayerNorm residual scratch
unless optional output 3 is requested.
- Regenerated and verified the affected CPU `OperatorKernels.md` rows.
### Validation
- Windows x64 Debug `onnxruntime_provider_test` build.
- 43 focused `LayerNormBFloat16CpuTest.*` and `SkipLayerNormTest.*`
tests passed, including float large-mean/small-variance Welford
coverage, BF16 statistics, all optional Skip outputs, prepack paths, and
generic broadcasting.
- Windows x86 Debug `onnxruntime_providers` build.
- CPU operator documentation generated from the Python bindings and the
affected rows matched the checked-in document.
- clang-format, lintrunner, and `git diff --check`.
The Python-enabled documentation build initially hit vendored Abseil
C4702 warnings promoted to errors; rerunning it with the
repository-supported `--compile_no_warning_as_error` option succeeded
for documentation generation. No source warning from this PR was
involved.
---------
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot-Session: 3278b8e1-b3ec-4be5-a92b-0a61e0a00ffa