You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
[Performance]: Avoid dense Python conversion for sparse TorchSampler logprobs #21980
TorchSampler.update_requests converts LogProbsState tensors to nested Python lists after the sampler completion event. Today, if one request asks for logprobs, LogProbsStateList.from_logprobs_state calls .tolist() for every preallocated sequence slot. Mixed batches therefore materialize thousands of unused rows.
Pass the active logprobs sequence slots into the conversion and compact the host tensors first when fewer than half of the slots need logprobs. Dense batches keep the existing direct .tolist() path. The request-to-row mapping preserves the existing result format.
This work is on the serialized host path after sampler_event.synchronize(), before requests can be updated or responses returned.
Report of performance regression
CPU-only benchmark on current main 9d32b9506, using the real LogProbsStateList.from_logprobs_state implementation. Inputs used CPU tensors shaped like the sampler's host buffers with max_topk_logprobs=20. The process was pinned to CPU 0, with 15 warmups, seven timed groups, and the median of 30-100 calls per group.
Preallocated slots
Steps
Requests needing logprobs
Before
Proposed
Speedup
256
1
1
357.8 us
25.5 us
14.0x
256
1
32
324.9 us
66.1 us
4.9x
2048
1
1
4515.5 us
25.4 us
177.5x
2048
1
64
4496.2 us
109.5 us
41.1x
The 2048-slot size matches the shipped max_batch_size default. A separate equivalence test compares dense and compact conversion for sampled-only, simple-format, and top-k logprobs; all four cases pass.
Misc discussion on performance
The device-to-host copies are unchanged. This proposal removes only the subsequent Python-object materialization for unused slots, so it does not add GPU work or synchronization.
Your current environment
OS: Linux 4.18.0 x86_64
Python: 3.11.18
PyTorch: 2.15.0+cpu
TensorRT-LLM: main at 9d32b9506
GPU: not used
Before submitting a new issue...
I searched open and closed issues and pull requests, including recent sampler and logprobs performance work.
AI assistance (Cursor) was used to investigate and benchmark this proposal.
Activity
[NVIDIA#21980][test] Cover sparse host logprobs at the sampler boundary