Fix: mistake sigmoid in kda#17508
Conversation
Summary of ChangesHello @strgrb, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed! This pull request resolves a subtle bug within the 'KimiLinearAttentionBackend' where an erroneous 'sigmoid' activation was applied to the 'beta' parameter during the decode operation. The change ensures that the 'sigmoid' function is only invoked when appropriate, thereby restoring the correct logprobability calculations and maintaining the integrity of the model's output. Highlights
🧠 New Feature in Public Preview: You can now enable Memory to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console. Using Gemini Code AssistThe full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips. Invoking Gemini You can request assistance from Gemini at any point by creating a comment using either
Customization To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a Limitations & Feedback Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here. You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension. Footnotes
|
There was a problem hiding this comment.
Code Review
This pull request correctly fixes a bug where an extra sigmoid function was applied to beta during the decode phase in KDA. The change correctly moves the sigmoid application to be conditional on not being in decode mode. I've also suggested a small refactoring to improve code clarity by reducing duplication.
|
Could you add an unit test for it? |
|
/rerun-stage stage-b-test-large-2-gpu |
|
✅ Triggered |
@ispobock I wrote a unittest and random generated data may always pass, and model dumped data works well. I will find a way to generate reasonable data and then commit the unittest. |
|
@ispobock Now unittest is pushed, and with this ut, we can see this bug: with extra sigmoid and we should use fp32 ssm_states to avoid random input always pass |
|
/tag-run-ci-label |
|
/rerun-failed-ci |
3 similar comments
|
/rerun-failed-ci |
|
/rerun-failed-ci |
|
/rerun-failed-ci |
|
@ispobock It seems most ci passed, and an amd ci failed with llada. I try it once more |
|
|
||
|
|
||
| @unittest.skipIf(not torch.cuda.is_available(), "Test requires CUDA") | ||
| class TestKDAFusedSigmoidGatingRecurrent(unittest.TestCase): |
There was a problem hiding this comment.
Could you add this test to https://github.com/sgl-project/sglang/tree/main/test/registered/attention?
Also register it like
There was a problem hiding this comment.
@ispobock Is this correct? I move the test here and register it to stage-b-test-large-1-gpu
|
/rerun-failed-ci |
1 similar comment
|
/rerun-failed-ci |
Motivation
This pr #17108 introduced a bug after resolving conflicts with main, that beta do an extra sigmoid in decode.
But when I test with gsm8k and mmlu, it gives the correct scores. So I use logprob to verify it:
I use an input of
1 2 3 5 8, and get the logprobs:[[-0.17581729590892792, 220, None], [-0.1355297565460205, 1718, None], [-0.2613707184791565, 220, None], [-0.02005852572619915, 2714, None], [-0.24853865802288055, 220, None], [-0.012261606752872467, 3587, None], [-0.23973554372787476, 220, None], [-0.007739911787211895, 3807, None], [-0.14101243019104004, 220, None], [-0.004367693793028593, 7173, None], [-0.25840112566947937, 220, None], [-0.005275614093989134, 17242, None], [-0.41415637731552124, 220, None], [-0.004919685889035463, 22851, None], [-0.12799102067947388, 220, None], [-0.003638078924268484, 38685, None], [-0.09586101025342941, 220, None], [-0.0013765154872089624, 30830, None], [-0.08789035677909851, 220, None], [-0.0007250064518302679, 48105, None], [-0.21781061589717865, 220, None], [-0.009240597486495972, 20320, None], [-0.000614216027315706, 22, None], [-0.06670233607292175, 220, None], [-0.0030783668626099825, 30049, None], [-0.0010446811793372035, 19, None], [-0.036415670067071915, 220, None], [-0.0008166077313944697, 39922, None], [-0.0005688241217285395, 16, None], [-0.030416714027523994, 220, None], [-0.00824251864105463, 46983, None], [-0.007040098775178194, 20, None]][[-0.17581729590892792, 220, None], [-0.13807269930839539, 1718, None], [-0.22698462009429932, 220, None], [-0.02354123815894127, 2714, None], [-0.2504671812057495, 220, None], [-0.014055313542485237, 3587, None], [-0.2388245314359665, 220, None], [-0.006573718972504139, 3807, None], [-0.14944948256015778, 220, None], [-0.006166716571897268, 7173, None], [-0.16696849465370178, 220, None], [-0.005782779306173325, 17242, None], [-0.5210497975349426, 220, None], [-0.006434556096792221, 22851, None], [-0.15668046474456787, 220, None], [-0.004042905755341053, 38685, None], [-0.12107308954000473, 220, None], [-0.0016079128254204988, 30830, None], [-0.0959644466638565, 220, None], [-0.0013440155889838934, 48105, None], [-0.183536097407341, 220, None], [-0.0059707374311983585, 20320, None], [-0.0005921755800954998, 22, None], [-0.0742078647017479, 220, None], [-0.003984726965427399, 30049, None], [-0.0022481423802673817, 19, None], [-0.04476695507764816, 220, None], [-0.0012746074935421348, 39922, None], [-0.0008269704412668943, 16, None], [-0.03894393518567085, 220, None], [-0.00423392141237855, 46983, None], [-0.01138688251376152, 20, None]][[-0.17581729590892792, 220, None], [-0.1355297565460205, 1718, None], [-0.26084673404693604, 220, None], [-0.019883597269654274, 2714, None], [-0.24637433886528015, 220, None], [-0.01390707679092884, 3587, None], [-0.2394082248210907, 220, None], [-0.0077369543723762035, 3807, None], [-0.13882087171077728, 220, None], [-0.004371016751974821, 7173, None], [-0.24931126832962036, 220, None], [-0.00554867135360837, 17242, None], [-0.43724241852760315, 220, None], [-0.005725057329982519, 22851, None], [-0.126996710896492, 220, None], [-0.0034029928501695395, 38685, None], [-0.09386846423149109, 220, None], [-0.0014907924924045801, 30830, None], [-0.08422954380512238, 220, None], [-0.0007373951375484467, 48105, None], [-0.19275186955928802, 220, None], [-0.008889622986316681, 20320, None], [-0.0006095697171986103, 22, None], [-0.06565475463867188, 220, None], [-0.002948106499388814, 30049, None], [-0.000979539705440402, 19, None], [-0.036493945866823196, 220, None], [-0.0008892634068615735, 39922, None], [-0.0006393534131348133, 16, None], [-0.030334722250699997, 220, None], [-0.007627647835761309, 46983, None], [-0.006255688611418009, 20, None]]Modifications
Accuracy Tests
Benchmarking and Profiling
Checklist
Review Process
/tag-run-ci-label,/rerun-failed-ci,/tag-and-rerun-ci