Skip to content

Update: expand auto_incore scope to cover RoPE and cache update in Qwen3 decode#16

Merged
zhangqi-chen merged 1 commit intohw-native-sys:mainfrom
lyfne123:main
Mar 17, 2026
Merged

Update: expand auto_incore scope to cover RoPE and cache update in Qwen3 decode#16
zhangqi-chen merged 1 commit intohw-native-sys:mainfrom
lyfne123:main

Conversation

@lyfne123
Copy link
Contributor

@lyfne123 lyfne123 commented Mar 17, 2026

  • Lift pl.auto_incore() to wrap the entire Scope 2 (RoPE, KV cache update, and decode attention) instead of attention only
  • Enable save_kernels in compile_and_run for kernel inspection
  • Reformat multi-arg slice/assemble calls for readability

Summary by CodeRabbit

  • Refactor

    • Optimized memory management efficiency in the decoding processing pipeline
    • Improved code formatting and layout clarity
  • Chores

    • Enabled kernel output tracing in example configuration

…en3 decode

- Lift `pl.auto_incore()` to wrap the entire Scope 2 (RoPE, KV cache
  update, and decode attention) instead of attention only
- Enable save_kernels in compile_and_run for kernel inspection
- Reformat multi-arg slice/assemble calls for readability
@coderabbitai
Copy link

coderabbitai bot commented Mar 17, 2026

📝 Walkthrough

Walkthrough

Wraps per-batch processing loops with pl.auto_incore() context in the RoPE and k-cache update path, applies the same pattern to RoPE application and cache tile loading sections, reformats function arguments for clarity, and enables kernel saving in RunConfig. Core decoding logic remains unchanged.

Changes

Cohort / File(s) Summary
RoPE & Cache Processing Context Management
examples/qwen3_32b_decode.py
Introduces pl.auto_incore() context wrappers around per-batch and per-head loops in RoPE rotation, k/v cache update, and tile loading sections. Reformats multiline valid_shape arguments in k_tile/v_tile slicing for improved readability. Enables save_kernels flag in RunConfig for trace output.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Poem

🐰 With auto_incore wrapped around each loop so tight,
RoPE rotations glide through memory's light,
Caches tile and shift with context divine,
Kernels saved and formatted—optimization so fine! ✨

🚥 Pre-merge checks | ✅ 2 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title directly and specifically describes the main change: expanding auto_incore scope to cover RoPE and cache updates in Qwen3 decode, which matches the primary objective of the PR.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

📝 Coding Plan
  • Generate coding plan for human review comments

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Tip

CodeRabbit can scan for known vulnerabilities in your dependencies using OSV Scanner.

OSV Scanner will automatically detect and report security vulnerabilities in your project's dependencies. No additional configuration is required.

@gemini-code-assist
Copy link

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 primarily focuses on enhancing the performance and debuggability of the Qwen3 decode model. It broadens the application of pl.auto_incore() for better optimization and introduces a mechanism to save kernels for detailed inspection. Additionally, minor formatting adjustments were made to improve code clarity.

Highlights

  • Performance Optimization: Expanded the scope of pl.auto_incore() to encompass the entire Scope 2 (RoPE, KV cache update, and decode attention) in the Qwen3 decode process, aiming to improve performance.
  • Debugging and Inspection: Enabled save_kernels in the compile_and_run function to allow for kernel inspection, aiding in debugging and optimization efforts.
  • Code Readability: Improved code readability by reformatting multi-argument pl.slice and pl.assemble calls across the codebase.
Changelog
  • examples/qwen3_32b_decode.py
    • Expanded the pl.auto_incore() context manager to cover RoPE, KV cache updates, and decode attention.
    • Reformatted pl.slice and pl.assemble function calls for improved readability.
    • Added save_kernels=True to the compile_and_run function for kernel inspection.
Activity
  • No human activity detected in this pull request.
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.

Copy link

@gemini-code-assist gemini-code-assist bot left a comment

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 expands the auto_incore scope in qwen3_32b_decode.py to include RoPE and KV cache updates, which is a good optimization. It also improves code formatting and enables kernel saving for inspection. My feedback focuses on making the kernel saving feature more configurable to avoid surprising users with generated files.

device_id=device_id,
rtol=2e-2,
atol=2e-2,
save_kernels=True,

Choose a reason for hiding this comment

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

medium

Hardcoding save_kernels=True will cause this example to always generate kernel files, which might be an unintended side effect for users. It would be better to make this behavior configurable. For instance, you could add a save_kernels parameter to the compile_and_run function and control it from the calling context (e.g., via a command-line argument in the __main__ block).

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

🧹 Nitpick comments (1)
examples/qwen3_32b_decode.py (1)

458-458: Make kernel dumping configurable instead of always enabled.

Line 458 hard-enables kernel artifact dumping for all runs. This is great for debugging, but noisy for normal execution. Prefer a function parameter with a safer default.

♻️ Proposed diff
 def compile_and_run(
@@
     dump_passes: bool = True,
+    save_kernels: bool = False,
 ):
@@
         config=RunConfig(
@@
-            save_kernels=True,
+            save_kernels=save_kernels,
             strategy=OptimizationStrategy.Default,
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@examples/qwen3_32b_decode.py` at line 458, The call currently hard-sets
save_kernels=True which always dumps kernel artifacts; change this to be
controlled by a function parameter (e.g., add a parameter save_kernels: bool =
False to the surrounding function like main/decode_runner) and pass that
parameter through where save_kernels is used (replace the literal True with the
parameter). Ensure the new parameter defaults to False so kernel dumping is
opt-in and update any callers or CLI wrapper to expose the option if desired.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Nitpick comments:
In `@examples/qwen3_32b_decode.py`:
- Line 458: The call currently hard-sets save_kernels=True which always dumps
kernel artifacts; change this to be controlled by a function parameter (e.g.,
add a parameter save_kernels: bool = False to the surrounding function like
main/decode_runner) and pass that parameter through where save_kernels is used
(replace the literal True with the parameter). Ensure the new parameter defaults
to False so kernel dumping is opt-in and update any callers or CLI wrapper to
expose the option if desired.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 6a57654d-1beb-4d3d-8b75-9688931bc08a

📥 Commits

Reviewing files that changed from the base of the PR and between 3edb010 and e0fd132.

📒 Files selected for processing (1)
  • examples/qwen3_32b_decode.py

@zhangqi-chen zhangqi-chen merged commit 15b323b into hw-native-sys:main Mar 17, 2026
3 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.

2 participants