perf(processor): reduce GPU-CPU sync in action tokenization#3123
Open
jashshah999 wants to merge 1 commit intohuggingface:mainfrom
Open
perf(processor): reduce GPU-CPU sync in action tokenization#3123jashshah999 wants to merge 1 commit intohuggingface:mainfrom
jashshah999 wants to merge 1 commit intohuggingface:mainfrom
Conversation
The _tokenize_action loop was calling action[i].cpu() and then tokens.to(device) per sample, creating 2*batch_size GPU-CPU synchronization points per training step. For batch_size=64, that is 128 sync stalls per step. Changes: - Move entire batch to CPU in one transfer before the loop - Build all token tensors on CPU, stack, then transfer once to GPU - Cache constant prefix/suffix token sequences (bos + "Action: " and "|") in __post_init__ instead of recomputing every iteration This reduces GPU-CPU sync from O(batch_size) to O(1) per call.
2 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.
What this does
Reduces GPU-CPU synchronization overhead in
ActionTokenizerProcessorStep._tokenize_action(), which is called every training step for tokenizer-based policies (SmolVLA, xVLA).The problem
The tokenization loop was calling
action[i:i+1].cpu()andtokens.to(device)per sample, creating2 * batch_sizeGPU-CPU synchronization points per training step. For a typicalbatch_size=64, that's 128 sync stalls per step.Additionally, constant token sequences (
bos_token_id,encode("Action: "),encode("|")) were recomputed every iteration.This is likely a contributing factor to issue #1488 (SmolVLA training much slower than ACT).
Changes
batch_size)batch_size)__post_init__Net effect: GPU-CPU sync reduced from
O(batch_size)toO(1)per call.Related: #1488