[WIP] kda in torchtitan (vllm integration) - #4352
Open
liangel-02 wants to merge 1 commit into
Open
Conversation
liangel-02
requested review from
fegin,
tianyu-l,
wconstab and
wwwjn
as code owners
August 27, 2026 17:16
liangel-02
added a commit
that referenced
this pull request
Aug 27, 2026
(remaking bc i accideltny merged #4164 into my ghstack instead of main) this PR adds attention module for KDA (relying on attention gym KDA kernels and user facing APIs) **correctness** tested with c4 dataset: <img width="940" height="496" alt="Screenshot 2026-08-24 at 3 04 05 PM" src="https://github.com/user-attachments/assets/c07f5e37-688d-47a6-9e96-e8ea8493e72f" /> torchtitan attention gym vs hugging face (natural routing) ``` Full multimodal last-token logit parity (TorchTitan vs HuggingFace) KL=7.0921e-02 cos=0.927007 max_diff=1.6885e+00 top1=N top5=20% ``` ^i compared hugigng face and torchtitan layer by layer using identical weights and inputs, first divergence appears at block 2 where expert choice agreement was 94.5% and max router score diff was 0.0065. with nearly tied experts, small numerical differences led to different experts being in the top k which led to model executing different expert weights. if we force expert routing to be the same, we see more alignment. i did this by first running hugging face and recording the top k experts for every token at every layer and then replacing torchtitan with those choices. torchtitan attention gym vs hugging face (forced expert routing) ``` Full multimodal last-token logit parity (TorchTitan vs HuggingFace) KL=2.1806e-04 cos=0.999769 max_diff=9.6069e-02 top1=Y top5=80% ``` torchtitan fla vs hugging face ``` Full multimodal last-token logit parity (TorchTitan vs HuggingFace) KL=2.3385e-04 cos=0.999754 max_diff=9.7656e-02 top1=Y top5=80% ``` **performance** <img width="530" height="144" alt="Screenshot 2026-08-24 at 6 35 10 PM" src="https://github.com/user-attachments/assets/a880b257-1a21-4818-b148-e302125ff86c" /> ^attention gym is 1.38x and uses 26% less memory attention gym trace: <img width="1225" height="416" alt="Screenshot 2026-08-24 at 6 41 17 PM" src="https://github.com/user-attachments/assets/11950616-8467-4c85-9353-ebfaafdaf31b" /> fla trace: <img width="1246" height="323" alt="Screenshot 2026-08-24 at 6 41 49 PM" src="https://github.com/user-attachments/assets/6168e16c-a6f4-4e62-a5a9-848c7a02055d" /> Stack from [ghstack](https://github.com/ezyang/ghstack/tree/0.15.0) (oldest at bottom): * #4352 * __->__ #4351
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.
Stack from ghstack (oldest at bottom):