Use pin_memory in forward_batch.init_new to reduce decoding latency#21360
Open
litmei wants to merge 13 commits intosgl-project:mainfrom
Open
Use pin_memory in forward_batch.init_new to reduce decoding latency#21360litmei wants to merge 13 commits intosgl-project:mainfrom
litmei wants to merge 13 commits intosgl-project:mainfrom
Conversation
Contributor
|
Warning You have reached your daily quota limit. Please wait up to 24 hours and I will start processing your requests again! |
Collaborator
|
/tag-and-rerun-ci |
Collaborator
|
/rerun-failed-ci |
2 similar comments
Contributor
|
/rerun-failed-ci |
Contributor
|
/rerun-failed-ci |
litmei
commented
Apr 7, 2026
litmei
commented
Apr 7, 2026
Comment on lines
+815
to
+827
| if _pin: | ||
| mrope_positions_cat = torch.cat( | ||
| [pos for pos in mrope_positions_list], | ||
| dim=1, | ||
| ).pin_memory() | ||
| else: | ||
| mrope_positions_cat = torch.cat( | ||
| [pos for pos in mrope_positions_list], | ||
| dim=1, | ||
| ) | ||
| self.mrope_positions = mrope_positions_cat.to( | ||
| dtype=torch.int64, device=model_runner.device | ||
| ) |
Contributor
Author
There was a problem hiding this comment.
could this part be simpler?
litmei
commented
Apr 8, 2026
5 tasks
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
In low-latency scenarios, there are substantial idle gaps between Decode phases.
Modifications
Profiling analysis identified a Host-to-Device (H2D) synchronization bottleneck within forward_batch.init_new. Applying .pin_memory() converts this synchronous operation into an asynchronous one.
Accuracy Tests
Benchmarking and Profiling
Before:
After:
Checklist
Review Process
/tag-run-ci-label,/rerun-failed-ci,/tag-and-rerun-ci