-
Notifications
You must be signed in to change notification settings - Fork 2.7k
[None][perf] Port tunable custom ops to fast_custom_op #18645
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
hyukn
wants to merge
2
commits into
NVIDIA:main
Choose a base branch
from
hyukn:perf/fast-custom-op-tunable-ops
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🎯 Functional Correctness | 🟠 Major | ⚡ Quick win
🔎 Supported by static analysis
🏁 Script executed:
Repository: NVIDIA/TensorRT-LLM
Length of output: 38361
🤖 get_repo_knowledge executed:
get_repo_knowledge NVIDIA/TensorRT-LLM /tmp/coderabbit-repo-knowledge/nvidia-tensorrt-llm-053b2761/learnings /tmp/coderabbit-repo-knowledge/nvidia-tensorrt-llm-053b2761/conventionsLength of output: 31351
🌐 Web query:
PyTorch 2.12 torch.library.custom_op device_types implementation _device_type_to_key uppercase CUDA💡 Result:
In PyTorch 2.12, the
torch.library.custom_opand associated registration APIs do not explicitly require or enforce uppercase "CUDA" when specifying device types [1][2]. Thedevice_typesargument intorch.library.custom_opandtorch.library.register_kernelaccepts lowercase strings such as"cpu"and"cuda"[1][2]. Internally, these device type strings are converted to the appropriate DispatchKey using the_device_type_to_keyfunction [2][3][4]. This function relies ontorch._C._dispatch_key_for_device(device_type)to resolve the device type string [3][4]. Historically, this resolution maps"cuda"to"CUDA"[5]. While some older or deprecated APIs (such as the legacyCustomOp.impl()) may have used hardcoded mappings or dictionaries (likeSUPPORTED_DEVICE_TYPE_TO_KEYwhere"cuda": "CUDA") that necessitated specific input casing [6][5], the standardtorch.libraryAPIs are designed to handle device type strings like"cuda"(lowercase) natively [1][2]. You should continue to use the standard lowercase"cuda"as documented [1][2].Citations:
🏁 Script executed:
Repository: NVIDIA/TensorRT-LLM
Length of output: 12300
🏁 Script executed:
Repository: NVIDIA/TensorRT-LLM
Length of output: 21989
🌐 Web query:
site:github.com/pytorch/pytorch "_dispatch_key_for_device(\"CUDA\")" OR "_dispatch_key_for_device" uppercase device type💡 Result:
The function torch._C._dispatch_key_for_device(device_type) is an internal PyTorch utility used to resolve a device string into its corresponding internal dispatch key string [1][2]. Regarding the device type case: 1. Consistency and Case Sensitivity: The internal implementation of _dispatch_key_for_device does not perform an explicit case-insensitive lookup on the input string to guarantee a specific output case; instead, it typically relies on the underlying c10::Device constructor [1]. However, in standard usage, the function is expected to handle standard device type identifiers correctly [2]. 2. Output Format: The function returns the dispatch key name as a string [1]. For standard backends, these names are uppercase (e.g., "CPU", "CUDA") [2][3]. 3. Usage Context: This function is primarily used within the PyTorch library to dynamically determine the appropriate dispatch key for a given device type, rather than hardcoding mappings (e.g., in custom operator registration or backend capability checks) [2][4][5]. Because this is a low-level internal API (torch._C), it is subject to change and is not intended for public application use [3][6]. If you are working with device dispatching, the recommended approach is to use the higher-level public APIs provided in torch.library or standard PyTorch device handling [7][8].
Citations:
🏁 Script executed:
Repository: NVIDIA/TensorRT-LLM
Length of output: 32901
🏁 Script executed:
Repository: NVIDIA/TensorRT-LLM
Length of output: 8057
Normalize
device_typesbefore validation-mode registration.When
TLLM_VALIDATE_CUSTOM_OPS=1, the default"CUDA"reachestorch.library.custom_op. PyTorch 2.12 accepts lowercase device types, so_dispatch_key_for_device("CUDA")raises during registration. Normalize"CUDA"to"cuda"before delegation and test both spellings.🤖 Prompt for AI Agents
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
+1
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@BowenFu, thanks for the confirmation. The finding remains open pending the normalization fix and test coverage.🐇 ✅
You are interacting with an AI system.