You are viewing a plain text version of this content. The canonical link for it is here.
Posted to discuss-archive@tvm.apache.org by "tqchen (via GitHub)" <gi...@apache.org> on 2026/02/17 22:07:13 UTC
[PR] [REFACTOR][TARGET] Further cleanup target python api [tvm]
tqchen opened a new pull request, #18793:
URL: https://github.com/apache/tvm/pull/18793
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
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: discuss-archive-unsubscribe@tvm.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: discuss-archive-unsubscribe@tvm.apache.org
For additional commands, e-mail: discuss-archive-help@tvm.apache.org
Re: [PR] [REFACTOR][TARGET] Further cleanup target python api [tvm]
Posted by "gemini-code-assist[bot] (via GitHub)" <gi...@apache.org>.
gemini-code-assist[bot] commented on code in PR #18793:
URL: https://github.com/apache/tvm/pull/18793#discussion_r2819316403
##########
tests/python/contrib/test_hexagon/test_async_dma_pipeline.py:
##########
@@ -269,7 +269,7 @@ def evaluate(
use_async_copy=0,
):
"""Evaluate function."""
- target_hexagon = tvm.target.hexagon("v68", link_params=True)
+ target_hexagon = tvm.target.Target("qcom/hexagon-v68")
Review Comment:

