[Docs] Fix RPC tutorial to use set_input + invoke_stateful API#18855
Conversation
The Cross Compilation and RPC tutorial was using direct function call vm['main'](input, *params) which fails over RPC due to type mismatch between DLTensor* (RPC) and ffi.Tensor (VM builtins like reshape). This commit updates the tutorial to use set_input() + invoke_stateful() API which correctly handles tensor conversion for RPC scenarios. Fixes apache#18824
Summary of ChangesHello, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed! This pull request addresses a critical type mismatch error in the Cross Compilation and RPC tutorial, which previously failed when Highlights
🧠 New Feature in Public Preview: You can now enable Memory to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console. Changelog
Using Gemini Code AssistThe full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips. Invoking Gemini You can request assistance from Gemini at any point by creating a comment using either
Customization To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a Limitations & Feedback Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here. You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension. Footnotes
|
There was a problem hiding this comment.
Code Review
This pull request correctly updates the RPC tutorial to use the set_input and invoke_stateful API, which is the proper way to handle remote execution over RPC. The added comments explaining the rationale are very helpful for users. I've found one issue with how the output from get_outputs is handled, which would cause the tutorial to fail. I've detailed this in a specific comment with a suggested fix.
Problem
Issue #18824: The Cross Compilation and RPC tutorial fails when running over RPC with error:
Mismatched type on argument #0 when calling: vm.builtin.reshape(0: ffi.Tensor, 1: ffi.Shape) -> ffi.Tensor
This happens because
tvm.runtime.tensor()creates tensors that becomeDLTensor*when transmitted via RPC, but VM builtins likevm.builtin.reshapeexpectffi.Tensor.Solution
Update the tutorial to use
set_input()+invoke_stateful()API instead of direct function callvm["main"](...). This API is designed for RPC and handles the tensor type conversion internally.Changes
vm.set_input(),vm.invoke_stateful(), andvm.get_outputs()time_evaluator("invoke_stateful", ...)for RPC compatibilityFixes #18824