Skip to content

[WIP] kda in torchtitan (vllm integration) - #4352

Open
liangel-02 wants to merge 1 commit into
gh/liangel-02/4/basefrom
gh/liangel-02/4/head
Open

[WIP] kda in torchtitan (vllm integration)#4352
liangel-02 wants to merge 1 commit into
gh/liangel-02/4/basefrom
gh/liangel-02/4/head

Conversation

@liangel-02

@liangel-02 liangel-02 commented Aug 27, 2026

Copy link
Copy Markdown
Contributor

[ghstack-poisoned]
@meta-cla meta-cla Bot added the CLA Signed This label is managed by the Meta Open Source bot. label Aug 27, 2026
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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ciflow/rl CLA Signed This label is managed by the Meta Open Source bot.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant