Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 27 additions & 4 deletions components/src/dynamo/planner/config/parallelization.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,11 +63,34 @@ def tp_size(self) -> int:
return self.tp

def label(self) -> str:
"""Build a label that is injective across all five parallel dimensions.

Encodes ``(tp, pp, dp, moe_tp, moe_ep)`` so distinct topologies never
collide. Default-1 dimensions are omitted for readability.

Examples (MoE picks)::

(tp=2, dp=1, moe_tp=2, moe_ep=1) -> "tp2-moetp2"
(tp=2, dp=1, moe_tp=1, moe_ep=2) -> "tp2-moeep2"
(tp=1, dp=2, moe_tp=1, moe_ep=2) -> "tp1-dp2-moeep2"
(tp=4, dp=1, moe_tp=4, moe_ep=1) -> "tp4-moetp4"

The prior 3-bucket form (``dep{moe_ep}`` / ``tep{moe_tp}`` / ``tp{tp}``)
collapsed ``(tp=2, moe_ep=2)`` and ``(tp=1, dp=2, moe_ep=2)`` to the
same ``"dep2"`` string, which corrupted ``thorough.py`` work_dir
naming and ``aiconfigurator.sdk.picking`` ``groupby("parallel")``
dedup.
"""
parts = [f"tp{self.tp}"]
if self.pp > 1:
parts.append(f"pp{self.pp}")
if self.dp > 1:
parts.append(f"dp{self.dp}")
if self.moe_tp > 1:
parts.append(f"moetp{self.moe_tp}")
if self.moe_ep > 1:
return f"dep{self.moe_ep}"
elif self.moe_tp > 1:
return f"tep{self.moe_tp}"
return f"tp{self.tp}"
parts.append(f"moeep{self.moe_ep}")
return "-".join(parts)


def picked_to_aic_model_config_kwargs(p: PickedParallelConfig) -> dict[str, int]:
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,112 @@
# SPDX-FileCopyrightText: Copyright (c) 2025-2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
# SPDX-License-Identifier: Apache-2.0
"""Regression tests for ``PickedParallelConfig.label`` collisions.

The legacy 3-bucket label (``dep{moe_ep}`` / ``tep{moe_tp}`` / ``tp{tp}``)
collapsed distinct 5-tuples to the same string — notably
``(tp=2, moe_ep=2)`` and ``(tp=1, dp=2, moe_ep=2)`` both mapped to
``"dep2"``. That broke ``thorough.py`` work_dir naming and
``aiconfigurator.sdk.picking`` ``groupby("parallel")`` dedup. These tests
pin the post-fix unique encoding.
"""
from __future__ import annotations

import pytest

pytestmark = [
pytest.mark.gpu_0,
# TODO: revert to pytest.mark.post_merge after pre_merge validation on this PR
pytest.mark.pre_merge,
pytest.mark.unit,
pytest.mark.planner,
]

try:
from dynamo.planner.config.parallelization import PickedParallelConfig
from dynamo.profiler.utils.aic_dataframe import make_parallel_label
except ImportError as e:
pytest.skip(f"Skip (missing dependency): {e}", allow_module_level=True)


# Realistic enumeration: pure TEP / pure DEP / pure TP / dense at
# num_gpus in {1, 2, 4, 8, 16}.
_NUM_GPUS = [1, 2, 4, 8, 16]
Comment thread
coderabbitai[bot] marked this conversation as resolved.
Resolved


def _enumerate() -> list[tuple[int, int, int, int, int]]:
"""Enumerate realistic ``(tp, pp, dp, moe_tp, moe_ep)`` tuples used as
test inputs — mirrors ``filter_real_silicon_configs`` across four
archetypes (pure TP-of-experts / pure TEP-of-attention / pure DEP /
dense) at ``num_gpus ∈ {1, 2, 4, 8, 16}``."""
out: list[tuple[int, int, int, int, int]] = []
for n in _NUM_GPUS:
if n == 1:
out.append((1, 1, 1, 1, 1))
continue
out.append((n, 1, 1, n, 1)) # pure TP-of-experts (moe_tp = tp = n)
out.append((n, 1, 1, 1, n)) # pure TEP-of-attention (tp = n, moe_ep = n)
out.append((1, 1, n, 1, n)) # pure DEP (dp = n, moe_ep = n)
out.append((n, 1, 1, 1, 1)) # dense (no MoE sharding)
return out