The `link_params=True` option was dropped in this change. This might affect the test's behavior as it controls whether parameters are linked into the binary. If this option is still required, you could construct the target from a dictionary that includes the tag and the `link-params` option to preserve it.
```suggestion
target_hexagon = tvm.target.Target({"tag": "qcom/hexagon-v68", "link-params": True})
```
##########
tests/python/relax/backend/clml/utils.py:
##########
@@ -92,7 +92,9 @@ def run_compare(mod, inputs, params_np):
ref = build_and_run(
mod,
inputs,
- tvm.target.adreno(),
+ tvm.target.Target(
+ {"kind": "opencl", "device": "adreno", "keys": ["adreno", "opencl", "gpu"]}
Review Comment:

The previous `tvm.target.adreno()` constructor included `model="unknown"` by default. This attribute seems to have been dropped in the refactoring. To maintain consistency, it might be good to add it back to the target configuration dictionary.
```suggestion
{"kind": "opencl", "device": "adreno", "keys": ["adreno", "opencl", "gpu"], "model": "unknown"}
```
##########
tests/python/relax/texture/adreno_utils.py:
##########
@@ -36,9 +36,11 @@ def get_target(backend, is_adreno=False):
tvm.target.Target
The target for the Adreno GPU.
"""
- target = tvm.target.adreno(backend=backend)
+ keys = ["adreno", backend, "gpu"]
+ target = tvm.target.Target({"kind": backend, "device": "adreno", "keys": keys})
Review Comment:

The previous `tvm.target.adreno()` constructor included `model="unknown"` by default. This attribute seems to have been dropped in the refactoring. To maintain consistency, it might be good to add it back to the target configuration dictionary.
```suggestion
target = tvm.target.Target({"kind": backend, "device": "adreno", "keys": keys, "model": "unknown"})
```
##########
tests/python/relax/backend/clml/utils.py:
##########
@@ -101,7 +103,9 @@ def run_compare(mod, inputs, params_np):
out = build_and_run(
clml_mod,
inputs,
- tvm.target.adreno(cfg="clml"),
+ tvm.target.Target(
+ {"kind": "opencl", "device": "adreno", "keys": ["adreno", "opencl", "gpu", "clml"]}
Review Comment:

The previous `tvm.target.adreno()` constructor included `model="unknown"` by default. This attribute seems to have been dropped in the refactoring. To maintain consistency, it might be good to add it back to the target configuration dictionary.
```suggestion
{"kind": "opencl", "device": "adreno", "keys": ["adreno", "opencl", "gpu", "clml"], "model": "unknown"}
```
##########
tests/python/relax/texture/adreno_utils.py:
##########
@@ -36,9 +36,11 @@ def get_target(backend, is_adreno=False):
tvm.target.Target
The target for the Adreno GPU.
"""
- target = tvm.target.adreno(backend=backend)
+ keys = ["adreno", backend, "gpu"]
+ target = tvm.target.Target({"kind": backend, "device": "adreno", "keys": keys})
if is_adreno:
- target = tvm.target.adreno(cfg="texture", backend=backend)
+ keys_tex = ["adreno", backend, "gpu", "texture"]
+ target = tvm.target.Target({"kind": backend, "device": "adreno", "keys": keys_tex})
Review Comment:

The previous `tvm.target.adreno()` constructor included `model="unknown"` by default. This attribute seems to have been dropped in the refactoring. To maintain consistency, it might be good to add it back to the target configuration dictionary.
```suggestion
target = tvm.target.Target({"kind": backend, "device": "adreno", "keys": keys_tex, "model": "unknown"})
```
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: discuss-archive-unsubscribe@tvm.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: discuss-archive-unsubscribe@tvm.apache.org
For additional commands, e-mail: discuss-archive-help@tvm.apache.org
Re: [PR] [REFACTOR][TARGET] Further cleanup target python api [tvm]
Posted by "gemini-code-assist[bot] (via GitHub)" <gi...@apache.org>.
gemini-code-assist[bot] commented on PR #18793:
URL: https://github.com/apache/tvm/pull/18793#issuecomment-3917324923
## Summary of Changes
Hello @tqchen, I'm Gemini Code Assist[^1]! 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](https://codeassist.google/code-review/login) to enable Memory in your admin console.**
<details>
<summary><b>Changelog</b></summary>
* **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", []))`.
</details>
<details>
<summary><b>Activity</b></summary>
* 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.
</details>
<details>
<summary><b>Using Gemini Code Assist</b></summary>
<br>
The full guide for Gemini Code Assist can be found on our [documentation page](https://developers.google.com/gemini-code-assist/docs/review-github-code), here are some quick tips.
<b>Invoking Gemini</b>
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.
<b>Customization</b>
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](https://developers.google.com/gemini-code-assist/docs/customize-gemini-behavior-github).
<b>Limitations & Feedback</b>
Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with :thumbsup: and :thumbsdown: 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](https://google.qualtrics.com/jfe/form/SV_2cyuGuTWsEw84yG).
<b>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](https://cloud.google.com/products/gemini/code-assist).</b>
</details>
[^1]: Review the [Privacy Notices](https://policies.google.com/privacy), [Generative AI Prohibited Use Policy](https://policies.google.com/terms/generative-ai/use-policy), [Terms of Service](https://policies.google.com/terms), and learn how to configure Gemini Code Assist in GitHub [here](https://developers.google.com/gemini-code-assist/docs/customize-gemini-behavior-github). Gemini can make mistakes, so double check it and [use code with caution](https://support.google.com/legal/answer/13505487).
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: discuss-archive-unsubscribe@tvm.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: discuss-archive-unsubscribe@tvm.apache.org
For additional commands, e-mail: discuss-archive-help@tvm.apache.org
Re: [PR] [REFACTOR][TARGET] Further cleanup target python api [tvm]
Posted by "tqchen (via GitHub)" <gi...@apache.org>.
tqchen merged PR #18793:
URL: https://github.com/apache/tvm/pull/18793
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: discuss-archive-unsubscribe@tvm.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: discuss-archive-unsubscribe@tvm.apache.org
For additional commands, e-mail: discuss-archive-help@tvm.apache.org
Re: [PR] [REFACTOR][TARGET] Further cleanup target python api [tvm]
Posted by "tqchen (via GitHub)" <gi...@apache.org>.
tqchen commented on PR #18793:
URL: https://github.com/apache/tvm/pull/18793#issuecomment-3917745920
@tvm-bot rerun
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: discuss-archive-unsubscribe@tvm.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: discuss-archive-unsubscribe@tvm.apache.org
For additional commands, e-mail: discuss-archive-help@tvm.apache.org