Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 14 additions & 2 deletions py/torch_tensorrt/dynamo/conversion/aten_ops_converters.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
get_positive_dim,
is_only_operator_on_placeholder,
)
from torch_tensorrt.dynamo.utils import DYNAMIC_DIM

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

Expand Down Expand Up @@ -2694,9 +2695,18 @@ def sort_validator(node: Node, settings: Optional[CompilationSettings] = None) -


def topk_sort_validator(k: int) -> bool:

# topk layer supports dynamic k value but we cannot determine supported dynamic topk value at
# compile time.
if k == DYNAMIC_DIM:
_LOGGER.debug(
"[top_k validator] Converter does not support k being a dynamic value. Therefore, aten::topk will run in PyTorch"
)
return False

if k > 3840:
_LOGGER.debug(
f"Currently only topk values up to 3840 are supported, got k={k}."
f"[top_k validator] Currently only topk values up to 3840 are supported, got k={k}. Therefore, aten::topk will run in PyTorch"
)
return False
return True
Expand Down Expand Up @@ -3160,7 +3170,9 @@ def aten_ops_upsample_bicubic2d(


@dynamo_tensorrt_converter(
torch.ops.aten.topk.default, capability_validator=topk_validator
torch.ops.aten.topk.default,
capability_validator=topk_validator,
supports_dynamic_shapes=True,
)
@enforce_tensor_types(
{
Expand Down
4 changes: 0 additions & 4 deletions py/torch_tensorrt/dynamo/conversion/impl/topk.py
Original file line number Diff line number Diff line change
Expand Up @@ -209,10 +209,6 @@ def topk(
get_axes_for_reduce_op(get_positive_dim(dim, len(input.shape))),
)

# topk layer supports dynamic k value but we cannot dertermin supported dynamic topk value at
# compile time.
assert k != DYNAMIC_DIM, "k value cannot be dynamic!"

# TensorRT ITopKLayer does not have a sorted flag, it is always returning the sorted topk elements
# so here no matter sorted is True or False the returned the topk Tensor object is always sorted
set_layer_name(topk_layer, target, f"{name}_topk", source_ir)
Expand Down
Loading