-
Notifications
You must be signed in to change notification settings - Fork 77
[WS2][PR3][Logp] Add deterministic vocab-parallel TP logprob reference #265
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: test
Are you sure you want to change the base?
Changes from all commits
b7ffb3a
cdc11ba
6455715
3b4eaef
e6dbeef
878ba88
a63bea2
4fcdc30
6ffade4
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -54,6 +54,32 @@ CUDA priority list when the extension exposes `_C.batch_invariant_logp_sm90` | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| (built with `KERNEL_ALIGN_FORCE_SM90=1`) on an SM90 device. On any other build | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| or device, dispatch is unchanged (Triton -> PyTorch). | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ## Tensor Parallel | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| `VocabParallelLogprobOp` | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| (`rl_engine/kernels/ops/pytorch/loss/vocab_parallel_logp.py`) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| **TP=1, TP=2, and TP=4 produce bit-identical results.** | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1. Split the padded vocabulary into `num_vocab_tiles` fixed tiles. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2. Each rank computes fp32 `(max, sumexp)` for the tiles it owns. Every tile | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| is reduced as the same contiguous `[n, tile]` shape, on any rank. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 3. All tile partials are shared with `all_gather`. The collective only moves | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| bytes; it never does math, so it cannot round anything. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 4. Every rank merges all tiles in the same fixed order, over the same | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| `[n, num_vocab_tiles]` shape. `LSE = M + log(sum(s_t * exp(m_t - M)))`. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 5. The target logit is copied from the rank that owns it (never summed). | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 6. `logp = target_logit - LSE`. Inactive rows become `0.0`. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+57
to
+72
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 📐 Maintainability & Code Quality | 🟡 Minor | ⚡ Quick win State the Line 61 asserts that TP=1, TP=2, and TP=4 produce bit-identical results. The implementation provides that guarantee only while Lines 59 to 61 also render as a single paragraph, so the operator name, the file path, and the claim run together without punctuation. 📝 Proposed wording ## Tensor Parallel
-`VocabParallelLogprobOp`
-(`rl_engine/kernels/ops/pytorch/loss/vocab_parallel_logp.py`)
-**TP=1, TP=2, and TP=4 produce bit-identical results.**
+`VocabParallelLogprobOp`
+(`rl_engine/kernels/ops/pytorch/loss/vocab_parallel_logp.py`) computes the
+selected-token logprob across vocab-parallel TP ranks.
+**TP=1, TP=2, and TP=4 produce bit-identical results**, provided
+`num_vocab_tiles` is the same value at every TP degree and on every rank, and
+every shard boundary is tile-aligned. Both conditions fail loudly.📝 Committable suggestion
Suggested change
🤖 Prompt for AI Agents |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Usage goes through the contract-aware entry point: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ```python | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| from rl_engine.kernels.registry import kernel_registry | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| result = kernel_registry.get_logprob_op(contract) # LogprobContract from | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| op = result.op # rl_engine.kernels.logprob_contract | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| logp, lse = op(local_logits, target_ids, contract=contract, tp_group=tp_group) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ``` | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ## Benchmarks | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| `benchmarks/benchmark_batch_invariant_logp.py` compares Native, Triton, and the | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
@@ -224,3 +250,6 @@ WSL/Linux with CUDA. | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| - `rl_engine/kernels/registry.py` | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| - `tests/test_batch_invariant_logp.py` | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| - `benchmarks/benchmark_batch_invariant_logp.py` | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| - `rl_engine/kernels/ops/pytorch/loss/vocab_parallel_logp.py` | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| - `rl_engine/kernels/logprob_contract.py` | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| - `tests/test_vocab_parallel_logp.py` | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🩺 Stability & Availability | 🟠 Major | 🏗️ Heavy lift
Run multi-GPU logprob tests in CI.
This job installs the CPU-only PyTorch wheel and uses
ubuntu-latest. The TP=2 and TP=4 NCCL tests skip on this runner. Add a GPU-backed CI job that runs the distributed test cases. Otherwise, CI does not validate the cross-TP bitwise-equality requirement.🤖 Prompt for AI Agents