Skip to content

feat(bindings): support scalar default wrapper generation#601

Open
zhangyue207 wants to merge 1 commit into
InfiniTensor:masterfrom
zhangyue207:feat/bindings-optional-tensors
Open

feat(bindings): support scalar default wrapper generation#601
zhangyue207 wants to merge 1 commit into
InfiniTensor:masterfrom
zhangyue207:feat/bindings-optional-tensors

Conversation

@zhangyue207
Copy link
Copy Markdown
Collaborator

Summary

  • Update scripts/generate_wrappers.py so scalar defaults from base headers are propagated into generated py::arg(...) declarations.
  • Add focused generator tests in tests/test_generate_wrappers.py using MHA-shaped fixture headers to verify required tensor outputs, optional tensor arguments, and scalar defaults.

Motivation

Later attention operators need wrapper generation for signatures that combine required output tensors, optional tensor inputs, and scalar defaults such as num_splits = 0. This PR keeps the generator change separate from the operator implementations so later PRs do not duplicate wrapper plumbing.

N/A. No issue is linked.

Type of Change

  • feat — new feature / new operator / new platform
  • fix — bug fix
  • perf — performance improvement (no behavioral change)
  • refactor — code restructuring without behavior change
  • test — adding or fixing tests only
  • docs — documentation only
  • build / ci — build system or CI configuration
  • chore — tooling, formatting, or other non-code changes
  • Breaking change (requires a ! in the Conventional Commits prefix or a BREAKING CHANGE: footer)

Platforms Affected

  • CPU (WITH_CPU)
  • NVIDIA (WITH_NVIDIA)
  • Iluvatar (WITH_ILUVATAR)
  • MetaX (WITH_METAX)
  • Cambricon (WITH_CAMBRICON)
  • Moore (WITH_MOORE)
  • Ascend (WITH_ASCEND)
  • PyTorch C++ bindings (WITH_TORCH)
  • Build system / CMake / CI
  • Python bindings / user-facing API

Test Results on Supported Platforms

Platform Built pytest Result Notes / Hardware
NVIDIA N/A N/A No backend code touched.
Iluvatar N/A N/A No backend code touched.
MetaX N/A N/A No backend code touched.
Cambricon N/A N/A No backend code touched.
Moore N/A N/A No backend code touched.
Ascend Yes 2 passed in 0.65s infiniops-ci/ascend:latest container on Ascend 910B4.
Full `pytest` output
tests/test_generate_wrappers.py::test_mha_varlen_fwd_requires_out_binding PASSED [ 50%]
tests/test_generate_wrappers.py::test_mha_fwd_kvcache_requires_out_binding PASSED [100%]

============================== 2 passed in 0.65s ===============================

Benchmark / Performance Impact

N/A. This PR changes wrapper generation only.

Notes for Reviewers

  • API alignment note: no production src/base/ operator API is changed in this PR. The MHA-shaped headers in the tests are local fixtures for generator behavior only; public MHA API alignment remains in the MHA operator PR.
  • The generator now reads base headers via _BASE_DIR, which preserves the default src/base behavior and lets tests provide focused temporary base headers.
  • The scalar-default scanner is intentionally limited to plain scalar defaults and leaves std::optional<Tensor> handling unchanged.

Checklist

Title, Branch, and Commits

  • PR title follows Conventional Commits.
  • Branch name follows <type>/xxx-yyyy-zzzz.
  • Each commit message follows Conventional Commits.
  • Small PR is a single squashable commit.
  • No stray merge commits from master — the branch is rebased cleanly on top of the current master.
  • No fixup! / squash! / wip commits remain.

Scope and Design

  • Changes are minimal — nothing unrelated to the stated motivation was added.
  • No dead code, commented-out blocks, debug prints, printf/std::cout/print(...) left behind, or TODO without an owner and issue link.
  • No unrelated formatting churn that would obscure the diff.
  • Public API changes are intentional. No production src/base/ public API is changed.

General Code Hygiene

  • The code is self-explanatory; comments were added only where the reason is non-obvious.
  • Every modified or added file ends with a single trailing newline.
  • No trailing whitespace, tab/space mixing, or stray BOMs.
  • Identifiers in comments and error messages are wrapped in backticks.
  • All comments and error messages are in English.
  • Comments and error messages are complete sentences unless the language/framework convention says otherwise.

C++ Specific

N/A. No C++ source files are changed.

Python Specific

  • ruff check scripts/generate_wrappers.py tests/test_generate_wrappers.py passes.
  • ruff format --check scripts/generate_wrappers.py tests/test_generate_wrappers.py passes.
  • Comments are complete English sentences with Markdown backticks for code references.
  • Framework-specific conventions are honored where applicable.
  • Function body spacing follows the project Python rules.

Testing

  • pytest tests/test_generate_wrappers.py -v --tb=short was run in the project Ascend container.
  • Platforms not tested are marked N/A in the table because no backend code is changed.
  • New functionality has focused tests under tests/.

Build, CI, and Tooling

  • pip install .[dev] --no-build-isolation -C cmake.define.WITH_ASCEND=ON -C cmake.define.BUILD_ASCEND_CUSTOM=OFF -C cmake.define.AUTO_DETECT_DEVICES=OFF -C cmake.define.GENERATE_PYTHON_BINDINGS=ON passes.
  • compile_commands.json still regenerates through the build.
  • No new backend/device auto-detection changes are required.
  • No new runtime dependency was added.

Documentation

  • Documentation changes are not required because this is internal generator behavior.

Security and Safety

  • No secrets, access tokens, internal URLs, customer data, or personal hardware identifiers have been committed.
  • Third-party code is license-compatible and attributed.
  • No unsafe pointer arithmetic, uninitialized reads, or missing bounds checks were introduced.

@zhangyue207 zhangyue207 force-pushed the feat/bindings-optional-tensors branch from 455697b to ca2c4d8 Compare May 13, 2026 04:37
@zhangyue207 zhangyue207 marked this pull request as ready for review May 13, 2026 04:39
@zhangyue207 zhangyue207 requested a review from a team May 13, 2026 04:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant