Repository navigation
feat(xtoken): support TP/CP/diff-DP sharded cross-tokenizer distillation - #2745
Conversation
cb37de4 to
1537d7d
Compare
1537d7d to
bbe782f
Compare
39cf1b2 to
5185829
Compare
|
/ok to test 17bec2f |
|
/ok to test b02211f |
yuki-97
left a comment
There was a problem hiding this comment.
thanks @RayenTian , nice work!
|
/ok to test 1513dd6 |
yuki-97
left a comment
There was a problem hiding this comment.
LGTM, @terrykong could you take a look as well?
|
/ok to test 18ebb7f |
terrykong
left a comment
There was a problem hiding this comment.
Thanks @RayenTian — this is a substantial, well-structured extension (heterogeneous TP/CP/DP teacher to student, CUDA-IPC shard transport, CP-aware loss reductions) with loss-invariance curves and a dedicated parallelism-invariance nightly. Reviewed by a team of agents (RL/loss, distributed bug-finder, tests, comment threads) with leader verification; local unit tests pass here including the 2-GPU NCCL helper tests.
One higher-priority item to confirm (KL-vs-CE normalization scope under student TP>1) plus three minor suggestions, all inline. No open threads.
Generated by Claude Code
|
/ok to test ca46ce9 |
|
/ok to test 0cffdaa |
Extend cross-tokenizer off-policy distillation to run with the student under tensor- and context-parallelism (and a data-parallel degree that may differ from the teacher's) on the automodel/DTensor policy worker. - Teacher full-vocab logits are exported per rank and shipped to the student via CUDA IPC (FullLogitsPostProcessor), then reassembled on the consumer across its CP group for heterogeneous teacher/student TP/CP layouts. - The loss runs TP/CP-aware: vocab-parallel log-softmax / argmax / projection, CP load-balanced -> contiguous re-layout, CP-aware next-token shift, and partial chunk-average + grad-preserving all-reduce. The generic collectives live in model_utils; the cross-tokenizer orchestration in x_token/loss_utils. - TP/CP process groups are derived from the student logits' own device mesh instead of being threaded through the generic LossPostProcessor, so the SFT / GRPO / distillation LOGPROB paths keep using the DTensor branch. Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]> Signed-off-by: ruit <[email protected]>
…on nightly - Unit tests for the TP/CP/diff-DP setup grid and the vocab-/CP-parallel loss helpers (real 2-GPU NCCL actors), plus per-step IPC buffer release. Adds the x_token unit-test package __init__.py so the Ray actor FQN is importable. - Nightly recipe distillation-xtoken-off-policy-qwen3-4b-to-llama3.2-1b-1n8g- dtensor-tp4cp2 (student TP4xCP2 <- teacher TP2xCP2) and its driver, wired into nightly.txt; guards sharded-loss parallelism-invariance. Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]> Signed-off-by: ruit <[email protected]>
…r cleanups Resolves the review comments on PR #2745: - next_token_accuracy was biased at CP>1: it fed raw load-balanced logits/input_ids/token_mask into cp_shift_next (which assumes a contiguous CP layout). prepare_xtoken_cross_tokenizer_loss_input now relays the student input_ids/token_mask to contiguous and stashes them on LocalizedAlignment; the call site reuses student_logits_contig + those fields. Verified CP-invariant end-to-end (CP1 vs CP2 accuracy match). - student_next_token_ce DTensor branch double-dropped the last position ([B,T-2] vs the local branch's [B,T-1]); get_logprobs_from_vocab_parallel_logits already drops the CP-roll wrap-around, so the extra [:, :-1] is removed. - Renamed dp_all_reduce_sum -> group_all_reduce_sum and added an explicit group= param; it reduces over WORLD (DP×CP×TP) by default, not DP. - Fixed a missing Optional import in policy/utils.py that broke import of ensure_teacher_ipc_buffer. - ensure_teacher_ipc_buffer is now called unconditionally (drop the if-storage-is-None guard); its needs_realloc logic subsumes the first-call case and microbatch shapes are constant within a get_full_logits_ipc call. - Added a cp_size=2/rank=1 zero-copy fastpath test that exercises the seq-offset slice (the cp_size=1 case can't catch a dropped offset). - Docstring fixes: localize_alignment (load-balanced, not contiguous) and the module-level group_all_reduce_sum cross-reference. Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]> Signed-off-by: ruit <[email protected]>
…s/test cleanups - Unify the TP/CP SUM all-reduce helpers behind one autograd primitive (`_AllReduceSum`) with two named wrappers: `group_all_reduce_sum_with_grad` (differentiable; numerator reductions) and `group_all_reduce_sum` (no-grad; normalizers). Make the KL denominator's WORLD scope and float32 cast explicit at the call sites in loss_functions.py. - Keep the xtoken P-KL/gold KL denominator reduced over WORLD: the numerator is TP/CP-replicated (projection + chunk-average all-reduces), so the WORLD count cancels that replication. Verified parallelism-invariant via a student-TP1 vs student-TP4 overlay (DP×CP-only normalization over-weights KL by tp_size). - Make `val_teacher_micro_batch_size` a required field and default it to `teacher.train_micro_batch_size` via exemplar interpolation instead of a hidden call-site fallback (setup + validate read it directly). - `assemble_teacher_logits_from_shards`: assert full_seq_len is divisible by the student CP size, and add a CPU TP2×CP2 reassembly unit test (monkeypatched IPC). - Fix the stale `get_full_logits_ipc` driver-side docstring and document the post-construction `LocalizedAlignment.student_input_ids/token_mask` fields. Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]> Signed-off-by: ruit <[email protected]>
The teacher->student logit transport uses node-local CUDA IPC (`cudaIpcOpenMemHandle` only maps buffers created on the same host), so a multi-node run is only safe when every student rank's teacher shards live on its own node. Add `assert_xtoken_ipc_node_local` (in x_token/utils.py) and call it from `setup()`: single-node is always allowed; >1 node requires teacher and student to share the data_parallel degree and a node-aligned model-parallel group (`tp*cp` equal, `<= gpus_per_node`, and dividing `gpus_per_node`). Otherwise it fails fast with a clear message instead of crashing mid-validation with `cudaErrorMapBufferObjectFailed`. Add CPU unit tests for the pass case and each failure mode. Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]> Signed-off-by: ruit <[email protected]>
|
/ok to test 75e43f9 |
RL POR Test Summary — NVIDIA-NeMo/RL PR #2745
Result: ✅ PASS
What this PR adds (feature surface under test)PR #2745 introduces off-policy cross-tokenizer distillation where the student
What the test exercises (step by step)Step 1 — Projection matrix build (PR tool): Step 1.5 — Offline dataset staging: Step 2 — Heterogeneous cross-tokenizer distillation (the feature): Step 3 — Metric extraction + smoke assertion: Assertions & evidence (stdout.log lines 1331–1332)(validation/loss 2.58722, validation/kl_loss 0.0707011 at step 3) Policy: presence + finiteness only — NOT a distillation-gain claim (3 steps is What is / isn't coveredCovered:
NOT covered (out of scope for a function-tier smoke):
Guards (false-signal protection)
Both → clean SKIP (exit 0), never a false PASS/FAIL. CI-shrink (within policy): only step count + seq length reduced; disk-precheck RCA note: runs 1–4 failed on infra only (offline-cache / disk-precheck), NOT PR Artifacts
MRBranch pushed; create the MR (pre-filled, targets |
What does this PR do ?
Adds TP / CP / heterogeneous-DP sharding support to the cross-tokenizer (xtoken) off-policy distillation loss (P-KL + gold) on the DTensor v2 worker, fixes a context-parallel loss-invariance bug, and adds a parallelism-invariance nightly.
Issues
Closes #2682
Following:
Result
Teacher : Qwen/Qwen3-4B TP2 CP2 DP2
Student : meta-llama/Llama-3.2-1B TP4 CP2 DP1
KL Loss
Gold Loss
XT Loss
Usage
Before your PR is "Ready for review"
Pre checks:
Additional Information