MCPcopy Create free account
hub / github.com/NVIDIA/TensorRT-LLM / test

Function test

examples/python_plugin/build_lookup.py:23–57  ·  view source on GitHub ↗
(dtype)

Source from the content-addressed store, hash-verified

21 dtype=torch.int32).cuda()
22
23 def test(dtype):
24 builder = tensorrt_llm.Builder()
25 builder.strongly_typed = True
26 network = builder.create_network()
27 with tensorrt_llm.net_guard(network):
28 x = Tensor(
29 name="x",
30 shape=index_shape,
31 dtype=tensorrt_llm.str_dtype_to_trt("int32"),
32 )
33 y = Tensor(name="y",
34 shape=(vocab_size, n_embed),
35 dtype=torch_dtype_to_trt(dtype))
36
37 def lookup(x, y):
38 lookup_plugin = LookUpPlugin(False, True)
39 return lookup_plugin(x, y)
40
41 output = lookup(x, y)
42
43 output.mark_output("output", torch_dtype_to_str(torch.float32))
44
45 builder_config = builder.create_builder_config("float32")
46 engine = builder.build_engine(network, builder_config)
47 assert engine is not None
48
49 output_dir = Path("tmp") / torch_dtype_to_str(dtype)
50 output_dir.mkdir(parents=True, exist_ok=True)
51
52 engine_path = output_dir / "lookup.engine"
53 config_path = output_dir / "config.json"
54
55 with engine_path.open("wb") as f:
56 f.write(engine)
57 builder.save_config(builder_config, str(config_path))
58
59 test(torch.bfloat16)
60 test(torch.float16)

Callers 1

build_lookup.pyFile · 0.70

Calls 9

create_networkMethod · 0.95
create_builder_configMethod · 0.95
build_engineMethod · 0.95
save_configMethod · 0.95
TensorClass · 0.90
torch_dtype_to_trtFunction · 0.90
torch_dtype_to_strFunction · 0.90
mark_outputMethod · 0.80
lookupFunction · 0.70

Tested by

no test coverage detected