Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix for triton dynamic batching requirement #890

Merged
merged 1 commit into from
Feb 3, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 15 additions & 21 deletions demo/BERT/builder.py
Original file line number Diff line number Diff line change
Expand Up @@ -523,27 +523,21 @@ def load_onnx_weights_and_quant(path, config):
return weights_dict

def emb_layernorm(builder, network, config, weights_dict, builder_config, sequence_length, batch_sizes):
if len(batch_sizes) > 1:
input_ids = network.add_input(name="input_ids", dtype=trt.int32, shape=(-1, sequence_length))
segment_ids = network.add_input(name="segment_ids", dtype=trt.int32, shape=(-1, sequence_length))
input_mask = network.add_input(name="input_mask", dtype=trt.int32, shape=(-1, sequence_length))

# Specify profiles for the batch sizes we're interested in.
# Make sure the profile also works for all sizes not covered by the previous profile.
prev_size = 0
for batch_size in sorted(batch_sizes):
profile = builder.create_optimization_profile()
min_shape = (prev_size + 1, sequence_length)
shape = (batch_size, sequence_length)
profile.set_shape("input_ids", min=min_shape, opt=shape, max=shape)
profile.set_shape("segment_ids", min=min_shape, opt=shape, max=shape)
profile.set_shape("input_mask", min=min_shape, opt=shape, max=shape)
builder_config.add_optimization_profile(profile)
prev_size = batch_size
else:
input_ids = network.add_input(name="input_ids", dtype=trt.int32, shape=(batch_sizes[0], sequence_length))
segment_ids = network.add_input(name="segment_ids", dtype=trt.int32, shape=(batch_sizes[0], sequence_length))
input_mask = network.add_input(name="input_mask", dtype=trt.int32, shape=(batch_sizes[0], sequence_length))
input_ids = network.add_input(name="input_ids", dtype=trt.int32, shape=(-1, sequence_length))
segment_ids = network.add_input(name="segment_ids", dtype=trt.int32, shape=(-1, sequence_length))
input_mask = network.add_input(name="input_mask", dtype=trt.int32, shape=(-1, sequence_length))

# Specify profiles for the batch sizes we're interested in.
# Make sure the profile also works for all sizes not covered by the previous profile.
for batch_size in sorted(batch_sizes):
profile = builder.create_optimization_profile()
min_shape = (1, sequence_length)
shape = (batch_size, sequence_length)
profile.set_shape("input_ids", min=min_shape, opt=shape, max=shape)
profile.set_shape("segment_ids", min=min_shape, opt=shape, max=shape)
profile.set_shape("input_mask", min=min_shape, opt=shape, max=shape)
builder_config.add_optimization_profile(profile)

wbeta = trt.PluginField("bert_embeddings_layernorm_beta", weights_dict["bert_embeddings_layernorm_beta"].numpy(), trt.PluginFieldType.FLOAT32)
wgamma = trt.PluginField("bert_embeddings_layernorm_gamma", weights_dict["bert_embeddings_layernorm_gamma"].numpy(), trt.PluginFieldType.FLOAT32)
wwordemb = trt.PluginField("bert_embeddings_word_embeddings", weights_dict["bert_embeddings_word_embeddings"].numpy(), trt.PluginFieldType.FLOAT32)
Expand Down