Skip to content

Support MoE sigmoid scoring - #1472

Merged
kyuyeunk merged 29 commits into
vllm-project:mainfrom
catswe:support_sigmoid_scoring
Feb 2, 2026
Merged

Support MoE sigmoid scoring#1472
kyuyeunk merged 29 commits into
vllm-project:mainfrom
catswe:support_sigmoid_scoring

Conversation

@catswe

@catswe catswe commented Jan 16, 2026

Copy link
Copy Markdown
Contributor

Description

This enables running GLM models #1104. I referenced this commit from Kyuyeun 652318d

Tests

image

Updated tpu-inference/tests/kernels/fused_moe_v1_test.py

Checklist

Before submitting this PR, please make sure:

  • I have performed a self-review of my code.
  • I have necessary comments in my code, particularly in hard-to-understand areas.
  • I have made or will make corresponding changes to any relevant documentation.

@catswe
catswe marked this pull request as ready for review January 17, 2026 18:04
@catswe
catswe marked this pull request as draft January 17, 2026 18:04
Signed-off-by: catswe <212922539+catswe@users.noreply.github.com>
Signed-off-by: catswe <212922539+catswe@users.noreply.github.com>
Signed-off-by: catswe <212922539+catswe@users.noreply.github.com>
Signed-off-by: catswe <212922539+catswe@users.noreply.github.com>
Signed-off-by: catswe <212922539+catswe@users.noreply.github.com>
Signed-off-by: catswe <212922539+catswe@users.noreply.github.com>
@catswe
catswe force-pushed the support_sigmoid_scoring branch from a4f0917 to c389796 Compare January 17, 2026 18:10
Signed-off-by: catswe <212922539+catswe@users.noreply.github.com>
Signed-off-by: catswe <212922539+catswe@users.noreply.github.com>
Signed-off-by: catswe <212922539+catswe@users.noreply.github.com>
Signed-off-by: catswe <212922539+catswe@users.noreply.github.com>
Signed-off-by: catswe <212922539+catswe@users.noreply.github.com>
Signed-off-by: catswe <212922539+catswe@users.noreply.github.com>
@catswe
catswe marked this pull request as ready for review January 19, 2026 05:59
@catswe catswe changed the title Support sigmoid scoring Support MoE sigmoid scoring Jan 19, 2026
Signed-off-by: catswe <212922539+catswe@users.noreply.github.com>

@kyuyeunk kyuyeunk left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

looks good. but requires approval from @bythew3i on changes for fused_moe/v1/kernel.py.

Comment thread tpu_inference/layers/common/fused_moe_gmm.py Outdated
Comment thread tpu_inference/kernels/fused_moe/v1/kernel.py Outdated
Signed-off-by: catswe <212922539+catswe@users.noreply.github.com>
@bvrockwell

Copy link
Copy Markdown
Collaborator

This is sweet @catswe @kyuyeunk - great job!

Signed-off-by: catswe <212922539+catswe@users.noreply.github.com>
Signed-off-by: catswe <212922539+catswe@users.noreply.github.com>
Signed-off-by: catswe <212922539+catswe@users.noreply.github.com>
@kyuyeunk kyuyeunk added the ready ONLY add when PR is ready to merge/full CI is needed label Jan 29, 2026
@catswe

catswe commented Jan 29, 2026

Copy link
Copy Markdown
Contributor Author

The newly written unit test failed since bf16 input causes a jax.nn.sigmoid Pallas Mosaic lowering error. I already filed a fix PR here jax-ml/jax#34674. One workaround that works properly and passes the test is this

def apply_scoring_fn(scoring_fn: str, x):
    match scoring_fn:
        case "softmax":
            return jax.nn.softmax(x, axis=-1)
        case "sigmoid":
            # TODO(catswe): switch to jax.nn.sigmoid once bf16 Mosaic lowering bug is fixed
            ones = jnp.ones_like(x)
            return ones / (ones + jnp.exp(-x))
        case _:
            raise NotImplementedError(
                f"Unsupported scoring function: {scoring_fn}")

Let me know what direction we want to move towards (e.g., move forward with the workaround, or wait for the bug fix to land and upgrade Jax version)

@kyuyeunk

Copy link
Copy Markdown
Collaborator

The newly written unit test failed since bf16 input causes jax.nn.sigmoid Pallas Mosaic lowering error. I already filed a fix here jax-ml/jax#34674. One workaround that works properly and passes the test is this

def apply_scoring_fn(scoring_fn: str, x):
    match scoring_fn:
        case "softmax":
            return jax.nn.softmax(x, axis=-1)
        case "sigmoid":
            # TODO(catswe): switch to jax.nn.sigmoid once bf16 Mosaic lowering bug is fixed
            ones = jnp.ones_like(x)
            return ones / (ones + jnp.exp(-x))
        case _:
            raise NotImplementedError(
                f"Unsupported scoring function: {scoring_fn}")

Let me know what direction we want to move towards

thanks for identifying this issue! I'll run some tests myself as well and get back to you if i find anything.

@catswe

catswe commented Jan 30, 2026

Copy link
Copy Markdown
Contributor Author

I pushed up a small change to manually implement sigmoid. jax.nn.sigmoid Pallas Mosaic lowering uses the same 1 / (1 + exp(-x)) formula, although there's a bug with bf16 input. I added a TODO to use jax.nn.sigmoid once the lowering bug is fixed and Jax version is updated

Edit: Apologies for the mass reviewers ping. Messed up my force push 😅

Signed-off-by: catswe <212922539+catswe@users.noreply.github.com>
@catswe
catswe force-pushed the support_sigmoid_scoring branch from 5ac93c6 to b518d92 Compare January 30, 2026 20:32
@kyuyeunk

kyuyeunk commented Feb 2, 2026

Copy link
Copy Markdown
Collaborator

I pushed up a small change to manually implement sigmoid. jax.nn.sigmoid Pallas Mosaic lowering uses the same 1 / (1 + exp(-x)) formula, although there's a bug with bf16 input. I added a TODO to use jax.nn.sigmoid once the lowering bug is fixed and Jax version is updated

Edit: Apologies for the mass reviewers ping. Messed up my force push 😅

just ran a quick test with latest jax version and it still triggered error. so current approach seems good to me. current approach of manually implementing sigmoid lgtm. thank you for the contribution!

@kyuyeunk
kyuyeunk merged commit 6150b36 into vllm-project:main Feb 2, 2026
29 checks passed
@catswe
catswe deleted the support_sigmoid_scoring branch February 6, 2026 05:23
lorriexingfang pushed a commit to lorriexingfang/tpu-inference that referenced this pull request Feb 26, 2026
Signed-off-by: catswe <212922539+catswe@users.noreply.github.com>
Signed-off-by: Xing Fang <xing.fang@anyscale.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ready ONLY add when PR is ready to merge/full CI is needed

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants