MCPcopy Create free account
hub / github.com/NVIDIA/FasterTransformer / build_engine

Function build_engine

examples/tensorrt/swin/builder.py:262–294  ·  view source on GitHub ↗
(config, args, weights_dict)

Source from the content-addressed store, hash-verified

260
261
262def build_engine(config, args, weights_dict):
263 explicit_batch_flag = 1 << int(trt.NetworkDefinitionCreationFlag.EXPLICIT_BATCH)
264
265 with trt.Builder(TRT_LOGGER) as builder, builder.create_network(explicit_batch_flag) as network, builder.create_builder_config() as builder_config:
266 builder_config.max_workspace_size = 8 << 30
267 if args.fp16:
268 builder_config.set_flag(trt.BuilderFlag.FP16)
269 builder_config.set_flag(trt.BuilderFlag.STRICT_TYPES)
270 trt_dtype = trt.float16
271 else:
272 trt_dtype = trt.float32
273
274 # Create the network
275 input_img = network.add_input(name="input_img", dtype=trt_dtype, shape=(-1, config.MODEL.SWIN.IN_CHANS, config.DATA.IMG_SIZE, config.DATA.IMG_SIZE))
276
277 # Specify profiles
278 profile = builder.create_optimization_profile()
279 min_shape = (1, config.MODEL.SWIN.IN_CHANS, config.DATA.IMG_SIZE, config.DATA.IMG_SIZE)
280 ##TODO: There is a bug in TRT when opt batch is large
281 max_shape = (config.DATA.BATCH_SIZE, config.MODEL.SWIN.IN_CHANS, config.DATA.IMG_SIZE, config.DATA.IMG_SIZE)
282 profile.set_shape("input_img", min=min_shape, opt=min_shape, max=max_shape)
283 builder_config.add_optimization_profile(profile)
284
285 #import pdb;pdb.set_trace()
286 sw_output = swin_transformer(network, config, args, input_img, weights_dict)
287 if args.fp16:
288 sw_output.precision = trt.float16
289 sw_output.set_output_type(0, trt.float16)
290 sw_output = network.add_identity(sw_output.get_output(0))
291 network.mark_output(sw_output.get_output(0))
292
293 engine = builder.build_engine(network, builder_config)
294 return engine
295
296
297def main():

Callers 1

mainFunction · 0.70

Calls 1

swin_transformerFunction · 0.70

Tested by

no test coverage detected