[Tests] Extract shared test_result helper into tests/_utils.py#234
Open
YWHyuk wants to merge 2 commits into
Open
[Tests] Extract shared test_result helper into tests/_utils.py#234YWHyuk wants to merge 2 commits into
YWHyuk wants to merge 2 commits into
Conversation
YWHyuk
commented
May 22, 2026
| args = parser.parse_args() | ||
|
|
||
| sys.path.append(os.environ.get("TORCHSIM_DIR", "/workspace/PyTorchSim")) | ||
| from tests._utils import test_result |
Collaborator
Author
There was a problem hiding this comment.
Place these before the imports if possible.
73ab1b4 to
c08e1dc
Compare
YWHyuk
added a commit
that referenced
this pull request
May 26, 2026
tests/ was a flat mix of op-level files, single-file model tests, and
multi-file model directories with inconsistent capitalization. This PR
introduces a hierarchy:
tests/
_pytorchsim_utils.py
ops/
elementwise/ reduce/ gemm/ conv/ attention/
view/ sort/ sparsity/ misc/ fusion/
models/
DeepSeek/ Diffusion/ Llama/ MLP/ MoE/
MobileNet/ Mixtral8x7B/ Yolov5/
test_mlp.py test_resnet.py test_single_perceptron.py
test_transformer.py test_vit.py
system/
test_eager.py test_hetro.py test_scheduler.py
test_stonne.py test_vectorops.py
Mixtral_8x7B renamed to Mixtral8x7B for consistency with the other
PascalCase model dirs. Existing single-file model dirs are kept as
dirs (they may grow companion files like the Mixtral model.py).
All file moves use git mv to preserve history. External path
references rewritten across .github/workflows/pytorchsim_test.yml,
README.md, CLAUDE.md, .github/ISSUE_TEMPLATE/bug_report.md, and the
scripts/{sparsity,stonne}_experiment/ shell scripts.
Cross-test imports updated to drop the `tests.` prefix (because PR #234
puts `<repo>/tests` on sys.path[0] to avoid the ultralytics top-level
`tests` package collision):
- tests/system/test_hetro.py
- tests/system/test_scheduler.py
- tests/system/test_vectorops.py
- tests/ops/sparsity/test_sparsity.py
__init__.py added to each new subdir so e.g. `from ops.elementwise.test_add
import test_vectoradd` resolves.
Six files (test_resnet, test_vit, test_stonne, test_sparse_core,
test_gqa, test_diffusion) had their `sys.path.append` inside an
`if __name__ == "__main__":` block, which made the PR-A migration
script insert the import at the wrong indent level. Moved the
sys.path/import block to module top.
Sample-verified locally on tests/ops/elementwise/test_add.py and
tests/ops/fusion/test_matmul_vector.py (both pass) plus import-only
checks on the cross-import files.
Stacks on top of PR #234 (tests/_pytorchsim_utils.py extraction).
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
c08e1dc to
5ca0455
Compare
YWHyuk
added a commit
that referenced
this pull request
May 26, 2026
tests/ was a flat mix of op-level files, single-file model tests, and
multi-file model directories with inconsistent capitalization. This PR
introduces a hierarchy:
tests/
_pytorchsim_utils.py
ops/
elementwise/ reduce/ gemm/ conv/ attention/
view/ sort/ sparsity/ misc/ fusion/
models/
DeepSeek/ Diffusion/ Llama/ MLP/ MoE/
MobileNet/ Mixtral8x7B/ Yolov5/
test_mlp.py test_resnet.py test_single_perceptron.py
test_transformer.py test_vit.py
system/
test_eager.py test_hetro.py test_scheduler.py
test_stonne.py test_vectorops.py
Mixtral_8x7B renamed to Mixtral8x7B for consistency with the other
PascalCase model dirs. Existing single-file model dirs are kept as
dirs (they may grow companion files like the Mixtral model.py).
All file moves use git mv to preserve history. External path
references rewritten across .github/workflows/pytorchsim_test.yml,
README.md, CLAUDE.md, .github/ISSUE_TEMPLATE/bug_report.md, and the
scripts/{sparsity,stonne}_experiment/ shell scripts.
Cross-test imports updated to drop the `tests.` prefix (because PR #234
puts `<repo>/tests` on sys.path[0] to avoid the ultralytics top-level
`tests` package collision):
- tests/system/test_hetro.py
- tests/system/test_scheduler.py
- tests/system/test_vectorops.py
- tests/ops/sparsity/test_sparsity.py
__init__.py added to each new subdir so e.g. `from ops.elementwise.test_add
import test_vectoradd` resolves.
Six files (test_resnet, test_vit, test_stonne, test_sparse_core,
test_gqa, test_diffusion) had their `sys.path.append` inside an
`if __name__ == "__main__":` block, which made the PR-A migration
script insert the import at the wrong indent level. Moved the
sys.path/import block to module top.
Sample-verified locally on tests/ops/elementwise/test_add.py and
tests/ops/fusion/test_matmul_vector.py (both pass) plus import-only
checks on the cross-import files.
Stacks on top of PR #234 (tests/_pytorchsim_utils.py extraction).
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
5ca0455 to
74863f1
Compare
YWHyuk
added a commit
that referenced
this pull request
May 26, 2026
tests/ was a flat mix of op-level files, single-file model tests, and
multi-file model directories with inconsistent capitalization. This PR
introduces a hierarchy:
tests/
_pytorchsim_utils.py
ops/
elementwise/ reduce/ gemm/ conv/ attention/
view/ sort/ sparsity/ misc/ fusion/
models/
DeepSeek/ Diffusion/ Llama/ MLP/ MoE/
MobileNet/ Mixtral8x7B/ Yolov5/
test_mlp.py test_resnet.py test_single_perceptron.py
test_transformer.py test_vit.py
system/
test_eager.py test_hetro.py test_scheduler.py
test_stonne.py test_vectorops.py
Mixtral_8x7B renamed to Mixtral8x7B for consistency with the other
PascalCase model dirs. Existing single-file model dirs are kept as
dirs (they may grow companion files like the Mixtral model.py).
All file moves use git mv to preserve history. External path
references rewritten across .github/workflows/pytorchsim_test.yml,
README.md, CLAUDE.md, .github/ISSUE_TEMPLATE/bug_report.md, and the
scripts/{sparsity,stonne}_experiment/ shell scripts.
Cross-test imports updated to drop the `tests.` prefix (because PR #234
puts `<repo>/tests` on sys.path[0] to avoid the ultralytics top-level
`tests` package collision):
- tests/system/test_hetro.py
- tests/system/test_scheduler.py
- tests/system/test_vectorops.py
- tests/ops/sparsity/test_sparsity.py
__init__.py added to each new subdir so e.g. `from ops.elementwise.test_add
import test_vectoradd` resolves.
Six files (test_resnet, test_vit, test_stonne, test_sparse_core,
test_gqa, test_diffusion) had their `sys.path.append` inside an
`if __name__ == "__main__":` block, which made the PR-A migration
script insert the import at the wrong indent level. Moved the
sys.path/import block to module top.
Sample-verified locally on tests/ops/elementwise/test_add.py and
tests/ops/fusion/test_matmul_vector.py (both pass) plus import-only
checks on the cross-import files.
Stacks on top of PR #234 (tests/_pytorchsim_utils.py extraction).
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
…s.py
Replaces 48 near-duplicate ~12-line `test_result(name, out, ...)` defs
(two signature variants, three slightly divergent bodies — one had a
'pass message only' bug) with a single canonical helper that prints
framed pass/fail messages and exits 1 on mismatch. Positional-argument
compatible, so caller sites are unchanged.
Each migrated file replaces its local def with:
import os, sys
sys.path.insert(0, os.path.join(
os.environ.get("TORCHSIM_DIR", default="/workspace/PyTorchSim"), "tests"))
from _pytorchsim_utils import test_result
The module name is deliberately unique rather than `tests._utils`:
ultralytics ships its own top-level `tests` package in site-packages,
which shadows any generic `tests` import. `insert(0, .../tests)` puts
the repo's tests dir ahead of site-packages so the helper resolves
regardless of installed packages.
Net diff: 50 files changed, 220 insertions(+), 729 deletions(-).
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
tests/ was a flat mix of op-level files, single-file model tests, and
inconsistently-cased model directories. Adds a hierarchy:
tests/
_pytorchsim_utils.py
ops/
elementwise/ reduce/ gemm/ conv/ attention/
view/ sort/ sparsity/ misc/ fusion/
models/
DeepSeek/ Diffusion/ Llama/ MLP/ MoE/
MobileNet/ Mixtral8x7B/ Yolov5/
test_mlp.py test_resnet.py test_single_perceptron.py
test_transformer.py test_vit.py
system/
test_eager.py test_hetro.py test_scheduler.py
test_stonne.py test_vectorops.py
Mixtral_8x7B → Mixtral8x7B for consistency with the other PascalCase
model dirs. Existing single-file model dirs are kept as dirs (they
may grow companion files like the Mixtral model.py).
All file moves use `git mv` to preserve history. External path
references rewritten across .github/workflows/pytorchsim_test.yml,
README.md, CLAUDE.md, .github/ISSUE_TEMPLATE/bug_report.md, and
scripts/{sparsity,stonne}_experiment/.
Cross-test imports drop the `tests.` prefix (the prior commit puts
`<repo>/tests` on sys.path[0]). `__init__.py` added to each new subdir
so e.g. `from ops.elementwise.test_add import test_vectoradd` resolves.
Sample-verified locally on tests/ops/elementwise/test_add.py and
tests/ops/fusion/test_matmul_vector.py.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
3994d7a to
dff1f10
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
def test_result(name, out, cpu_out, ...)block, with two signature variants (cpu_outvsref) and three slightly divergent body variants (including a 'pass message only' bug in some files). Net duplication: ~560 lines.tests/_utils.pywith a single canonicaltest_resultand migrates every file tofrom tests._utils import test_result.Mechanical migration was applied uniformly; sample-verified locally on
test_add,test_exponent,test_sort,Fusion/test_matmul_vector,Fusion/test_attention_fusion— all pass.Net diff:
49 files changed, 208 insertions(+), 720 deletions(-).🤖 Generated with Claude Code