[Perf] Parallelize fill_bitmask to accelerate high-throughput guided decoding (#21862)
Signed-off-by: Benjamin Chislett <benjamin.chislett@centml.ai>
This commit is contained in:
@@ -1324,9 +1324,14 @@ class GPUModelRunner(LoRAModelRunnerMixin, KVConnectorModelRunnerMixin):
|
||||
cumulative_index += 1 + num_spec_tokens
|
||||
grammar_bitmask = sorted_bitmask
|
||||
|
||||
# If the grammar bitmask and the logits have the same shape
|
||||
# we don't need to pass indices to the kernel,
|
||||
# since the bitmask is already aligned with the logits.
|
||||
skip_out_indices = grammar_bitmask.shape[0] == logits.shape[0]
|
||||
|
||||
# Serialization of np.ndarray is much more efficient than a tensor,
|
||||
# so we receive it in that format.
|
||||
grammar_bitmask = torch.from_numpy(grammar_bitmask)
|
||||
grammar_bitmask = torch.from_numpy(grammar_bitmask).contiguous()
|
||||
|
||||
# Force use of the torch.compile implementation from xgrammar to work
|
||||
# around issues with the Triton kernel in concurrent structured output
|
||||
@@ -1334,7 +1339,7 @@ class GPUModelRunner(LoRAModelRunnerMixin, KVConnectorModelRunnerMixin):
|
||||
xgr_torch_compile.apply_token_bitmask_inplace_torch_compile(
|
||||
logits,
|
||||
grammar_bitmask.to(self.device, non_blocking=True),
|
||||
indices=out_indices,
|
||||
indices=out_indices if not skip_out_indices else None,
|
||||
)
|
||||
|
||||
def sync_and_slice_intermediate_tensors(
|
||||
|
||||
Reference in New Issue
Block a user