feat: broaden Ascend AMP and dtype support - #135
Merged
Conversation
lvyufeng
force-pushed
the
feat/amp-dtype-support
branch
from
August 19, 2026 05:20
55cb6a2 to
07a877e
Compare
Add generated Ascend AMP unscale and foreach list-add routes, preserve float64 copies, and apply PyTorch promotion semantics to tensor-tensor binaries. Unsupported ACLNN unary and matmul dtype combinations now use the CPU reference fallback while returning correctly typed Ascend tensors.\n\nAdd comprehensive AMP and dtype integration coverage plus per-backend dtype documentation.\n\nTested: pytest tests/integration/test_amp.py - 25 passed\nTested: pytest tests/integration/test_dtype_coverage.py - 174 passed\nTested: pytest tests/unit/test_profiler_privateuse1.py tests/unit/test_vendor_routing.py - 26 passed, 3 skipped\nTested: ruff check .; ruff format --check .; git diff --check\nKnown environment failure: pytest tests/unit/ - one unrelated BPU PYTHONPATH assertion failed under the Ascend-configured shell.\n\nCo-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
zhaoyinglia
approved these changes
Aug 19, 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.
AI Agent Information
Summary
This change broadens Ascend AMP support and makes dtype behavior follow PyTorch semantics at CANN capability boundaries. It adds generated AMP unscale and foreach list-add routes, preserves float64 copies and casts, applies promotion-aware binary output allocation, and falls back to CPU for unsupported ACLNN unary and matmul dtype combinations. Comprehensive integration tests and backend dtype documentation are included.
Change Type
Platforms Affected
Problem Analysis
What was broken/missing?
_amp_foreach_non_finite_check_and_unscale_had no Ascend PrivateUse1 implementation._foreach_add_.Listwas not routed on Ascend._to_copyclamped requested float64 storage to float32.Why did it happen?
The generic Ascend codegen assumed that ACL dtype-enum availability implied per-operator support and allocated binary outputs from
self.options(). CANN 9.0 has narrower operator contracts than its dtype enum, while PrivateUse1 bypassed the normal native promotion and AMP auxiliary kernel paths for several operations.Investigation process:
flagos/mainat81fd16cand reproduced the ACLNN int16 negation, float64 matmul, mixed promotion, and float64 copy failures on Ascend 910.Solution Design
Implementation approach:
dtype_support.hwith shared Ascend capability and fallback helpers.scripts/codegen_ascend.pycategories and templates so all Ascend generated output remains codegen-owned.at::result_typeplus true-division promotion to allocate and marshal binary inputs correctly._to_copy.Key design decisions:
ascend_kernels.cc; do not hand-edit generated kernels.Code changes by file:
scripts/codegen_ascend.py: add dtype-aware unary/matmul fallback, promotion-aware binary templates, AMP unscale, and foreach list-add categories.csrc/aten/backends/ascend/dtype_support.h: shared Ascend dtype capability and CPU-result movement helpers.csrc/aten/backends/ascend/generated/ascend_kernels.cc: regenerated kernels from the updated generator.csrc/aten/backends/ascend/matmul.cc: fallback for unsupported matmul dtype combinations.csrc/aten/copy_ops.cc: preserve requested float64 dtype on Ascend copies/casts.torch_fl/configs/backends_ascend.conf: generated registrations for AMP and foreach routes.tests/integration/test_amp.py: AMP out-overload regression coverage.tests/integration/test_dtype_coverage.py: factory, unary, binary, reduction, indexing, comparison, copy, promotion, and fallback coverage.docs/reference/dtype-support.md: per-backend dtype and AMP contract.docs/reference/operator-support.md: measured Ascend route evidence and update history.Changes by commit:
55cb6a2-feat: broaden Ascend AMP and dtype support: implements generated Ascend AMP/dtype behavior, tests, and documentation.Verification
Pre-submission Checklist
Linting Results
Test Results
The single full-unit failure is the pre-existing
tests/unit/bpu/test_x86_env.py::test_env_carries_library_path_and_stubsassertion. The current shell exports Ascend paths inPYTHONPATH; the test expects the isolated temporary HBDK stubs path. The affected BPU test passes in its intended clean environment and no BPU files are changed by this PR.Manual Verification
Code Quality Verification
Style Consistency
Edge Cases Considered
.outoverload.Potential Risks
Rollback Plan
Revert commit
55cb6a2. This removes the new generated routes and restores the prior Ascend dtype behavior without changing CUDA, MetaX, DCU, or MUSA code.Related Work
Explicitly Not Included
Human Review Notes
Areas needing special attention:
BinaryResultTypeand generated binary templates for promotion behavior across all routed binary categories.dtype_support.hagainst future CANN toolkit releases.Questions for reviewer:
PYTHONPATHcontamination from affecting the existing x86 environment test?🤖 Generated with Claude Code