Fix CUDA stream synchronization in sampler logprobs extraction#20064
Draft
chanh wants to merge 1 commit intosgl-project:mainfrom
Draft
Fix CUDA stream synchronization in sampler logprobs extraction#20064chanh wants to merge 1 commit intosgl-project:mainfrom
chanh wants to merge 1 commit intosgl-project:mainfrom
Conversation
`get_token_ids_logprobs_batch_optimized` was creating tensors directly on GPU and using `torch.repeat_interleave` with a GPU tensor, both of which force a `cudaStreamSynchronize` — a known issue (pytorch/pytorch#108968). Fix: compute lengths and flatten token IDs as Python lists on CPU, create tensors on CPU, then transfer to GPU with `non_blocking=True`. This eliminates the device sync and allows the GPU to continue executing kernels without stalling. Profiling confirms the cuda sync is removed after this change.
Contributor
|
Warning You have reached your daily quota limit. Please wait up to 24 hours and I will start processing your requests again! |
9 tasks
Qiaolin-Yu
reviewed
Mar 20, 2026
Collaborator
Qiaolin-Yu
left a comment
There was a problem hiding this comment.
Is it possible to do similar things like
Adding no_copy_to_cpu here and do the actual gpu-> cpu transfer in
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Motivation
get_token_ids_logprobs_batch_optimized was creating tensors directly on GPU and calling torch.repeat_interleave with a GPU tensor, both of which force a cudaStreamSynchronize — a known PyTorch issue
(pytorch/pytorch#108968). This stalls the GPU, preventing it from executing kernels concurrently during the sampler phase.
Modifications
Accuracy Tests
No model output changes — this is a performance fix only.
Benchmarking and Profiling
Profiling confirms the cudaStreamSynchronize call is removed after this change.
Checklist
Review Process
/tag-run-ci-label,/rerun-failed-ci,/tag-and-rerun-ci