Extend static analysis for arithmetic operators - #6476
Conversation
Signed-off-by: Rostan Tabet <rtabet@nvidia.com>
Signed-off-by: Rostan Tabet <rtabet@nvidia.com>
Signed-off-by: Rostan Tabet <rtabet@nvidia.com>
Signed-off-by: Rostan Tabet <rtabet@nvidia.com>
Signed-off-by: Rostan Tabet <rtabet@nvidia.com>
|
!build |
|
CI MESSAGE: [66962570]: BUILD STARTED |
Signed-off-by: Rostan Tabet <rtabet@nvidia.com>
94b76d7 to
e28c90a
Compare
|
!build |
|
CI MESSAGE: [66975775]: BUILD STARTED |
|
CI MESSAGE: [66975775]: BUILD PASSED |
|
CI MESSAGE: [66962570]: BUILD PASSED |
|
|
||
| # only reachable from math functions called with only scalars, e.g. ndd.math.max(2, 3) | ||
| if not tensor_args: | ||
| args = [to_input(arg) for arg in args] |
There was a problem hiding this comment.
[Minor] This unconditionally converts every scalar argument to a Tensor when there are no Tensor/Batch operands at all — which, per the comment above, is exactly the ndd.math.max(2, 3)-style call this PR's constant-promotion feature is meant to help. After this loop runs, every arg has become a Tensor, so the any(type(arg) in (bool, int, float) ...) check below is always False here and none of these arguments can be promoted to integer_constants/real_constants — the whole point of this PR is bypassed for the pure-scalar call path.
The reason for this branch is presumably .NumInput(1, 64) on the underlying op (verified in arithmetic.cc:146) requiring at least one real tensor input, which tensor_args can't guarantee when it's empty. But that only requires one of the arguments to stay a Tensor, not all of them — e.g. converting just args[0] before running constant classification on the rest would satisfy NumInput(1, 64) while still letting the remaining scalars take the $N path.
Category:
New feature (non-breaking change which adds functionality)
Description:
This extends dynamic mode static analysis to support arithmetic operators.
PR #6475 promotes bools, ints, and floats to constants in arithmetic ops. With this PR, we can limit it to only those that are provably constant.
To prevent a regression on Python 3.10 when a call is on the same line as an arithmetic operation, we also add disambiguation on the bytecode since exact span checking is absent.
Additional information:
Affected modules and functionalities:
Dynamic mode.
Key points relevant for the review:
Commits a677329 and 0374268 belong to #6475.
Tests:
test_arithm_ops.pyChecklist
Documentation
DALI team only
Requirements
REQ IDs: N/A
JIRA TASK: N/A