Repository navigation
Add Qwen3 P-EAGLE parallel model and KL loss core - #29
hootandy321 wants to merge 1 commit into
Conversation
Codex Review Summary: ✅ CompletedThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
|
Thanks @hootandy321, and welcome to ASpec! 🎉 Really happy to see our first community PR, and to hear you're already trying ASpec for your own experiments. Thanks for putting so much care into the tests and docs, too. Starting with the Qwen3 model/loss core sounds like a good first step, and building this up through smaller PRs makes sense. Let's work through the review here and keep discussing the next steps in #16. Feel free to share questions or anything you get stuck on. We're happy to help! |
97af8a0 to
d91cc80
Compare
|
No actionable comments were generated in the recent review. Walkthrough
Merge Risk:
|
Part of #16. This PR covers the model/loss prerequisite. I am continuing to iterate and test the remaining work locally and plan to submit follow-up PRs once it is more complete.
Main changes
Following the scope suggested in the issue, this PR adds a standalone Qwen3 P-EAGLE model and forward-KL loss module as components for parallel draft training.
The model computes multiple prediction depths in one forward pass, using shared projection and decoder parameters, a trainable token mask embedding, and a trainable auxiliary hidden mask. It preserves Qwen3 Q/K normalization and makes the alignment between Target features, input tokens, and per-depth distillation targets explicit.
The main changes are:
tests/cpu, where the upstream CI workflow discovers them automatically.This is still a minimal implementation. It currently uses a deterministic dense anchor/depth layout to validate the model and loss semantics. The supported scope is one packed input row, a full vocabulary, full attention, zero attention dropout, and eager/SDPA execution.
If this direction and scope look reasonable, I would be happy to continue improving it and complete the remaining work through follow-up PRs.
Verification (agent-run tests, human-reviewed)
Checks were run in an isolated Linux venv using Python 3.13.3, Torch
2.13.0+cpu, Transformers5.12.1, and the repository's CPU test dependencies:python -m pytest -q tests/cpu): 711 passed, no skips, including the 64 new tests.python -m pytest -q tests/source): 9 passed, no skips.The branch has been rebased onto upstream
fd4dfa2e7aeab30cc447670d927478cb44bec04b. The P-EAGLE tests now live intests/cpu/test_peagle.py; the CI workflow itself matches upstream.The first CPU run hit an upstream DMTP strict round-trip assertion with a
2.38e-7difference. I reproduced the same assertion on unmodified upstreammainwith seed 0. An unchanged rerun of this PR passed all 711 CPU tests. The initial failure and reproduction logs have been retained.Component-level comparisons were also rerun against the pinned upstream source:
5.96e-8.Due to time constraints, training with the real Qwen3-8B Target, CUDA numerics, and related runtime measurements have not yet been validated.
This pull request adds a Qwen3-only P-EAGLE model core and a forward-KL loss function. It adds no public trainer, CLI option, checkpoint format, or export path.
Changed files (6 files, 782 lines added, 0 removed):
aspec/models/peagle.py(+267): new model, layout, mask, and loss code.tests/cpu/test_peagle.py(+381): CPU tests and independent scalar reference helpers.docs/user-guide/peagle.md(+126): usage, input shape rules, masking semantics, loss definition, and deferred work.docs/user-guide/algorithms.md(+6),docs/support.md(+1),docs/framework/REFERENCES.md(+1): support table, guide section, and source attribution.New public API in
aspec/models/peagle.py:peagle_dense_layout(document_ids, num_depths): builds anchor and depth positions.peagle_attention_mask(anchor_pos, depth, document_ids): builds the attention mask.PEagleOutput: dataclass with logits, layout, validity, and depth metadata.PEagleDraftModel(config, *, mask_token_id, num_aux_hidden_states=3, num_depths=4): Qwen3 draft model.forwardtakesinput_ids,hidden_states,document_ids, and optionalposition_ids.peagle_kl_loss(output, teacher_logits, loss_mask): returns the loss and per-depth observations.Behavior and constraints, confirmed in the diff:
ValueError.[1, S]. It requires int64 token IDs and document IDs. It uses-1for padding.mask_token_idmust lie within the Target vocabulary.num_aux_hidden_statesTarget features.1e-5.Verification:
5.96e-8. These are author-reported results.Compatibility: The change adds new modules and documentation only. It changes no existing public declarations.