[GRPO] chunk over vocab without materializing logits #953
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.
Summary
Updating the forward pass to compute only the required per-token log probabilities, simplifying the loss function interface, and adding comprehensive tests to ensure correctness against the Triton implementation:
chunk_forwardmethod infused_linear_ppo.pynow computes log probabilities only for selected tokens (usingselected_token_ids), avoiding allocation of large[B, T, V]tensors and instead returning[B, T]tensors for per-token log probabilities. This greatly reduces memory usage, especially for large vocabularies._compute_chunk_lossis updated to use these per-token log probabilities directly, and the interface for the loss function is changed accordingly (fromlog_probstoper_token_logps). [1] [2]Simplification and correctness improvements:
ppo_loss_fningrpo_loss.pyis simplified: it now expects pre-gathered per-token log probabilities, removing the need for an internal.gather()operation and unnecessary handling of full log probability tensors.Testing and validation:
test_chunked_vs_triton_grpo_loss, is added to ensure that the chunked, memory-optimized loss matches the Triton kernel implementation across a range of configurations, including different batch sizes, sequence lengths, hidden sizes, vocab sizes, loss types, and hyperparameters. This test checks per-token losses, KL divergences, clipping indicators, and reduced losses for correctness.Testing Done
make testto ensure correctnessmake checkstyleto ensure code stylemake test-convergenceto ensure convergence