Enable Liger layers - #58
Open
jiosephlee wants to merge 2 commits into
Open
Conversation
Signed-off-by: Joseph Lee <jiosephlee@gmail.com>
Signed-off-by: Joseph Lee <jiosephlee@gmail.com>
Contributor
Author
|
To be honest, not sure if it's worth supporting liger's kernels for the model definition as there are tradeoffs. Curious if there's been efforts to incorporate Liger's FusedGRPO kernels. That would lead to clear memory improvements, but would need to be validated first and would disable certain features (e.g. entropy calculation since full vocab logits are not available) |
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.
Summary
This PR adds an opt-in path for Liger layer kernels in Molt. Liger-kernels provides potential optimizations (in-practice they interestingly increase throughput but also memory usage). The PR selectively replaces compatible transformer-layer forwards while Molt retains ownership of the model-loading, attention, packing, and training paths. The flag remains opt-in and default-off.
The integration is model-level: native AutoModel architectures can have different module layouts, so each architecture needs explicit patching and parity validation. This PR enables dense text Qwen3 as the first validated
architecture. It applies Liger directly to the loaded Qwen3 instance and replaces only its MLP and decoder/final RMSNorm forwards.
For this initial Qwen3 support, native padded BSHD and TE-packed THD layouts are supported with TP, CP, EP, and sequence parallelism all set to one. VLMs remain unsupported.
Why attention, RoPE, and RL loss stay in Molt
Molt's native AutoModel path owns packed-sequence handling, context parallelism, Transformer Engine attention, and the associated RoPE layout. Replacing them with Liger's Hugging Face-oriented patches could alter those semantics or diverge from rollout inference.
Molt RL also needs materialized logits for action log-probabilities, entropy, KL, PPO/GRPO losses, and rewards. Liger's fused linear cross-entropy avoids materializing logits for supervised LM training, so it is intentionally not enabled here.
Validation
Correctness
python -m compileall -q molt examples/python testsandgit diff --checkpassed.
Qwen/Qwen3-4Bis the representative real-model validation case for this initial architecture. Parity was measured through Molt's native AutoModel path with BF16 mixed precision, padded SDPA, one B200 GPU, the same two-sample, eight-token parity input, and one AdamW step (lr=1e-3):8.7082386e-42.2494090e-54.0752126e-51.3351440e-55.1259995e-66.4167313e-71.9073486e-51.0626657e-52.3754510e-60000003.0100346e-65.3618911e-112.0269095e-5The largest AdamW update difference was
8.9158025e-4in layer 35's MLP down projection (mean difference3.9335588e-9). It is below the current parameter parity tolerance (1e-2) but is not bitwise-equivalent and is disclosed here. Relative errors per individual element are intentionally not reported because they are unstable near zero.One-run performance smoke test
The one-run performance smoke test uses
Qwen/Qwen3-4B, native padded SDPA, BF16, two B200 GPUs, batch size 2, sequence length 2048, five warmups, and 20 measured steps:This is one paired run, not a statistical performance claim. Liger improved throughput in this configuration but did not reduce memory, so this PR makes no memory-efficiency claim.
Limitations and follow-ups
torchrun.