Skip to content

Commit 82172ef

Browse files
authored
Added the dynamic check in the validator (#3790)
1 parent 01ef47a commit 82172ef

File tree

2 files changed

+12
-6
lines changed

2 files changed

+12
-6
lines changed

py/torch_tensorrt/dynamo/conversion/aten_ops_converters.py

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
get_positive_dim,
2626
is_only_operator_on_placeholder,
2727
)
28+
from torch_tensorrt.dynamo.utils import DYNAMIC_DIM
2829

2930
_LOGGER: logging.Logger = logging.getLogger(__name__)
3031

@@ -2758,9 +2759,18 @@ def sort_validator(node: Node, settings: Optional[CompilationSettings] = None) -
27582759

27592760

27602761
def topk_sort_validator(k: int) -> bool:
2762+
2763+
# topk layer supports dynamic k value but we cannot determine supported dynamic topk value at
2764+
# compile time.
2765+
if k == DYNAMIC_DIM or not isinstance(k, int):
2766+
_LOGGER.warning(
2767+
"[top_k validator] It's not expected for k to be a dynamic or data-dependent value. aten::topk will run in PyTorch"
2768+
)
2769+
return False
2770+
27612771
if k > 3840:
2762-
_LOGGER.debug(
2763-
f"Currently only topk values up to 3840 are supported, got k={k}."
2772+
_LOGGER.warning(
2773+
f"[top_k validator] Currently only topk values up to 3840 are supported, got k={k}. Therefore, aten::topk will run in PyTorch"
27642774
)
27652775
return False
27662776
return True

py/torch_tensorrt/dynamo/conversion/impl/topk.py

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -209,10 +209,6 @@ def topk(
209209
get_axes_for_reduce_op(get_positive_dim(dim, len(input.shape))),
210210
)
211211

212-
# topk layer supports dynamic k value but we cannot dertermin supported dynamic topk value at
213-
# compile time.
214-
assert k != DYNAMIC_DIM, "k value cannot be dynamic!"
215-
216212
# TensorRT ITopKLayer does not have a sorted flag, it is always returning the sorted topk elements
217213
# so here no matter sorted is True or False the returned the topk Tensor object is always sorted
218214
set_layer_name(topk_layer, target, f"{name}_topk", source_ir)

0 commit comments

Comments
 (0)