feat(torch): generate PyTorch backend from local ATen schemas#595
Merged
Conversation
9cb7b73 to
be71261
Compare
0897fc9 to
26082cd
Compare
26082cd to
0016a27
Compare
Collaborator
Author
|
请 @crapromer 初审,@Ziminli 终审。 |
crapromer
previously approved these changes
May 18, 2026
Ziminli
previously approved these changes
May 18, 2026
Collaborator
Ziminli
left a comment
There was a problem hiding this comment.
仅有小的格式问题,可以新提一个 PR 单独修改。
0016a27 to
f766a0e
Compare
crapromer
approved these changes
May 18, 2026
Ziminli
approved these changes
May 18, 2026
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 revalidated after the review-comment fix 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= fullpytest -vrun.total=build/install + pytest; source sync and launcher overhead are excluded.pytestResult9206 passed, 8664 skipped, 105 warnings in 181.26s (0:03:01)7410 passed, 8942 skipped, 102 warnings in 157.59s (0:02:37)2 failed, 8697 passed, 7653 skipped, 119 warnings in 224.25s (0:03:44)-n 6run. Targeted recheck of the same nodeids with-n 1completed with1 passed, 1 skipped.5899 passed, 10069 skipped, 323 warnings in 467.15s (0:07:47)8471 passed, 7899 skipped, 120 warnings in 239.66s (0:03:59)7406 passed, 8904 skipped, 111 warnings in 235.42s (0:03:55)pytest_exit_code=0; outer wrapper returned137after the summary.Generated source trees and verbose pytest logs were copied locally for this run. The generated metadata contained PyTorch op entries on every platform: NVIDIA/Moore/Ascend 614, MetaX/Iluvatar 612, and Cambricon 604. The small differences come from the locally installed PyTorch schema/version on each platform.
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 saved verbose pytest logs and generated source trees under the local result directory
ci-results/remote/pr595-reviewfix-full-20260518/. The MetaX targeted recheck log is underci-results/remote/pr595-reviewfix-metax-recheck-20260518/. The generated source trees are also archived locally as/tmp/torch-codegen-pr595-reviewfix-generated-20260518.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