Repository navigation
[AutoTP] Add optional Liger vocabulary-parallel cross entropy - #8540
Conversation
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 5453799d02
ℹ️ About Codex in GitHub
Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".
| and target.numel() > 0 | ||
| and _uniform_vocab_shards[(tp_group, local_vocab_size, vocab_start_index, vocab_end_index)]) | ||
| if use_liger: | ||
| loss = _liger_vocab_cross_entropy(vocab_parallel_logits, target.to(dtype=torch.long), tp_group, ignore_index) |
There was a problem hiding this comment.
Avoid treating the default world as the TP group
When a multi-rank data-parallel job calls the public API with backend="liger" and leaves tp_group=None, the preceding metadata logic treats TP as disabled, but this call passes None to Liger's distributed group argument, where it denotes the default world process group. Liger then interprets the DP replicas' full-vocabulary logits as separate vocabulary shards, producing an incorrect global loss and gradients. Fall back to the PyTorch implementation in this case or pass an explicit singleton TP group.
Useful? React with 👍 / 👎.
| vocab_parallel_ce_backend: Literal["torch", "liger"] = "torch" | ||
| """Optional Liger CE acceleration; the PyTorch reference remains the default.""" |
There was a problem hiding this comment.
Add the mandatory commit sign-off
Commit 5e07eda8cb904aad0dce2b9a9df136255b432c78 is a non-merge commit but its message has no Signed-off-by trailer, so it does not satisfy this repository's commit/CI requirements and will fail DCO-style validation. Recreate the commit with the configured author identity and the required sign-off.
AGENTS.md reference: AGENTS.md:L8-L8
Useful? React with 👍 / 👎.
|
@0z5a Could you have a rebase? Thanks |
Signed-off-by: 0z5a <dezhen.lu@student.uni-tuebingen.de> (cherry picked from commit 5453799)
5453799 to
3b7b856
Compare
| # Liger's kernel all-gathers fixed-width shards, while the PyTorch path trims uneven | ||
| # ones, so the kernel stays restricted to equal shards. | ||
| tp_world_size = dist.get_world_size(tp_group) if tp_group is not None else 1 | ||
| return (get_accelerator().device_name() == "cuda" and get_accelerator().on_accelerator(vocab_parallel_logits) |
There was a problem hiding this comment.
liger kernel is written on trion, does it mean it could run on not only cuda device but any accelerator supports triton? May need something cuda independent here.
There was a problem hiding this comment.
just tested liger kernel works for xpu device as well (with triton and liger kernel installed), so guard it by cuda should be too restrict.
There was a problem hiding this comment.
Agree. Can our CI test xpu or other device?
There was a problem hiding this comment.
current XPU does not have regular nightly run. I think allow the test run in v1 (install liger-kernel in workflow if necessary) and guard by whether triton is supported (accelerator.is_triton_supported()) should be good enough. This is a contract between accelerator and deepspeed whether triton kernels should be supported.
| reuse_dist_env = False | ||
|
|
||
| def test_losses_and_gradients(self): | ||
| pytest.importorskip("liger_kernel.ops.vocab_parallel_cross_entropy") |
There was a problem hiding this comment.
Would this test be skipped on current Modal runner?
| vocab_end_index=vocab_parallel_head.vocab_end_index, | ||
| ignore_index=ignore_index) | ||
| ignore_index=ignore_index, | ||
| backend=backend) |
There was a problem hiding this comment.
Need to check whether VocabParallelCausalLMLoss accepts the backend argument
|
@delock @jinyouzhi Thanks for review. I will check it tomorrow. Zzz... |
- Select Liger only behind an explicit tensor-parallel group. A None group is the default world to some Liger versions, which would read data-parallel replicas as vocabulary shards and produce a wrong global loss. - Gate the kernel on the accelerator's Triton support instead of CUDA only, so Triton-capable XPU and other accelerators take the same path. - Accept backend on VocabParallelCausalLMLoss so configure_vocab_parallel_loss no longer raises TypeError for vocab_parallel_ce_backend. - Install liger-kernel in the development requirements so the v1 test executes in CI instead of being skipped by importorskip. - Cover the new dispatch contract with tests and keep the documented boundaries current. Signed-off-by: 0z5a <dezhen.lu@student.uni-tuebingen.de>
|
Addressed all four review points in 1152579.
CUDA-only guard (@delock): the gate is now Test skipped on the Modal runner (@delock): yes — it was skipped there, because the sandbox had no
DCO (@chatgpt-codex-connector): the flagged commit was dropped when the branch was rebased onto the merged #8309; both commits now carry Validation on the current head (1152579)Two RTX 5090 (32607 MiB each), Python 3.12.13, torch 2.13.0+cu130, Triton 3.7.1, transformers 5.10.4, liger-kernel 0.8.2.
Stage 1: the CE op alone (forward + backward, TP=2, BF16, local vocab 16000)
The fused op is 1.28x faster at 8192 tokens and 1.91x at 16384, with 33% less peak allocation at both sizes, and the losses agree exactly. Stage 2/3: E2E AutoTP training, real checkpoints and data
pythia-1.4b is the GPTNeoX Reading the numbers
|
|
To use Codex here, create a Codex account and connect to github. |
|
LGTM |
Dependency and review scope
Depends on #8309 (PR-B from #8173), currently open. This branch is based on its head
1b4ba6b162e87b10bedbb7316466bd877e2cb278; inherited PR-B commits retain their original authorship. The final commit is the optional Liger backend work. Please review that commit for this PR's independent changes. This is a draft until PR-B lands; the master comparison currently includes the dependency changes.This addresses the optional fused CE and memory-profiling direction in #8173. It does not include row-parallel output-head training (#8538) or coupled tied-embedding sharding.
Changes
tensor_parallel.vocab_parallel_ce_backend: "liger"alongsidevocab_parallel_lm_head: true; default"torch"remains dependency-free.liger-kernel>=0.8.1) and retain the existing reduction / causal-label-shifting contract.This fuses CE only, not the linear projection. Local vocabulary logits are still materialized.
Real-device validation
jk01: two NVIDIA L20 GPUs (46068 MiB each), isolated container, Python 3.12.3, PyTorch 2.13.0+cu130, CUDA 13.0, Transformers 5.14.1, Triton 3.7.1, liger-kernel 0.8.2.
git diff --checkpassed.The distributed integration methods in
TestLigerVocabParallelCEwere executed via two-rank torchrun on the actual devices. Reproduce with pytest:Memory profile
Compared local linear + vocabulary-parallel CE forward/backward + five SGD updates, two micro-batches each, after kernel warm-up and resetting weights/allocated peaks. BF16, TP=2, 1024 tokens per rank, hidden=128, global vocabulary=65536, local vocabulary=32768. Statistics are the maximum across ranks.
Peak allocated decreases approximately 39.3%; incremental peak decreases approximately 42.1%. Losses and final local weights agree. This is a short single-sample memory comparison, not evidence of throughput speedup; allocated memory is not total device or reserved memory.
Four-GPU TP x SP integration, mixed-precision/ZeRO checkpoint round trips, and large-model convergence are not validated by this two-GPU run.