feat(torch): generate PyTorch backend from local ATen schemas#595
Open
voltjia wants to merge 4 commits into
Open
feat(torch): generate PyTorch backend from local ATen schemas#595voltjia wants to merge 4 commits into
voltjia wants to merge 4 commits into
Conversation
9cb7b73 to
be71261
Compare
0897fc9 to
26082cd
Compare
26082cd to
0016a27
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
pyyamlto[build-system].requiresso the build can parse the generated-backend allowlist duringpip install.scripts/generate_torch_ops.py, a YAML-driven generator that reads the locally installed PyTorch /torchgenpackagednative_functions.yaml.scripts/torch_ops.yamlwith 525 allowlisted ATen base op names for generated PyTorch backend coverage.WITH_TORCH=ON.scripts/generate_wrappers.pyso generated base and backend files participate in Python bindings and dispatch metadata.generated/torch_ops_metadata.jsonand execute each active PyTorch backend slot.Motivation
InfiniOps already supports multiple native/vendor backends. This PR adds a generated PyTorch C++ backend path so a large set of ATen
_outoperators can be exposed through the same operator/binding surface without hand-writing hundreds of base and backend files.The generator intentionally uses the local PyTorch installation instead of downloading
native_functions.yaml: enablingWITH_TORCHalready requires PyTorch to be installed, and using the local schema keeps generated code matched to the PyTorch headers and libraries being compiled.Closes N/A.
Type of Change
feat— new feature / new operator / new platformN/A:
fix— this is not a bug-fix-only PR.N/A:
perf— no runtime hot-path optimization is intended.N/A:
refactor— the primary change is new generated PyTorch backend support.test— adds generated-backend coverage.N/A:
docs— this is not documentation-only.build/ci— integrates generation into the build.N/A:
chore— this is not tooling-only.N/A: Breaking change.
Platforms Affected
WITH_CPU)WITH_NVIDIA)WITH_ILUVATAR)WITH_METAX)WITH_CAMBRICON)WITH_MOORE)WITH_ASCEND)WITH_TORCH)Test Results on Supported Platforms
All supported platforms were validated with
WITH_TORCH=ONandpytest -v; generated PyTorch backend tests were included in the collected pytest set on every platform below.Timing columns were measured inside the test container with base image build skipped:
build/install=pip install .[dev] --no-build-isolation, including generated source creation and native extension compilation.pytest= fullpytestrun.total=build/install + pytest; source sync and launcher overhead are excluded.pytestResult9206 passed, 8664 skipped, 104 warnings in 177.98s (0:02:57)7410 passed, 8942 skipped, 100 warnings in 150.05s (0:02:30)8698 passed, 7654 skipped, 102 warnings in 226.55s (0:03:46)5899 passed, 10069 skipped, 317 warnings in 461.84s (0:07:41)8471 passed, 7899 skipped, 119 warnings in 237.29s (0:03:57)7406 passed, 8904 skipped, 108 warnings in 232.62s (0:03:52)137after the summary.Full `pytest` output (optional)
Benchmark / Performance Impact
N/A for runtime hot paths. Generated PyTorch backends call the corresponding ATen
_outimplementation.The validation run above records build/install and pytest wall times to help track generated-backend build cost. Build/install time is currently the dominant cost on every platform.
The latest validation also saved verbose pytest logs and generated source trees under the local result directory
ci-results/remote/torch-codegen-pr595-reviewfix-vgenerated-20260517/. The generated source trees are also archived locally as/tmp/torch-codegen-pr595-reviewfix-generated-20260517.tar.gz.Notes for Reviewers
masterafter fix(torch): makegemmfallback portable #611 and fix(tests): runcausal_softmaxreference on CPU #612 merged.build: add PyYAML build dependencyfeat(scripts): add YAML-driven torch op codegenbuild(torch): integrate generated torch backendtest(torch): add generated backend coveragesrc/base/<op>.hfiles continue to shadow generated base headers.Checklist
Title, Branch, and Commits
<type>/xxx-yyyy-zzzz—feat/torch-codegen.master— branch is rebased cleanly on top of currentmaster.fixup!/squash!/wipcommits remain.Scope and Design
TODOs were added.infini::ops::<Op>classes and slot-8 PyTorch backends are part of this feature.General Code Hygiene
C++ Specific
N/A: no committed
.h,.cc,.cuh, or.mlufiles are modified by this PR.Python Specific
ruff format --checkpassed for modified Python files in the CI container.ruff checkpassed for modified Python files in the CI container.ruffworkflow is green on the latest pushed commit.pytest.skipmessages follow existing test conventions.ruff format --check.Testing
pytestwas run on every supported platform — see the platform table above.tests/.pytest.mark.parametrizefor generated op metadata, shapes, dtypes, and tolerances.Build, CI, and Tooling
pip install .[dev] --no-build-isolationon every supported platform.compile_commands.jsongeneration remains enabled through existing CMake configuration.WITH_TORCHauto-detection was updated to use an installed Python withtorch.clang-formatworkflow is green on the latest pushed commit.ruffworkflow is green on the latest pushed commit.pyyamlis added topyproject.toml's[build-system].requires.Documentation
N/A: no user-facing documentation file was changed.
Security and Safety