@pytest.mark.parametrize("tup", _enumerate())
def test_label_unique_per_tuple(tup: tuple[int, int, int, int, int]) -> None:
"""Both label producers (``PickedParallelConfig.label`` and
``make_parallel_label``) must agree on every enumerated tuple."""
tp, pp, dp, moe_tp, moe_ep = tup
cfg = PickedParallelConfig(tp=tp, pp=pp, dp=dp, moe_tp=moe_tp, moe_ep=moe_ep)
df = make_parallel_label(tp, pp, dp, moe_tp, moe_ep)
assert cfg.label() == df


def test_label_distinct_across_all_enumerated_tuples() -> None:
"""Every distinct 5-tuple must yield a distinct label string."""
seen: dict[str, tuple[int, int, int, int, int]] = {}
for tup in _enumerate():
cfg = PickedParallelConfig(
tp=tup[0], pp=tup[1], dp=tup[2], moe_tp=tup[3], moe_ep=tup[4]
)
label = cfg.label()
assert (
label not in seen
), f"label collision: {label!r} from {tup} also from {seen[label]}"
seen[label] = tup


def test_regression_dep2_collision() -> None:
"""Explicit regression for the historical ``dep2`` collision."""
a = PickedParallelConfig(tp=2, dp=1, moe_ep=2)
b = PickedParallelConfig(tp=1, dp=2, moe_ep=2)
assert a != b
assert a.label() != b.label()


# (tp, pp, dp, moe_tp, moe_ep, expected_label)
_FORMAT_PINS: list[tuple[int, int, int, int, int, str]] = [
# All-default baseline.
(1, 1, 1, 1, 1, "tp1"),
# Default-1 omission: only tp varies.
(4, 1, 1, 1, 1, "tp4"),
# Docstring examples.
(2, 1, 1, 2, 1, "tp2-moetp2"),
(2, 1, 1, 1, 2, "tp2-moeep2"),
(1, 1, 2, 1, 2, "tp1-dp2-moeep2"),
(4, 1, 1, 4, 1, "tp4-moetp4"),
# PP dimension (otherwise unexercised by _enumerate()).
(2, 2, 1, 1, 1, "tp2-pp2"),
# Dense-with-attention-DP (no MoE).
(2, 1, 2, 1, 1, "tp2-dp2"),
]


@pytest.mark.parametrize("tp,pp,dp,moe_tp,moe_ep,expected", _FORMAT_PINS)
def test_label_format_pin(
tp: int, pp: int, dp: int, moe_tp: int, moe_ep: int, expected: str
) -> None:
"""Pin the exact label string — downstream consumers (``thorough.py``
work_dir, ``aiconfigurator.sdk.picking``) depend on the format, so a
separator / prefix change must be a deliberate, test-breaking edit."""
cfg = PickedParallelConfig(tp=tp, pp=pp, dp=dp, moe_tp=moe_tp, moe_ep=moe_ep)
assert cfg.label() == expected
assert make_parallel_label(tp, pp, dp, moe_tp, moe_ep) == expected
100 changes: 100 additions & 0 deletions components/src/dynamo/profiler/tests/unit/test_aic_dataframe.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
# SPDX-FileCopyrightText: Copyright (c) 2025-2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
# SPDX-License-Identifier: Apache-2.0
"""Regression tests for ``make_parallel_label`` collisions.

The legacy 3-bucket label collapsed distinct 5-tuples to the same string,
which corrupted ``thorough.py`` sweep work_dir naming and the
``aiconfigurator.sdk.picking`` ``groupby("parallel")`` dedup. These tests
pin the post-fix unique encoding.
"""
from __future__ import annotations

import pandas as pd
import pytest

pytestmark = [
pytest.mark.gpu_0,
# TODO: revert to pytest.mark.post_merge after pre_merge validation on this PR
pytest.mark.pre_merge,
pytest.mark.unit,
pytest.mark.planner,
]

try:
from dynamo.profiler.utils.aic_dataframe import make_parallel_label
except ImportError as e:
pytest.skip(f"Skip (missing dependency): {e}", allow_module_level=True)


_NUM_GPUS = [1, 2, 4, 8, 16]
Comment thread
coderabbitai[bot] marked this conversation as resolved.
Resolved


