-
Notifications
You must be signed in to change notification settings - Fork 74
Use toPolymorphicValue to convert py::handle directly to PolymorphicValue
#5771
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
base: main
Are you sure you want to change the base?
Conversation
|
!test |
Description
|
| Relevant files | |||
|---|---|---|---|
| Enhancement |
|
PR Reviewer Guide
Here are some key observations to aid the review process:
| 🧪 PR contains tests |
| ⚡ Recommended focus areas for review |
Type Coverage Gap
toPolymorphicValue function only handles 5 specific types (Tensor, bool, int64_t, double, complex), while torch::jit::toIValue may support additional types. This could break existing functionality if users pass unsupported types that were previously handled by the PyTorch function. |
Test failures
-
(High, 1)
NVFuser multi-device CUDA system-not-ready error in LowerCollectiveCudaAndNcclTestTest Name GB200 (dist.) Source LowerCollectiveCudaAndNcclTest.Broadcast/memcpy_2MB ❌ Link -
(Medium, 3)
NVFuser internal assert on mismatched-input-type check (test_python_direct.test_mismatched_input_types)Test Name A100 GB200 H100 Source tests.python.direct.test_python_direct.test_mismatched_input_types ❌ ❌ ❌
Greptile SummaryReplaced
Confidence Score: 5/5
Important Files Changed
Sequence DiagramsequenceDiagram
participant Python as Python Code
participant Direct as from_pyiterable
participant New as toPolymorphicValue
participant KAH as KernelArgumentHolder
Note over Python,KAH: Before (using torch::jit::toIValue)
Python->>Direct: py::iterable with py::handle objects
Direct->>Direct: torch::jit::toIValue(obj)
Direct->>Direct: IValue returned
Direct->>KAH: args.push(IValue)
KAH->>KAH: IValueToPolymorphicValue
KAH->>KAH: Store PolymorphicValue
Note over Python,KAH: After (direct conversion)
Python->>Direct: py::iterable with py::handle objects
Direct->>New: toPolymorphicValue(obj)
New->>New: Check type (Tensor/bool/int/float/complex)
New->>New: Cast to appropriate C++ type
New->>Direct: Return PolymorphicValue
Direct->>KAH: args.push(PolymorphicValue)
KAH->>KAH: Store PolymorphicValue
|
torch::jit::toIValueconverts frompy::handletoIValue. ThenKernelArgumentHolderconvertsIValuetoPolymorphicValue. The PyTorch function handles several types, beyond what NvFuser supports, resulting in unnecessary latency.toPolymorphicValueconvertspy::handledirectly toPolymorphicValueto save latency.nanobind.tests/python/direct/test_python_frontend.py
toPolymorphicValuetorch::jit::toIValueAll python tests --- 7% improvement
toPolymorphicValuetorch::jit::toIValue