|
1 | 1 | # mypy: disallow-untyped-decorators=False |
2 | 2 |
|
3 | 3 | import logging |
4 | | -from typing import Dict, Sequence, Tuple, Union |
| 4 | +from typing import Dict, Optional, Sequence, Tuple, Union |
5 | 5 |
|
6 | 6 | import tensorrt as trt |
7 | | -from torch.fx.node import Argument, Target |
| 7 | +from torch.fx.node import Argument, Node, Target |
8 | 8 | from torch_tensorrt._features import ENABLED_FEATURES |
| 9 | +from torch_tensorrt.dynamo._settings import CompilationSettings |
9 | 10 | from torch_tensorrt.dynamo._SourceIR import SourceIR |
10 | 11 | from torch_tensorrt.dynamo.conversion import impl |
11 | 12 | from torch_tensorrt.dynamo.conversion._ConversionContext import ConversionContext |
12 | 13 | from torch_tensorrt.dynamo.conversion._ConverterRegistry import ( |
13 | 14 | dynamo_tensorrt_converter, |
14 | 15 | ) |
| 16 | +from torch_tensorrt.dynamo.conversion.aten_ops_converters import ( |
| 17 | + turing_rejects_forward_convolution, |
| 18 | +) |
| 19 | +from torch_tensorrt.dynamo.conversion.converter_utils import args_bounds_check |
15 | 20 | from torch_tensorrt.dynamo.lowering.passes.fuse_distributed_ops import ( |
16 | 21 | tensorrt_fused_nccl_all_gather_op, |
17 | 22 | tensorrt_fused_nccl_all_reduce_op, |
|
27 | 32 | _LOGGER: logging.Logger = logging.getLogger(__name__) |
28 | 33 |
|
29 | 34 |
|
30 | | -@dynamo_tensorrt_converter(tensorrt_conv_asym_pad_op, supports_dynamic_shapes=True) |
| 35 | +def conv_asym_pad_capability_validator( |
| 36 | + node: Node, settings: Optional[CompilationSettings] = None |
| 37 | +) -> bool: |
| 38 | + """Apply the aten.convolution capability guards to the fused pad+conv op. |
| 39 | +
|
| 40 | + ``fuse_pad_into_convolution`` rewrites constant_pad_nd -> aten.convolution into |
| 41 | + this op during lowering, which erases the aten.convolution node that |
| 42 | + ``convolution_capability_validator`` would otherwise have rejected. Without this, |
| 43 | + the pass smuggles a 3D convolution past that guard onto Turing (SM 7.5), where it |
| 44 | + surfaces at runtime as a null execution context. The pass runs in the normal |
| 45 | + compile path, so this is not confined to tests. |
| 46 | +
|
| 47 | + Spatial rank comes from the argument list rather than node meta, so the guard holds |
| 48 | + whether or not the caller traced with dynamo. |
| 49 | + """ |
| 50 | + # conv_asym_pad(source, weight, bias, stride, pre_padding, post_padding, dilation, |
| 51 | + # groups) -- no transposed argument; the pass skips those outright. |
| 52 | + _ARG_STRIDE = 3 |
| 53 | + stride = args_bounds_check(node.args, _ARG_STRIDE) |
| 54 | + spatial_rank = len(stride) if stride is not None else None |
| 55 | + return not turing_rejects_forward_convolution(node, spatial_rank, settings) |
| 56 | + |
| 57 | + |
| 58 | +@dynamo_tensorrt_converter( |
| 59 | + tensorrt_conv_asym_pad_op, |
| 60 | + capability_validator=conv_asym_pad_capability_validator, |
| 61 | + supports_dynamic_shapes=True, |
| 62 | +) |
31 | 63 | def conv_asym_pad( |
32 | 64 | ctx: ConversionContext, |
33 | 65 | target: Target, |
|
0 commit comments