perf: reuse ATen tensors and optimize PyTorch fallback wrappers#798
Open
baominghelly wants to merge 2 commits into
Open
perf: reuse ATen tensors and optimize PyTorch fallback wrappers#798baominghelly wants to merge 2 commits into
baominghelly wants to merge 2 commits into
Conversation
20ef1b2 to
4165545
Compare
4165545 to
907a82a
Compare
e1611ea to
97d15af
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
at::Tensoras an opaque source handle when a Python tensor enters the bindings.at::Tensorwithat::from_blobon every dispatch.from_blobconversion for tensors without a source handle.at::Tensor.-O3instead of the previous fixed-O0.Motivation
Generated PyTorch fallback wrappers previously reconstructed an
at::Tensorfor every tensor argument on every call. Although tensor data remained zero-copy, repeatedly creating the wrapper added substantial host-side dispatch overhead for small and latency-sensitive operators.This change carries the original
at::Tensorthrough the InfiniOpsTensorwrapper and reuses its existingTensorImpl. The core tensor type keeps the handle type-erased, so it does not gain a PyTorch dependency.The bridge runs once per tensor argument, so it is built as a separate optimized object target. Generated wrappers are also optimized by default.
INFINI_OPS_TORCH_OPT_LEVELaccepts0,1,2,3, ors, allowing builds to override the default3when required.Type of Change
feat- new feature / new operator / new platformfix- bug fixperf- performance improvement (no behavioral change)refactor- code restructuring without behavior changetest- adding or fixing testsdocs- documentation onlybuild/ci- build system or CI configurationchore- tooling, formatting, or other non-code changesPlatforms Affected
WITH_CPU)WITH_NVIDIA)WITH_ILUVATAR)WITH_METAX)WITH_CAMBRICON)WITH_MOORE)WITH_ASCEND)WITH_TORCH)The shared PyTorch fallback conversion and generated-wrapper build paths change for every backend. Local build, correctness, and performance validation was performed on CPU and NVIDIA; the other vendor environments were not locally available.
Smoke Test Result
Build:
Generator and build-structure unit tests:
NVIDIA generated fallback suite:
mse_loss,smooth_l1_loss, andsoft_margin_lossare excluded because of known mismatches in the generic Python reference harness. These mismatches are unrelated to this change and reproduce independently.Test Results on Supported Platforms
1499 passed, 3145 skipped, 54 deselectedBenchmark / Performance Impact
Command:
Environment and methodology:
standardLLM shapesFinal result relative to the original fixed-
O0, non-reuse implementation:Median InfiniOps latency decreased by 64.12%, corresponding to approximately 2.79x throughput at the wrapper level. Normalizing for the reference-side timing difference gives an improvement of approximately 60.61%. The median dispatch gap decreased by approximately 80.07%.
Notes for Reviewers
Please focus on:
Tensor.from_blobpath.src/torch/pybind11_.ccoutside the generated Torch wrapper target so the dispatch bridge remains optimized.-O3behavior.The excluded loss-operator cases are generic reference-harness mismatches and are unrelated to tensor reuse or compiler optimization.