def _enumerate() -> list[tuple[int, int, int, int, int]]:
"""Enumerate realistic ``(tp, pp, dp, moe_tp, moe_ep)`` tuples used as
test inputs across four archetypes (pure TP-of-experts /
pure TEP-of-attention / pure DEP / dense) at
``num_gpus ∈ {1, 2, 4, 8, 16}``."""
out: list[tuple[int, int, int, int, int]] = []
for n in _NUM_GPUS:
if n == 1:
out.append((1, 1, 1, 1, 1))
continue
out.append((n, 1, 1, n, 1)) # pure TP-of-experts
out.append((n, 1, 1, 1, n)) # pure TEP-of-attention
out.append((1, 1, n, 1, n)) # pure DEP
out.append((n, 1, 1, 1, 1)) # dense
return out


def test_label_distinct_across_all_enumerated_tuples() -> None:
"""Every distinct 5-tuple must yield a distinct label string."""
seen: dict[str, tuple[int, int, int, int, int]] = {}
for tup in _enumerate():
label = make_parallel_label(*tup)
assert (
label not in seen
), f"label collision: {label!r} from {tup} also from {seen[label]}"
seen[label] = tup


def test_groupby_does_not_merge_distinct_topologies() -> None:
"""``aiconfigurator.sdk.picking`` does ``df.groupby("parallel")``. Two
distinct topologies must produce two groups, not one."""
df = pd.DataFrame(
[
{"parallel": make_parallel_label(2, 1, 1, 1, 2), "seq/s/gpu": 100.0},
{"parallel": make_parallel_label(1, 1, 2, 1, 2), "seq/s/gpu": 90.0},
]
)
groups = list(df.groupby("parallel"))
assert (
len(groups) == 2
), "groupby merged distinct topologies — label is not injective"


# (tp, pp, dp, moe_tp, moe_ep, expected_label)
_FORMAT_PINS: list[tuple[int, int, int, int, int, str]] = [
# All-default baseline.
(1, 1, 1, 1, 1, "tp1"),
# Default-1 omission: only tp varies.
(4, 1, 1, 1, 1, "tp4"),
# Docstring examples (mirrored from PickedParallelConfig.label).
(2, 1, 1, 2, 1, "tp2-moetp2"),
(2, 1, 1, 1, 2, "tp2-moeep2"),
(1, 1, 2, 1, 2, "tp1-dp2-moeep2"),
(4, 1, 1, 4, 1, "tp4-moetp4"),
# PP dimension (otherwise unexercised by _enumerate()).
(2, 2, 1, 1, 1, "tp2-pp2"),
# Dense-with-attention-DP (no MoE).
(2, 1, 2, 1, 1, "tp2-dp2"),
]


@pytest.mark.parametrize("tp,pp,dp,moe_tp,moe_ep,expected", _FORMAT_PINS)
def test_make_parallel_label_format_pin(
tp: int, pp: int, dp: int, moe_tp: int, moe_ep: int, expected: str
) -> None:
"""Pin the exact label string — ``aiconfigurator.sdk.picking`` and
``thorough.py`` consume this string verbatim, so format drift must be
a deliberate, test-breaking edit."""
assert make_parallel_label(tp, pp, dp, moe_tp, moe_ep) == expected
21 changes: 15 additions & 6 deletions components/src/dynamo/profiler/utils/aic_dataframe.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,22 @@


def make_parallel_label(tp: int, pp: int, dp: int, moe_tp: int, moe_ep: int) -> str:
"""Build the ``parallel`` label string used for dedup in picking."""
"""Build the ``parallel`` label string used for dedup in picking.

Injective across ``(tp, pp, dp, moe_tp, moe_ep)`` — every distinct
5-tuple maps to a distinct string. Default-1 dimensions are omitted
from the label for readability.
"""
parts = [f"tp{tp}"]
if pp > 1:
parts.append(f"pp{pp}")
if dp > 1:
parts.append(f"dp{dp}")
if moe_tp > 1:
parts.append(f"moetp{moe_tp}")
if moe_ep > 1:
return f"dep{moe_ep}"
elif moe_tp > 1:
return f"tep{moe_tp}"
else:
return f"tp{tp}"
parts.append(f"moeep{moe_ep}")
return "-".join(parts)


def build_prefill_row(
Expand Down
Loading