TensorRT-LLMs/tests/functional/test_repeat_interleave.py
Kaiyu Xie 250d9c293d
Update TensorRT-LLM Release branch (#1445)
* Update TensorRT-LLM

---------

Co-authored-by: Bhuvanesh Sridharan <bhuvan.sridharan@gmail.com>
Co-authored-by: Morgan Funtowicz <funtowiczmo@gmail.com>
Co-authored-by: Eddie-Wang1120 <wangjinheng1120@163.com>
Co-authored-by: meghagarwal <16129366+megha95@users.noreply.github.com>
2024-04-12 17:59:19 +08:00

49 lines
1.5 KiB
Python

import os
import sys
import unittest
import numpy as np
import torch
from parameterized import parameterized
from polygraphy.backend.trt import EngineFromNetwork, TrtRunner
import tensorrt_llm
from tensorrt_llm import Tensor
sys.path.append(os.path.join(os.path.dirname(__file__), '..'))
from utils.util import unittest_name_func
class TestFunctional(unittest.TestCase):
def setUp(self):
tensorrt_llm.logger.set_level('error')
@parameterized.expand([[0], [1], [2]], name_func=unittest_name_func)
def test_repeat_interleave(self, axis):
dtype = 'float32'
repeats = 3
x_data = torch.randn(
(2, 3, 4), dtype=tensorrt_llm._utils.str_dtype_to_torch(dtype))
builder = tensorrt_llm.Builder()
net = builder.create_network()
with tensorrt_llm.net_guard(net):
network = tensorrt_llm.default_trtnet()
x = Tensor(name='x',
shape=x_data.shape,
dtype=tensorrt_llm.str_dtype_to_trt(dtype))
output = tensorrt_llm.functional.repeat_interleave(
x, repeats, axis).trt_tensor
output.name = 'output'
network.mark_output(output)
build_engine = EngineFromNetwork((builder.trt_builder, net.trt_network))
with TrtRunner(build_engine) as runner:
outputs = runner.infer(feed_dict={
'x': x_data.numpy(),
})
ref = torch.repeat_interleave(x_data, repeats, axis)
np.testing.assert_allclose(ref, outputs['output'])