(dtype)
| 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) |
no test coverage detected