MCPcopy
hub / github.com/NVIDIA/TensorRT-LLM / conv1d

Function conv1d

tensorrt_llm/functional.py:3546–3583  ·  view source on GitHub ↗
(input: Tensor,
           weight: Tensor,
           bias: Optional[Tensor] = None,
           stride: int = 1,
           padding: int = 0,
           dilation: int = 1,
           groups: int = 1)

Source from the content-addressed store, hash-verified

3544
3545
3546def conv1d(input: Tensor,
3547 weight: Tensor,
3548 bias: Optional[Tensor] = None,
3549 stride: int = 1,
3550 padding: int = 0,
3551 dilation: int = 1,
3552 groups: int = 1) -> Tensor:
3553
3554 noutput = weight.size()[0]
3555 kernel_size = weight.size()[-2]
3556 is_weight_constant = (weight.producer is not None
3557 and weight.producer.type == trt.LayerType.CONSTANT)
3558 weight = weight.producer.weights if is_weight_constant else trt.Weights()
3559
3560 if bias is not None:
3561 is_bias_constant = (bias.producer is not None
3562 and bias.producer.type == trt.LayerType.CONSTANT)
3563 bias = bias.producer.weights if is_bias_constant else trt.Weights()
3564
3565 input_shuffled = stack([input], dim=input.ndim())
3566 kernel_size = trt.Dims([kernel_size, 1])
3567
3568 layer = default_trtnet().add_convolution_nd(input_shuffled.trt_tensor,
3569 noutput, kernel_size, weight,
3570 bias)
3571 layer.stride_nd = (stride, 2)
3572 layer.padding_nd = (padding, 0)
3573 layer.dilation_nd = (dilation, 2)
3574 layer.num_groups = groups
3575
3576 if not is_weight_constant:
3577 layer.set_input(1, weight.trt_tensor)
3578 if bias is not None and not is_bias_constant:
3579 layer.set_input(2, bias.trt_tensor)
3580
3581 output_2d = _create_tensor(layer.get_output(0), layer)
3582 output_1d = squeeze(output_2d, dim=-1)
3583 return output_1d
3584
3585
3586def conv2d(input: Tensor,

Callers 1

forwardMethod · 0.85

Calls 7

stackFunction · 0.85
default_trtnetFunction · 0.85
_create_tensorFunction · 0.85
squeezeFunction · 0.85
sizeMethod · 0.45
ndimMethod · 0.45
get_outputMethod · 0.45

Tested by

no test coverage detected