Skip to content
Closed
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
18 changes: 10 additions & 8 deletions torch/fx/experimental/fx2trt/converters/acc_ops_converters.py
Original file line number Diff line number Diff line change
Expand Up @@ -1408,9 +1408,7 @@ def acc_ops_sigmoid(network, target, args, kwargs, name):
"of the TensorRT region!"
)

layer = network.add_activation(input=input_val, type=trt.ActivationType.SIGMOID)
set_layer_name(layer, target, name)
return layer.get_output(0)
return add_activation_layer(network, input_val, trt.ActivationType.SIGMOID, target, name)


@tensorrt_converter(acc_ops.permute)
Expand Down Expand Up @@ -1687,8 +1685,12 @@ def acc_ops_hardtanh(network, target, args, kwargs, name):
raise RuntimeError(f"hardtanh received input {input_val} that is not part "
"of the TensorRT region!")

layer = network.add_activation(input_val, trt.ActivationType.CLIP)
layer.alpha = kwargs["min_val"]
layer.beta = kwargs["max_val"]
set_layer_name(layer, target, name)
return layer.get_output(0)
return add_activation_layer(
network,
input_val,
trt.ActivationType.CLIP,
target,
name,
alpha=kwargs["min_val"],
beta=kwargs["max_val"],
)
11 changes: 11 additions & 0 deletions torch/fx/experimental/fx2trt/converters/converter_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -314,6 +314,7 @@ def broadcast(

return a, b


def add_binary_elementwise_layer(
network: trt.INetworkDefinition,
lhs_val: Union[int, float, trt.tensorrt.ITensor, torch.Tensor],
Expand Down Expand Up @@ -413,6 +414,8 @@ def add_activation_layer(
operation_type: trt.ActivationType,
target: Target,
name: str,
alpha: Optional[Any] = None,
beta: Optional[Any] = None,
) -> trt.tensorrt.ITensor:
"""
Add a TensorRT Activation layer to `network`.
Expand All @@ -425,6 +428,10 @@ def add_activation_layer(
operation.
target (Target): Target of fx node.
name (str): The name we want to assign to the created TensorRT layer.
alpha (Optional[Any]): If not None, we will use it to set the alpha
attribute of the created TensorRT activation layer.
beta (Optional[Any]): If not None, we will use it to set the beta
attribute of the created TensorRT activation layer.

Returns:
The output of TensorRT Activation layer.
Expand All @@ -435,6 +442,10 @@ def add_activation_layer(
"of the TensorRT region!"
)
layer = network.add_activation(input_val, operation_type)
if alpha:
layer.alpha = alpha
if beta:
layer.beta = beta
set_layer_name(layer, target, name)
return layer.get_output(0)

Expand Down