Repository navigation
Expand file tree
/
Copy path_norm_validate.py
More file actions
43 lines (32 loc) · 2.22 KB
/
Copy path_norm_validate.py
File metadata and controls
43 lines (32 loc) · 2.22 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
# SPDX-FileCopyrightText: Copyright (c) 2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
# SPDX-License-Identifier: Apache-2.0
"""Python-native validation for the norm forward and backward families.
The families' ``EngineFamily.validator``. When a python engine is a candidate for a norm graph, ``pygraph.validate()``
calls :func:`validate_graph`, and a True answer skips the eager C++ lowering: the backend's verdict on the graph waits
for plan selection, where a decline does not stop a python engine from serving the graph. Two kinds of norm graph
qualify:
- extended affine graphs (adaptive scales, or a scale of ``1 + gamma``), whose fusion the backend can reject while
finalizing its operation graph; ``cudnn.norm.affine.validate_graph`` validates them;
- RMSNorm forward graphs that request the ``BATCH_INVARIANT`` numerical note, which only python engines serve, over
rows the backend may not lay out, such as rows sliced from wider rows.
Every other norm graph keeps the classic validation, in which ``validate()`` raises the backend's rejection.
"""
from __future__ import annotations
def validate_graph(graph) -> bool:
"""Whether ``graph`` is a norm graph validated here, whose C++ lowering waits for plan selection."""
from .norm.affine import validate_graph as validate_extended_affine
return validate_extended_affine(graph) or _validate_batch_invariant_rmsnorm(graph)
def _validate_batch_invariant_rmsnorm(graph) -> bool:
"""An RMSNorm forward that requests the ``BATCH_INVARIANT`` note, with a scale over trailing normalized axes and a
phase the C++ node accepts. Extended affine graphs follow their own rule alone."""
if not graph._requires_batch_invariant:
return False
from .norm.config_sm100 import NormVariant
from .norm.graph_analyzer import _norm_node, analyze, rowwise_axes_mismatch
facts = analyze(graph)
if facts is None or facts.invalid or facts.extended_affine:
return False
if facts.variant != NormVariant.RMS_NORM or facts.phase != "fprop" or facts.scale_t is None or rowwise_axes_mismatch(facts) is not None:
return False
phase = _norm_node(graph).params.get("norm_forward_phase")
return getattr(phase, "name", None) in ("TRAINING", "INFERENCE")