Skip to content

[IR] Validate global_symbol on all functions, not just Relax#18834

Closed
tqchen wants to merge 2 commits intoapache:mainfrom
tqchen:validate-global-symbol
Closed

[IR] Validate global_symbol on all functions, not just Relax#18834
tqchen wants to merge 2 commits intoapache:mainfrom
tqchen:validate-global-symbol

Conversation

@tqchen
Copy link
Member

@tqchen tqchen commented Feb 26, 2026

This PR moves the CheckGlobalVarAndGsymbolConsistency check in the well-formed verifier to apply to all functions (not just Relax functions), fixing issue #17176.

Previously, only Relax functions were checked for consistency between GlobalVar name and global_symbol attribute. This meant TIR PrimFunc and other BaseFunc types could have mismatched names silently, causing subtle bugs.

Changes:

  • src/relax/analysis/well_formed.cc: Move consistency check outside the Relax-only branch; change parameter type from Function to BaseFunc
  • Fix 8 test files that had inconsistent global_symbol vs GlobalVar names

Based on #17203.

Move CheckGlobalVarAndGsymbolConsistency call outside the Relax-function-only
branch so it applies to all BaseFunc types (including TIR PrimFunc). Change
the method parameter type from Function to BaseFunc and use structured
bindings for the iteration loop.

Fix tests that had inconsistent global_symbol attributes vs GlobalVar names:
- test_tir_host_func.py: remove mismatched "global_symbol": "test" for main
- test_tir_intrin.py: remove mismatched "global_symbol": "test_fma" for test_tir_fma
- test_tir_transform_device_kernel_launch.py: fix kernel_by_another_name mismatch
- test_s_tir_transform_manifest_shared_memory_local_stage.py: remove mismatched "default_function" for main
@gemini-code-assist
Copy link
Contributor

Summary of Changes

Hello @tqchen, 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 enhances the robustness of the IRModule by enforcing consistent naming conventions across all function types. By broadening the scope of the GlobalVar and global_symbol consistency check, it proactively identifies and prevents potential issues that could arise from mismatched function identifiers, thereby improving the overall integrity and predictability of the intermediate representation.

Highlights

  • Expanded Consistency Check Scope: The CheckGlobalVarAndGsymbolConsistency check in the well-formed verifier has been extended to apply to all BaseFunc types, not just Relax functions.
  • Bug Fix for GlobalVar/global_symbol Mismatch: This change addresses issue [Relax][Bug] Cannot find PackedFunc tir_zeros #17176, preventing subtle bugs caused by silent mismatches between GlobalVar names and global_symbol attributes in TIR PrimFunc and other BaseFunc types.
  • Test File Updates: Eight test files were modified to correct inconsistencies between global_symbol attributes and GlobalVar names, aligning them with the new verification logic.

🧠 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
  • src/relax/analysis/well_formed.cc
    • Moved the CheckGlobalVarAndGsymbolConsistency call to apply to all BaseFunc types within an IRModule.
    • Updated the CheckGlobalVarAndGsymbolConsistency method signature to accept BaseFunc instead of Function.
  • tests/python/s_tir/transform/test_s_tir_transform_manifest_shared_memory_local_stage.py
    • Removed redundant global_symbol attributes from T.func_attr definitions in MatmulBefore and MatmulAfter classes.
  • tests/python/tir-base/test_tir_host_func.py
    • Removed global_symbol attribute from T.func_attr in the main function definition.
    • Modified IRModule creation to explicitly set the global_symbol attribute on the function.
    • Removed global_symbol attribute from the tir.transform.Apply pass.
  • tests/python/tir-base/test_tir_intrin.py
    • Removed the global_symbol attribute from the test_tir_fma function's T.func_attr.
  • tests/python/tir-transform/test_tir_transform_device_kernel_launch.py
    • Removed global_symbol attribute from T.func_attr in the kernel function.
    • Updated T.call_packed to use the default function name "kernel" instead of "kernel_by_another_name".
    • Modified the global_symbol attribute in the Expected class's kernel function to "kernel".
Activity
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
Contributor

@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 correctly extends the global_symbol consistency check to all function types in the well-formed verifier, not just Relax functions. This is a valuable improvement that prevents subtle bugs from mismatched names. The changes in src/relax/analysis/well_formed.cc are clean and effective. The accompanying test file updates correctly fix existing inconsistencies that the new check would flag. I have one minor suggestion for a small performance improvement in well_formed.cc.

@tqchen tqchen closed this Feb 26, 2026
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