Skip to content

[Docs] Fix RPC tutorial to use set_input + invoke_stateful API#18855

Merged
tqchen merged 1 commit into
apache:mainfrom
igotyuandme320:main
Feb 28, 2026
Merged

[Docs] Fix RPC tutorial to use set_input + invoke_stateful API#18855
tqchen merged 1 commit into
apache:mainfrom
igotyuandme320:main

Conversation

@igotyuandme320

Copy link
Copy Markdown
Contributor

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 become DLTensor* when transmitted via RPC, but VM builtins like vm.builtin.reshape expect ffi.Tensor.

Solution

Update the tutorial to use set_input() + invoke_stateful() API instead of direct function call vm["main"](...). This API is designed for RPC and handles the tensor type conversion internally.

Changes

  • Updated Step 5 to use vm.set_input(), vm.invoke_stateful(), and vm.get_outputs()
  • Updated Step 6 to use time_evaluator("invoke_stateful", ...) for RPC compatibility
  • Added explanatory comments about why this approach is needed

Fixes #18824

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
@gemini-code-assist

Copy link
Copy Markdown
Contributor

Summary of Changes

Hello, 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 tvm.runtime.tensor() created DLTensor* objects that were incompatible with VM builtins expecting ffi.Tensor during RPC execution. The solution involves refactoring the tutorial to leverage the set_input() and invoke_stateful() API, which is specifically designed to handle these tensor type conversions internally for RPC, ensuring the tutorial functions correctly and provides accurate performance evaluation.

Highlights

  • RPC Tutorial Fix: Updated the Cross Compilation and RPC tutorial to resolve a Mismatched type error that occurred when running over RPC.
  • API Usage Update: Modified the tutorial to use vm.set_input() and vm.invoke_stateful() for running inference, replacing direct function calls (vm["main"](...)) for improved RPC compatibility.
  • Performance Evaluation Adjustment: Adjusted the time_evaluator call to use "invoke_stateful" for accurate performance measurement in RPC scenarios.
  • Explanatory Comments Added: Included comments to clarify why the set_input and invoke_stateful API is necessary for RPC due to internal tensor type conversion.

🧠 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
  • docs/how_to/tutorials/cross_compilation_and_rpc.py
    • Updated inference execution to use set_input and invoke_stateful for RPC compatibility.
    • Modified performance evaluation to use time_evaluator("invoke_stateful", ...).
    • Added explanatory comments regarding RPC tensor handling and type conversion.
Using Gemini Code Assist

The 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 /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

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 .gemini/ folder in the base of the repository. Detailed instructions can be found here.

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

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

@gemini-code-assist gemini-code-assist Bot 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.

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.

@tqchen tqchen merged commit 293b580 into apache:main Feb 28, 2026
6 checks passed
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.

[Bug] Mismatched type on argument, when run Cross Compilation and RPC tutorial

2 participants