Skip to content

[REFACTOR][TARGET] Further cleanup target python api#18793

Merged
tqchen merged 1 commit intoapache:mainfrom
tqchen:target-cleanup
Feb 18, 2026
Merged

[REFACTOR][TARGET] Further cleanup target python api#18793
tqchen merged 1 commit intoapache:mainfrom
tqchen:target-cleanup

Conversation

@tqchen
Copy link
Member

@tqchen tqchen commented Feb 17, 2026

This PR cleans up the target python api.

  • Removes the indirections of attribute exposure
  • Move tag registry to python so it is easily configurable
  • Remove legacy constructors in favor of tags

@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 introduces a substantial refactoring of the TVM target Python API, aiming to enhance consistency, configurability, and maintainability. The core changes involve standardizing target attribute access through a dictionary-like interface, deprecating older, specialized target constructors in favor of a unified Target() constructor, and migrating target tag definitions to Python. These updates simplify the process of defining and managing hardware targets within TVM, making the API more robust and easier to extend for new devices.

Highlights

  • Target API Refactor: The tvm.target Python API has been significantly refactored to remove direct attribute accessors (e.g., target.arch, target.libs) in favor of accessing attributes via target.attrs["key"]. This change promotes a more consistent and flexible way to interact with target properties.
  • Legacy Constructor Deprecation: Legacy target constructor functions like tvm.target.cuda() and tvm.target.hexagon() have been deprecated. Users are now encouraged to use the unified tvm.target.Target() constructor with JSON configuration dictionaries or predefined tag names for target creation.
  • Python-based Target Tag Registry: Target tag definitions have been moved from C++ to a new Python-based tvm/target/tag_registry package. This change centralizes tag management in Python, making it easier to configure, extend, and maintain target definitions for various hardware platforms (e.g., CUDA, ARM CPU, Hexagon, Adreno, Metal, RISC-V, AWS CPU).
  • Simplified Target Canonicalization: Several static methods related to target canonicalization, such as Target.canon_target and Target.canon_multi_target, have been removed. The tvm.target.Target() constructor now handles canonicalization directly, streamlining target object creation.

