Skip to content

[Ascend] Fix msprof cache flush annotation handling - #4385

Open
lyz-hw wants to merge 1 commit into
tile-ai:mainfrom
lyz-hw:fix-ascend-msprof-cache-flush-annotation
Open

lyz-hw wants to merge 1 commit into
tile-ai:mainfrom
lyz-hw:fix-ascend-msprof-cache-flush-annotation

Conversation

@lyz-hw

@lyz-hw lyz-hw commented Nov 16, 2026 •

Copy link
Copy Markdown

Problem

On Python 3.10.13, running example_gemm.py with backend="msprof" fails while constructing the cache-flush PrimFunc:

TypeError: Forward references must evaluate to types. Got buffer.

Because msprof.py uses postponed annotations, Cache: TA.Tensor(...) is stored as a string. TileLang later resolves it as a forward reference, but TA.Tensor(...) evaluates to a TileLang Buffer rather than a Python type.

Approach

Define the inner cache-flush function without an inline annotation, then use a decorator to set the concrete Buffer in func.__annotations__ before calling TA.prim_func. This preserves the shape and dtype metadata needed to build the PrimFunc while avoiding the ForwardRef type check. The cache-flush kernel body and benchmark logic are unchanged.

@github-actions

Copy link
Copy Markdown

👋 Hi! Thank you for contributing to the TileLang project.

Please remember to run pre-commit run --all-files in the root directory of the project to ensure your changes are properly linted and formatted. This will help ensure your contribution passes the format check.

We appreciate you taking this step! Our team will review your contribution, and we look forward to your awesome work! 🚀

@coderabbitai

coderabbitai Bot commented Nov 16, 2026 •

Copy link
Copy Markdown
Contributor

Explain Change →

No actionable comments were generated in the recent review.

Walkthrough

The nested cache-flush kernel now receives a concrete TA.Tensor annotation for Cache before TA.prim_func is applied. The kernel body remains unchanged.

Changes: Cache Flush Kernel

Layer / File(s) Summary
Set the Cache annotation
tilelang/profiler/msprof.py
A wrapper sets Cache to TA.Tensor((numel,), "int32") before applying TA.prim_func. This replaces the postponed string annotation.

Estimated code review effort: 2 (Simple) | ~8 minutes

Change: Bug fix

Suggested labels: bug, ascend, python

Suggested reviewers: siriusneo, ljc00118

Merge Risk: Minimal · up to 04d1d

This change fixes msprof cache-flush kernel construction on Python 3.10 by setting the Cache annotation directly. The kernel behavior is unchanged and no concrete merge risk was found.

Pre-merge checks: Passed 4

Check name Status Explanation
Title check Passed The title names the Ascend msprof cache-flush annotation fix, which matches the single-file change in tilelang/profiler/msprof.py that replaces the postponed Cache annotation with a concrete buffer. I…
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.
Description check Passed The description states the problem (a TypeError on Python 3.10.13 when running example_gemm.py with backend="msprof"), the cause (postponed annotations storing Cache as a string), and the fix (define …
Full details: Title check

Explanation

The title names the Ascend msprof cache-flush annotation fix, which matches the single-file change in tilelang/profiler/msprof.py that replaces the postponed Cache annotation with a concrete buffer. It is specific and describes the main change.

Full details: Description check

Explanation

The description states the problem (a TypeError on Python 3.10.13 when running example_gemm.py with backend="msprof"), the cause (postponed annotations storing Cache as a string), and the fix (define the inner function without an inline annotation and set the Buffer in func.annotations before calling TA.prim_func). This matches the raw summary of changes to msprof.py.

Finishing Touches

Generate unit tests (beta)

  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

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

Recent review info

Run configuration

Commits

Reviewing files that changed from the base of the PR and between 210611d and 04d1d0a.

Files selected for processing: 1

  • tilelang/profiler/msprof.py

Included review availability: This review used your included allowance. Your plan provides up to 8 included reviews per hour; 7 remain after this review.

@coderabbitai
coderabbitai Bot requested review from LJC00118 and SiriusNEO November 16, 2026 02:44
@coderabbitai coderabbitai Bot added ascend bug Something isn't working python Pull requests that update python code labels Nov 16, 2026
@lyz-hw

lyz-hw commented Nov 16, 2026

Copy link
Copy Markdown
Author

cc @CeleNewYear @yangsichan Please help review this PR. Appreciated.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ascend bug Something isn't working python Pull requests that update python code

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant