test: unify cross-backend RNG integration coverage - #141
Open
lvyufeng wants to merge 1 commit into
Open
Conversation
lvyufeng
force-pushed
the
test/unify-rng
branch
3 times, most recently
from
August 19, 2026 08:33
62269de to
0298739
Compare
Consolidate MUSA RNG integration coverage into the shared dispatch suite and select hardware-specific behavior with pytest marks. Synchronize the public torch.flagos RNG state API with CUDA-shaped Philox generators used by CUDA and MetaX FlagGems paths, and update CI and documentation accordingly. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
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.
AI Agent Information
torch.flagos, synchronized CUDA and MetaX compatibility state, and updated CI and documentation.Summary
This PR makes
tests/integration/ops/test_rng_dispatch.pythe single cross-backend RNG integration suite. Shared behavior is exercised through thetorch.flagospublic API, while genuine backend differences use existing pytest platform marks; the redundant MUSA-only integration file is removed. CUDA and MetaX compatibility layers now synchronize their internal CUDA-shaped Philox generators with the publictorch.flagosseed and state APIs, and CUDA, DCU, MetaX, and documentation references are updated accordingly.Change Type
Platforms Affected
Problem Analysis
What was broken/missing?
RNG integration coverage was split between the shared dispatch test and a duplicate MUSA-only test file. The split allowed public RNG behavior to drift between hardware-specific suites and caused the shared tests to encode CUDA generator implementation details even though the user-facing backend is
torch.flagos.Why did it happen?
CUDA-compatible FlagGems and boxing paths use CUDA-shaped Philox generators internally, while native PrivateUse1 paths expose
torch.flagosgenerators. The test consolidation initially treated those internal representations as the public contract. In addition, CUDA and MetaX compatibility layers seeded their internal Philox generators without synchronizing thetorch.flagosstate API.Investigation process:
test_rng_dispatch.py, the deleted MUSA RNG suite, platform marker setup, all affected CI manifests, and MUSA/operator-support documentation.torch.flagosstate was separate from CUDA-shaped generators.torch_fl/flagos/random.py,csrc/runtime/generator.cc, the CUDA/MetaX compatibility shims, and FlagGems integration paths.Solution Design
Implementation approach:
test_rng_dispatch.pyand select MUSA-only reservation behavior with@pytest.mark.musa.torch.flagos.torch.flagos.manual_seed,manual_seed_all,get_rng_state, andset_rng_stateon CUDA and MetaX.Key design decisions:
The public cross-backend contract uses
torch.flagos, nottorch.cuda. CUDA and MetaX still require Philox-shaped generator state internally for FlagGems, so those representations remain behind compatibility shims rather than being exposed as test prerequisites. The duplicate MUSA integration file is removed instead of maintaining another hardware-specific source of truth.Code changes by file:
.github/configs/cuda.yml: run the unified RNG suite explicitly..github/configs/dcu.yml: run the unified RNG suite explicitly..github/configs/metax.yml: run the unified RNG suite explicitly.docs/reference/operator-support.md: replace the standalone MUSA RNG test reference and retain the upstream MUPTI history entry.docs/vendors/musa/installation.md: document the unified RNG test path and MUSA mark selection.tests/integration/ops/test_musa_rng.py: remove duplicate MUSA integration coverage.tests/integration/ops/test_rng_dispatch.py: consolidate shared RNG contracts and isolate backend-specific behavior with marks and capability checks.tests/unit/test_musa_rng_bridge.py: skip the MUSA-symbol-dependent case on builds without the bridge symbol.torch_fl/accelerator/cuda/_cuda_compat.py: synchronize publictorch.flagosseed/state APIs with internal CUDA Philox generators.torch_fl/accelerator/metax/_metax_compat.py: synchronize publictorch.flagosseed/state APIs with internal MetaX Philox generators.Changes by commit:
3f32be5-test: unify cross-backend RNG integration coverage: consolidate tests, synchronize public and internal RNG state, and update CI/docs.Verification
Pre-submission Checklist
Linting Results
Test Results
The FlagGems-only command was also attempted:
The two failures occur before RNG assertions because
onesis not registered in the current localbackends_flaggems.confenvironment. Hardware CI with the vendor FlagGems runtime is required for that path.Manual Verification
Collection verification:
$ python -m pytest tests/integration/ops/test_rng_dispatch.py --collect-only -q 115 tests collected in 0.11sCode Quality Verification
Style Consistency
Edge Cases Considered
torch.flagos.get_rng_stateandset_rng_state.manual_seed_allreplay and independent per-device generators.Potential Risks
torch.flagosseed/state callables; regressions would affect FlagGems reproducibility on those platforms.Rollback Plan
Revert commit
3f32be5. This restores the previous MUSA-specific integration file and compatibility behavior without changing unrelated commits.Related Work
Explicitly Not Included
Human Review Notes
Areas needing special attention:
torch.flagosstate synchronization matches their internal Philox consumption model.flagosgenerator acceptance remains correctly capability-conditioned for native backends.Questions for reviewer:
Additional Context
The branch is based on the latest
flagos/mainand contains only the RNG unification commit.🤖 Generated with Claude Code