🧠 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
  • python/tvm/contrib/hexagon/pytest_plugin.py
    • Updated Hexagon target creation to use the new tvm.target.Target dictionary-based constructor.
  • python/tvm/contrib/nvcc.py
    • Modified target architecture access from target.arch to target.attrs.get("arch", "").
  • python/tvm/contrib/thrust.py
    • Updated target.libs access to list(target.attrs.get("libs", [])) for consistency.
  • python/tvm/relax/frontend/nn/llm/kv_cache.py
    • Changed target.max_num_threads access to int(target.attrs["max_num_threads"]).
  • python/tvm/relax/frontend/torch/dynamo.py
    • Replaced tvm.target.cuda() with tvm.target.Target("cuda").
  • python/tvm/s_tir/dlight/gpu/gemv.py
    • Updated access to max_shared_memory_per_block and max_num_threads to use target.attrs.
  • python/tvm/s_tir/dlight/gpu/low_batch_gemv.py
    • Updated access to max_shared_memory_per_block and max_num_threads to use target.attrs.
  • python/tvm/s_tir/dlight/gpu/matmul.py
    • Modified target architecture access from target.arch to str(target.attrs.get("arch", "")).
  • python/tvm/s_tir/meta_schedule/schedule/cuda/layout_transform.py
    • Updated thread_warp_size access to use target.attrs and in operator for checking existence.
  • python/tvm/target/init.py
    • Removed direct target creation functions (e.g., cuda, rocm, hexagon).
    • Updated module docstring to reflect JSON-based target configuration and tag usage.
    • Imported tag_registry for Python-side tag definitions.
  • python/tvm/target/compilation_config.py
    • Removed the file, its functionality was either deprecated or moved.
  • python/tvm/target/tag.py
    • Renamed to python/tvm/target/tag_registry/__init__.py.
    • Simplified content to re-export list_tags and register_tag from registry.py.
  • python/tvm/target/tag_registry/init.py
    • Added new file to serve as the Python-side target tag registry entry point.
    • Imports various tag definition files (e.g., cuda, arm_cpu, hexagon).
  • python/tvm/target/tag_registry/adreno.py
    • Added new file to define Qualcomm Adreno GPU target tags.
  • python/tvm/target/tag_registry/arm_cpu.py
    • Added new file to define ARM CPU target tags.
  • python/tvm/target/tag_registry/aws_cpu.py
    • Added new file to define AWS CPU instance target tags.
  • python/tvm/target/tag_registry/cuda.py
    • Added new file to define NVIDIA CUDA target tags.
  • python/tvm/target/tag_registry/hexagon.py
    • Added new file to define Qualcomm Hexagon target tags.
  • python/tvm/target/tag_registry/metal.py
    • Added new file to define Apple Metal GPU target tags.
  • python/tvm/target/tag_registry/registry.py
    • Added new file containing the core list_tags and register_tag functions for the Python tag registry.
  • python/tvm/target/tag_registry/riscv_cpu.py
    • Added new file to define RISC-V CPU target tags.
  • python/tvm/target/target.py
    • Removed direct attribute properties (e.g., arch, max_num_threads, libs) from the Target class.
    • Removed static canonicalization methods like canon_target and canon_multi_target.
    • Updated the class docstring to reflect the new JSON-based and tag-based target construction.
  • python/tvm/tir/build.py
    • Replaced Target.canon_target() calls with direct Target() constructor calls.
  • python/tvm/topi/gpu/scan.py
    • Updated max_num_threads access to use target.attrs["max_num_threads"].
  • python/tvm/topi/gpu/sort.py
    • Updated max_threads access to use target.attrs["max_num_threads"].
  • python/tvm/topi/math.py
    • Modified target.device_name access to str(target.attrs.get("device", "")).
  • src/target/tag.cc
    • Removed C++ TVM_REGISTER_TARGET_TAG macros, shifting tag registration to Python.
  • tests/python/codegen/test_target_codegen_cuda.py
    • Updated tvm.target.cuda() calls to tvm.target.Target("cuda").
  • tests/python/codegen/test_target_codegen_hexagon.py
    • Updated Hexagon target creation to use tvm.target.Target with tag names or dictionary configurations.
  • tests/python/contrib/test_hexagon/infrastructure.py
    • Introduced _make_hexagon_target to construct Hexagon targets using dictionary configurations, replacing direct tvm.target.hexagon calls.
  • tests/python/contrib/test_hexagon/test_async_dma_pipeline.py
    • Updated Hexagon target creation to use tvm.target.Target("qcom/hexagon-v68").
  • tests/python/contrib/test_hexagon/test_dma_builtin.py
    • Updated Hexagon target creation to use tvm.target.Target("qcom/hexagon-v69").
  • tests/python/contrib/test_hexagon/test_relax_2d_buffer_allocation.py
    • Updated Hexagon target creation to use tvm.target.Target with a dictionary configuration.
  • tests/python/contrib/test_hexagon/test_relax_integration.py
    • Updated Hexagon target creation to use tvm.target.Target("qcom/hexagon-v68").
  • tests/python/relax/backend/clml/utils.py
    • Updated Adreno target creation to use tvm.target.Target with dictionary configurations.
  • tests/python/relax/texture/adreno_utils.py
    • Updated Adreno target creation to use tvm.target.Target with dictionary configurations.
  • tests/python/s_tir/meta_schedule/test_meta_schedule_postproc_verify_vtcm_limit.py
    • Updated Hexagon target creation to use tvm.target.Target with a dictionary configuration.
  • tests/python/s_tir/meta_schedule/test_meta_schedule_schedule_rule_mlt.py
    • Removed tvm.target import and updated Hexagon target creation to use Target("qcom/hexagon-v69").
  • tests/python/target/test_target_target.py
    • Removed imports of legacy target constructor functions (e.g., cuda, rocm).
    • Updated assertions to use target.attrs.get("key", default) instead of direct attribute access.
    • Removed tests for deprecated canon_target and related methods.
  • tests/python/target/test_x86_features.py
    • Updated mcpu and mattr access to use target.attrs.get("key", "") or list(target.attrs.get("key", [])).
Activity
  • The pull request introduces a comprehensive refactoring of the tvm.target Python API.
  • It deprecates legacy target constructor functions and direct attribute accessors.
  • A new Python-based target tag registry has been implemented, with tag definitions moved from C++ to Python files.
  • Numerous internal and test files have been updated to align with the new API design, using tvm.target.Target() with dictionary configurations or tag names.
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 is a significant and welcome refactoring of the tvm.target Python API. It cleans up the API by removing legacy constructors and direct attribute access in favor of a more consistent dictionary-based configuration and tag system. Moving the tag registry to Python makes it much more extensible. The changes are applied consistently across the codebase, including tests. I've found a couple of minor potential issues where target attributes might have been unintentionally dropped during the refactoring, which I've commented on. Overall, this is a great improvement for the TVM Target API.

This PR cleans up the target python api.

- Removes the indirections of attribute exposure
- Move tag registry to python so it is easily configurable
- Remove legacy constructors in favor of tags
@tqchen
Copy link
Member Author

tqchen commented Feb 18, 2026

@tvm-bot rerun

@tqchen tqchen merged commit 283fd19 into apache:main Feb 18, 2026
10 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

Comments