From dc5bf02487e048a78563927b2e53823a7d0b1896 Mon Sep 17 00:00:00 2001 From: Chao Wang <26245345+ChaoWao@users.noreply.github.com> Date: Tue, 28 Jul 2026 01:36:29 -0700 Subject: [PATCH] Refactor: make the examples tree internally consistent Three inconsistencies, each of which makes the tree harder to read than the code in it warrants. None changes behaviour. Test module names now match their directory. Four scene tests were named after a sibling example rather than their own: paged_attention_manual_scope and paged_attention_unroll_manual_scope, on both arches, each carried the plain paged_attention test name, so a failure report named a directory that was not the one running. scalar_data_test is renamed to scalar_data, since the directory suffix only duplicated what test_ already says; the file inside keeps its name and now matches. vector_add keeps two test modules on purpose: test_run_timing.py asserts the [STRACE] markers and is a second test, not a mismatched one. Four L3 example directories gained the __init__.py their siblings all have. Without it the package-relative `from .main import run` that every one of these tests uses depends on rootdir inference rather than being a package. allreduce had no test at all, so the only L3 example without regression protection was a collective. It now has one, scoped to a2a3: the demo's own README and CLI default document that platform, and while the algorithm is covered on a5 by tests/st/worker/collectives/allreduce, nobody has run this demo there. Widening it is a separate, verifiable step. The test documents that run() takes (device_ids, platform), the reverse of the single-device demos beside it. Co-Authored-By: Claude Opus 5 (1M context) --- ...y => test_paged_attention_manual_scope.py} | 0 ...st_paged_attention_unroll_manual_scope.py} | 0 .../kernels/aiv/kernel_add.cpp | 0 .../kernels/aiv/kernel_noop.cpp | 0 .../orchestration/scalar_data_orch.cpp | 0 .../test_scalar_data.py | 0 ...y => test_paged_attention_manual_scope.py} | 0 ...st_paged_attention_unroll_manual_scope.py} | 0 examples/workers/l3/allreduce/__init__.py | 9 ++++++ .../workers/l3/allreduce/test_allreduce.py | 31 +++++++++++++++++++ .../workers/l3/ffn_tp_parallel/__init__.py | 9 ++++++ .../l3/l3_l2_message_queue/__init__.py | 9 ++++++ .../l3/l3_l2_orch_comm_stream/__init__.py | 9 ++++++ 13 files changed, 67 insertions(+) rename examples/a2a3/tensormap_and_ringbuffer/paged_attention_manual_scope/{test_paged_attention.py => test_paged_attention_manual_scope.py} (100%) rename examples/a2a3/tensormap_and_ringbuffer/paged_attention_unroll_manual_scope/{test_paged_attention_unroll.py => test_paged_attention_unroll_manual_scope.py} (100%) rename examples/a2a3/tensormap_and_ringbuffer/{scalar_data_test => scalar_data}/kernels/aiv/kernel_add.cpp (100%) rename examples/a2a3/tensormap_and_ringbuffer/{scalar_data_test => scalar_data}/kernels/aiv/kernel_noop.cpp (100%) rename examples/a2a3/tensormap_and_ringbuffer/{scalar_data_test => scalar_data}/kernels/orchestration/scalar_data_orch.cpp (100%) rename examples/a2a3/tensormap_and_ringbuffer/{scalar_data_test => scalar_data}/test_scalar_data.py (100%) rename examples/a5/tensormap_and_ringbuffer/paged_attention_manual_scope/{test_paged_attention.py => test_paged_attention_manual_scope.py} (100%) rename examples/a5/tensormap_and_ringbuffer/paged_attention_unroll_manual_scope/{test_paged_attention_unroll.py => test_paged_attention_unroll_manual_scope.py} (100%) create mode 100644 examples/workers/l3/allreduce/__init__.py create mode 100644 examples/workers/l3/allreduce/test_allreduce.py create mode 100644 examples/workers/l3/ffn_tp_parallel/__init__.py create mode 100644 examples/workers/l3/l3_l2_message_queue/__init__.py create mode 100644 examples/workers/l3/l3_l2_orch_comm_stream/__init__.py diff --git a/examples/a2a3/tensormap_and_ringbuffer/paged_attention_manual_scope/test_paged_attention.py b/examples/a2a3/tensormap_and_ringbuffer/paged_attention_manual_scope/test_paged_attention_manual_scope.py similarity index 100% rename from examples/a2a3/tensormap_and_ringbuffer/paged_attention_manual_scope/test_paged_attention.py rename to examples/a2a3/tensormap_and_ringbuffer/paged_attention_manual_scope/test_paged_attention_manual_scope.py diff --git a/examples/a2a3/tensormap_and_ringbuffer/paged_attention_unroll_manual_scope/test_paged_attention_unroll.py b/examples/a2a3/tensormap_and_ringbuffer/paged_attention_unroll_manual_scope/test_paged_attention_unroll_manual_scope.py similarity index 100% rename from examples/a2a3/tensormap_and_ringbuffer/paged_attention_unroll_manual_scope/test_paged_attention_unroll.py rename to examples/a2a3/tensormap_and_ringbuffer/paged_attention_unroll_manual_scope/test_paged_attention_unroll_manual_scope.py diff --git a/examples/a2a3/tensormap_and_ringbuffer/scalar_data_test/kernels/aiv/kernel_add.cpp b/examples/a2a3/tensormap_and_ringbuffer/scalar_data/kernels/aiv/kernel_add.cpp similarity index 100% rename from examples/a2a3/tensormap_and_ringbuffer/scalar_data_test/kernels/aiv/kernel_add.cpp rename to examples/a2a3/tensormap_and_ringbuffer/scalar_data/kernels/aiv/kernel_add.cpp diff --git a/examples/a2a3/tensormap_and_ringbuffer/scalar_data_test/kernels/aiv/kernel_noop.cpp b/examples/a2a3/tensormap_and_ringbuffer/scalar_data/kernels/aiv/kernel_noop.cpp similarity index 100% rename from examples/a2a3/tensormap_and_ringbuffer/scalar_data_test/kernels/aiv/kernel_noop.cpp rename to examples/a2a3/tensormap_and_ringbuffer/scalar_data/kernels/aiv/kernel_noop.cpp diff --git a/examples/a2a3/tensormap_and_ringbuffer/scalar_data_test/kernels/orchestration/scalar_data_orch.cpp b/examples/a2a3/tensormap_and_ringbuffer/scalar_data/kernels/orchestration/scalar_data_orch.cpp similarity index 100% rename from examples/a2a3/tensormap_and_ringbuffer/scalar_data_test/kernels/orchestration/scalar_data_orch.cpp rename to examples/a2a3/tensormap_and_ringbuffer/scalar_data/kernels/orchestration/scalar_data_orch.cpp diff --git a/examples/a2a3/tensormap_and_ringbuffer/scalar_data_test/test_scalar_data.py b/examples/a2a3/tensormap_and_ringbuffer/scalar_data/test_scalar_data.py similarity index 100% rename from examples/a2a3/tensormap_and_ringbuffer/scalar_data_test/test_scalar_data.py rename to examples/a2a3/tensormap_and_ringbuffer/scalar_data/test_scalar_data.py diff --git a/examples/a5/tensormap_and_ringbuffer/paged_attention_manual_scope/test_paged_attention.py b/examples/a5/tensormap_and_ringbuffer/paged_attention_manual_scope/test_paged_attention_manual_scope.py similarity index 100% rename from examples/a5/tensormap_and_ringbuffer/paged_attention_manual_scope/test_paged_attention.py rename to examples/a5/tensormap_and_ringbuffer/paged_attention_manual_scope/test_paged_attention_manual_scope.py diff --git a/examples/a5/tensormap_and_ringbuffer/paged_attention_unroll_manual_scope/test_paged_attention_unroll.py b/examples/a5/tensormap_and_ringbuffer/paged_attention_unroll_manual_scope/test_paged_attention_unroll_manual_scope.py similarity index 100% rename from examples/a5/tensormap_and_ringbuffer/paged_attention_unroll_manual_scope/test_paged_attention_unroll.py rename to examples/a5/tensormap_and_ringbuffer/paged_attention_unroll_manual_scope/test_paged_attention_unroll_manual_scope.py diff --git a/examples/workers/l3/allreduce/__init__.py b/examples/workers/l3/allreduce/__init__.py new file mode 100644 index 0000000000..25708baecc --- /dev/null +++ b/examples/workers/l3/allreduce/__init__.py @@ -0,0 +1,9 @@ +# Copyright (c) PyPTO Contributors. +# This program is free software, you can redistribute it and/or modify it under the terms and conditions of +# CANN Open Software License Agreement Version 2.0 (the "License"). +# Please refer to the License for details. You may not use this file except in compliance with the License. +# THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR IMPLIED, +# INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY, OR FITNESS FOR A PARTICULAR PURPOSE. +# See LICENSE in the root of the software repository for the full text of the License. +# ----------------------------------------------------------------------------------------------------------- +"""Package marker so ``test_*.py`` can do ``from .main import run``.""" diff --git a/examples/workers/l3/allreduce/test_allreduce.py b/examples/workers/l3/allreduce/test_allreduce.py new file mode 100644 index 0000000000..02172dd75b --- /dev/null +++ b/examples/workers/l3/allreduce/test_allreduce.py @@ -0,0 +1,31 @@ +# Copyright (c) PyPTO Contributors. +# This program is free software, you can redistribute it and/or modify it under the terms and conditions of +# CANN Open Software License Agreement Version 2.0 (the "License"). +# Please refer to the License for details. You may not use this file except in compliance with the License. +# THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR IMPLIED, +# INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY, OR FITNESS FOR A PARTICULAR PURPOSE. +# See LICENSE in the root of the software repository for the full text of the License. +# ----------------------------------------------------------------------------------------------------------- +"""Hardware ST for examples/workers/l3/allreduce. + +Covers the demo only. The allreduce *algorithm* corpus — ring, twophase, ibing +and bidirectional-ring — lives in tests/st/worker/collectives/allreduce. +""" + +import pytest + +from .main import run + + +# a2a3 only, which is what this demo's own README and CLI default document. +# The algorithm itself runs on a5 — tests/st/worker/collectives/allreduce +# declares all four platforms — so widening this is likely safe, but nobody has +# exercised *this* demo there yet. +@pytest.mark.platforms(["a2a3sim", "a2a3"]) +@pytest.mark.runtime("tensormap_and_ringbuffer") +@pytest.mark.device_count(2) +def test_allreduce(st_platform, st_device_ids): + # run() takes (device_ids, platform) — the reverse of the single-device + # demos in this tree, which take (platform, device_id). + rc = run([int(d) for d in st_device_ids], platform=st_platform) + assert rc == 0 diff --git a/examples/workers/l3/ffn_tp_parallel/__init__.py b/examples/workers/l3/ffn_tp_parallel/__init__.py new file mode 100644 index 0000000000..25708baecc --- /dev/null +++ b/examples/workers/l3/ffn_tp_parallel/__init__.py @@ -0,0 +1,9 @@ +# Copyright (c) PyPTO Contributors. +# This program is free software, you can redistribute it and/or modify it under the terms and conditions of +# CANN Open Software License Agreement Version 2.0 (the "License"). +# Please refer to the License for details. You may not use this file except in compliance with the License. +# THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR IMPLIED, +# INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY, OR FITNESS FOR A PARTICULAR PURPOSE. +# See LICENSE in the root of the software repository for the full text of the License. +# ----------------------------------------------------------------------------------------------------------- +"""Package marker so ``test_*.py`` can do ``from .main import run``.""" diff --git a/examples/workers/l3/l3_l2_message_queue/__init__.py b/examples/workers/l3/l3_l2_message_queue/__init__.py new file mode 100644 index 0000000000..25708baecc --- /dev/null +++ b/examples/workers/l3/l3_l2_message_queue/__init__.py @@ -0,0 +1,9 @@ +# Copyright (c) PyPTO Contributors. +# This program is free software, you can redistribute it and/or modify it under the terms and conditions of +# CANN Open Software License Agreement Version 2.0 (the "License"). +# Please refer to the License for details. You may not use this file except in compliance with the License. +# THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR IMPLIED, +# INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY, OR FITNESS FOR A PARTICULAR PURPOSE. +# See LICENSE in the root of the software repository for the full text of the License. +# ----------------------------------------------------------------------------------------------------------- +"""Package marker so ``test_*.py`` can do ``from .main import run``.""" diff --git a/examples/workers/l3/l3_l2_orch_comm_stream/__init__.py b/examples/workers/l3/l3_l2_orch_comm_stream/__init__.py new file mode 100644 index 0000000000..25708baecc --- /dev/null +++ b/examples/workers/l3/l3_l2_orch_comm_stream/__init__.py @@ -0,0 +1,9 @@ +# Copyright (c) PyPTO Contributors. +# This program is free software, you can redistribute it and/or modify it under the terms and conditions of +# CANN Open Software License Agreement Version 2.0 (the "License"). +# Please refer to the License for details. You may not use this file except in compliance with the License. +# THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR IMPLIED, +# INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY, OR FITNESS FOR A PARTICULAR PURPOSE. +# See LICENSE in the root of the software repository for the full text of the License. +# ----------------------------------------------------------------------------------------------------------- +"""Package marker so ``test_*.py`` can do ``from .main import run``."""