Skip to content

fix(scripts): apply regex fallback in dispatch entries generation#620

Open
fuyou4546 wants to merge 1 commit into
InfiniTensor:masterfrom
fuyou4546:fix/generate-wrappers-libclang-fallback
Open

fix(scripts): apply regex fallback in dispatch entries generation#620
fuyou4546 wants to merge 1 commit into
InfiniTensor:masterfrom
fuyou4546:fix/generate-wrappers-libclang-fallback

Conversation

@fuyou4546
Copy link
Copy Markdown

@fuyou4546 fuyou4546 commented May 21, 2026

Summary

  • Mirror the existing regex fallback logic from _generate_pybind11() into _generate_generated_dispatch_entries() in scripts/generate_wrappers.py.
  • Ensures the dispatch layer emits the correct C++ parameter types (std::vector<Tensor>, std::optional<Tensor>, std::vector<int64_t>) even when libclang silently downgrades them to int.

Motivation

_generate_pybind11() already falls back to regex scans when
libclang silently downgrades std::vector<Tensor>,
std::optional<Tensor>, and std::vector<int64_t> to int on
environments with incomplete STL header indexing. The dispatch
generator did not, so it emitted int rest_inputs while the pybind
layer used std::vector<Tensor> rest_inputs, breaking the build with a
type-mismatch error.

Closes #

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 Yes 4153 passed, 1393 skipped in 189.66s (0:03:09) conda env where the bug reproduces.
Iluvatar N/A Not affected No Iluvatar files or tests changed.
MetaX N/A Not affected No MetaX files or tests changed.
Cambricon N/A Not affected No Cambricon files or tests changed.
Moore N/A Not affected No Moore files or tests changed.
Ascend N/A Not affected No Ascend files or tests changed.
Full `pytest` output (optional)
pytest tests/
test session starts
platform linux -- Python 3.12.0, pytest-9.0.3, pluggy-1.6.0
rootdir: /home/zhangshuo/projects/InfiniTensor/InfiniOps
configfile: pyproject.toml
plugins: xdist-3.8.0, cov-7.1.0
collected 5546 items
···
4153 passed, 1393 skipped in 189.66s (0:03:09)

Benchmark / Performance Impact

N/A

Notes for Reviewers

The new logic in _generate_generated_dispatch_entries() is a direct
mirror of the existing fallback in _generate_pybind11() (same three
_find_* helpers, same _is_* predicate style). The only divergence
is that the dispatch layer keeps native C++ types (Tensor) rather
than substituting py::object, because it forwards directly to
Operator<Op>::Make(...). The trigger is environmental and not
consistently reproducible across setups (works fine in the project's
Docker image), so mirroring the existing precedent keeps the patch
minimal and avoids per-environment investigation.


Checklist

Every contributor must verify every item below before requesting
review. Tick each box only after the check has actually been performed —
do not tick speculatively. If an item truly does not apply, replace the
checkbox with N/A and briefly explain why in an inline comment.

Title, Branch, and Commits

  • PR title follows Conventional Commits (e.g. feat(nvidia): …, fix(cuda/gemm): …).
  • Branch name follows <type>/xxx-yyyy-zzzz where <type> matches the PR title's Conventional Commits type and words are joined with hyphens (see CONTRIBUTING.md §Branches).
  • Each commit message follows Conventional Commits.
  • Small PR is a single squashable commit; or, for a large PR, every commit is meaningful, well-formed, and independently reviewable (see CONTRIBUTING.md §Pull Requests).
  • 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 (CONTRIBUTING.md §Code/General).
  • 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.
  • N/A — No public API changes.

General Code Hygiene (applies to all languages)

  • The code is self-explanatory; comments were added only where the why is non-obvious (CONTRIBUTING.md §Code/General).
  • Every modified or added file ends with a single trailing newline (CONTRIBUTING.md §Code/General).
  • No trailing whitespace, tab/space mixing, or stray BOMs.
  • N/A — No comments or error messages were added.
  • All comments and error messages are in English (CONTRIBUTING.md §Code/General).
  • N/A — No comments or error messages were added.

C++ Specific (if C++ files changed)

  • N/A — No C++ files changed.

Python Specific (if Python files changed)

  • Code is PEP 8 compliant; ruff check passes cleanly on CI (see .github/workflows/ruff.yml).
  • ruff format --check passes cleanly — if not, run ruff format and commit the result.
  • N/A — No comments were added.
  • N/A — No framework messages were added or changed.
  • No blank line between the function signature and the body when there is no docstring or comment (CONTRIBUTING.md §Python).
  • A blank line is present before and after if, for, and similar control-flow statements (CONTRIBUTING.md §Python).
  • A blank line appears before each return, except when it directly follows a control-flow statement (CONTRIBUTING.md §Python).
  • N/A — No docstrings were added or changed.
  • N/A — No type hints were added or changed.

Testing

  • pytest was run locally on every supported platform that this PR can affect, and the results are recorded in the "Test Results" table above (CONTRIBUTING.md §Pull Requests).
  • For any platform that could not be tested, an explicit reason is given in the table and a reviewer with access has been tagged.
  • N/A — No new operator functionality was added.
  • N/A — No test parameterization was added or changed.
  • N/A — No Payload tests were added or changed.
  • N/A — No default dtype / device parameterization was added or changed.
  • N/A — No new flaky test was added.
  • Regression check: pip install . succeeds in the affected conda environment with this PR, and fails on master with the type-mismatch error quoted in "Motivation".

Build, CI, and Tooling

  • The project builds cleanly from a fresh directory with pip install .[dev] on at least one affected platform.
  • compile_commands.json still regenerates (CMake option CMAKE_EXPORT_COMPILE_COMMANDS=ON in pyproject.toml — required by the code-lint skill and clang-tidy -p).
  • N/A — No new backend or device was added.
  • N/A — No backend-selection logic was changed.
  • ruff check scripts/generate_wrappers.py and ruff format --check scripts/generate_wrappers.py pass locally.
  • N/A — No runtime dependency was added.

Documentation

  • N/A — No README, CONTRIBUTING, build flag, or developer workflow change is introduced.
  • N/A — No new operator, dispatch helper, or public utility is added outside generated code behavior.
  • N/A — No user-visible breaking change is intentionally introduced.

Security and Safety

  • No secrets, access tokens, internal URLs, customer data, or personal hardware identifiers have been committed.
  • N/A — No third-party code is added.
  • No unsafe pointer arithmetic, uninitialized reads, or missing bounds checks were introduced.

@fuyou4546 fuyou4546 requested a review from a team May 21, 2026 10:47
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