Skip to content

[DLPack][TVM FFI] Return PyCapsule in __c_dlpack_exchange_api__ in tvm ffi 0.1.4+#76673

Merged
SigureMo merged 7 commits into
PaddlePaddle:developfrom
cattidea:dlpack/return-pycapsule-in-tvm-ffi-0-1-4-plus
Nov 30, 2025
Merged

[DLPack][TVM FFI] Return PyCapsule in __c_dlpack_exchange_api__ in tvm ffi 0.1.4+#76673
SigureMo merged 7 commits into
PaddlePaddle:developfrom
cattidea:dlpack/return-pycapsule-in-tvm-ffi-0-1-4-plus

Conversation

@SigureMo

@SigureMo SigureMo commented Nov 27, 2025

Copy link
Copy Markdown
Member

PR Category

Execute Infrastructure

PR Types

Improvements

Description

在 TVM FFI 0.1.4+ 或者说只要用户没有装 TVM FFI 0.1.0/0.1.1/0.1.2/0.1.3__c_dlpack_exchange_api__ 就返回按照新的协议的指针包装后的 PyCapsule,以匹配最新协议(这里更多是实现而非原本协议中的内容,见 pytorch/pytorch#162845pytorch/pytorch#165483

虽然 TVM FFI 0.1.4 已经做了兼容性处理(apache/tvm-ffi#288),但我们不敢保证这一兼容性处理具体会持续多久,我们希望即将发布的 3.3.0 能够与下游生态有更松的耦合(FlashInfer、TileLang 等),确保这一版本尽可能长期可用,因此在 3.3.0 会添加这一兼容性逻辑

此外 CI 只监控 tvm-ffi 0.1.4 行为,0.1.3- 行为已经在 548666a 验证过

@paddle-bot

paddle-bot Bot commented Nov 27, 2025

Copy link
Copy Markdown

你的PR提交成功,感谢你对开源项目的贡献!
请关注后续CI自动化测试结果,详情请参考Paddle-CI手册
Your PR has been submitted. Thanks for your contribution!
Please wait for the result of CI firstly. See Paddle CI Manual for details.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR adds compatibility for TVM FFI 0.1.4+ by conditionally returning either a raw pointer or a PyCapsule from the __c_dlpack_exchange_api__ interface. The change ensures backward compatibility with TVM FFI versions 0.1.0-0.1.3 while supporting the new protocol in 0.1.4+.

Key Changes:

  • Introduced version detection logic to determine which DLPack exchange API format to return
  • Added new C++ binding dlpack_exchange_api_pycapsule() that returns a PyCapsule
  • Modified tensor patch method to call version-aware _get_c_dlpack_exchange_api() function instead of directly using the raw pointer

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 3 comments.

File Description
python/paddle/base/dygraph/tensor_patch_methods.py Implements version detection logic and conditional return of pointer vs PyCapsule for DLPack exchange API
paddle/fluid/pybind/pybind.cc Adds new Python binding function to return DLPack exchange API as a PyCapsule

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread python/paddle/base/dygraph/tensor_patch_methods.py Outdated
Comment thread python/paddle/base/dygraph/tensor_patch_methods.py
Comment thread python/paddle/base/dygraph/tensor_patch_methods.py Outdated
SigureMo and others added 3 commits November 28, 2025 02:07
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
@codecov-commenter

codecov-commenter commented Nov 27, 2025

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 66.66667% with 3 lines in your changes missing coverage. Please review.
⚠️ Please upload report for BASE (develop@584c692). Learn more about missing BASE report.

Files with missing lines Patch % Lines
python/paddle/base/dygraph/tensor_patch_methods.py 66.66% 3 Missing ⚠️

❌ Your patch status has failed because the patch coverage (66.66%) is below the target coverage (90.00%). You can increase the patch coverage or adjust the target coverage.

Additional details and impacted files
@@            Coverage Diff             @@
##             develop   #76673   +/-   ##
==========================================
  Coverage           ?   66.66%           
==========================================
  Files              ?        1           
  Lines              ?        9           
  Branches           ?        0           
==========================================
  Hits               ?        6           
  Misses             ?        3           
  Partials           ?        0           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@SigureMo

Copy link
Copy Markdown
Member Author
image

tvm_ffi 0.1.0-0.1.3 正确性覆盖已经在 548666a 验证

@SigureMo

Copy link
Copy Markdown
Member Author
image

如上所述,最终未覆盖部分在之前 commit 验证过,最终只监控最新的 tvm ffi 0.1.4,不监控 0.1.3,故豁免

@SigureMo SigureMo requested review from gouzil and zrr1999 November 30, 2025 14:49
@ooooo-create

Copy link
Copy Markdown
Contributor

/skip-ci coverage

@SigureMo SigureMo merged commit 7a6e844 into PaddlePaddle:develop Nov 30, 2025
64 of 67 checks passed
@SigureMo SigureMo deleted the dlpack/return-pycapsule-in-tvm-ffi-0-1-4-plus branch November 30, 2025 14:59
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.

5 participants