Skip to content

One shape-agnostic entry per op: callers should not import shape packages #11

Open

Description

@benenzhu

Callers (vLLM) should not need to know which shape package serves a call. Today that holds for the dense MXFP8 GEMM only.

Where it holds. vLLM calls gemm/mxfp8_common (mxfp8_linear, mxfp8_gemm_prequant) with tensors. The entry reads (N, K) from the weight and routes to the shape's folder gemm/mxfp8_n<N>_k<K> (_SHAPE_HOSTS, #9). tuned_shapes() tells the caller which shapes are covered.

Where it does not. Other packages are imported by their shape path, for example amd_kernels.gemm.mxfp8_bmm_mxfp8_out_n1024_k4096 (#7) or amd_kernels.norm.gemma_rmsnorm_bf16_mxfp8_h6144.host. Another model's shape, or another TP size, then needs a code change in vLLM.

Proposal. One entry per op contract:

  • it takes tensors and reads the shape from them;
  • it routes to the shape package (the packages stay as they are, one per shape);
  • for a call no package covers, it returns a reason, and the caller falls back to its own path.

The batched MXFP8 GEMM with MXFP8 output (#7) could be the first one, e.g. mxfp8_bmm(x, x_scale, w, w_scale, ...) in front of gemm/mxfp8_bmm_mxfp8_out_n1024_k4096. Related: #4 (a provider's select(op, args, kwargs) could sit on the same entries).

Activity

  1. Fangzhou-Ai commented on Nov 21, 2026

    @Fangzhou-Ai
    Collaborator

    PR #10 now follows this: each Kimi-K3.1 op has one shape-agnostic entry, and the shape packages are unchanged. Head is 5659622.

    The entries follow the gemm/mxfp8_common pattern:

    • Routing: a _SHAPE_HOSTS table maps a key read from tensor dims (plus the world size for communicating kernels) to a
      shape-package module string. importlib loads that package on the first call of its key.
    • Fallback: <op>_unsupported_reason takes the op's arguments. It returns None or a one-line reason, host-only and
      safe in graph capture. Off the table, <op> raises ValueError with the same text.
    • Coverage: <op>_shapes() lists the covered keys.
    • Factories (*_comm / *_workspace / *_runner) take the key dims as keywords and read the world size from the
      group.

    Entry packages (amd_kernels. ...):

    • sampling.top_p_mask_common: top_p_mask. Routes to top_p_mask_f32_v163840 and upstream top_p_mask_f32_v200064.
    • sampling.markov_gumbel_common: markov_gumbel_fused
    • embedding.vocab_gather_common: vocab_gather_comm. Routes to vocab_gather_h7168_v163840_ranks8 and upstream
      vocab_gather_h6144 (2 / 4 ranks).
    • attention.kda_common: kda_decode_fb_gate_spec, kda_prefill, kda_mono_decode
    • attention.mla_decode_common: qkv_a_norm_kv_insert, indexer_prep, q_bproj_wuk_gather, fp8_sparse_mla_decode,
      lse_combine_vup, fp8_dense_mla_decode
    • indexer.mxfp4_indexer_common: mxfp4_paged_score_topk, mxfp4_prefill_score, mxfp4_prefill_topk
    • collectives.topk_gather_merge_common: topk_gather_merge_comm
    • collectives.logits_exchange_common: logits_exchange_comm (gemm_exchange)
    • moe.latent_moe_common: router_sigmoid_bias_topk, mxfp4_moe_experts, allreduce_latent_rmsnorm_up_proj,
      allreduce_slots_rmsnorm_up_proj, layer_tail_launch
    • norm.attnres_rmsnorm_common: attnres_comm (allreduce_attnres_rmsnorm)
    • gemm.bf16_common: bf16_latent_down_mxfp4_quant, bf16_linear_gather
    • decoder.bf16_dense_mlp_common: bf16_dense_mlp

    The PR body's "Entries (issue #11)" table lists each op's routed packages and reason functions.

    Our vLLM integration now imports only these entries, with no shape package. Its c16 gsm8k smoke (250 questions, real
    acceptance) matched the stock reference: 98.8%, acceptance length 3.628.

    Not part of this PR:

    🤖 Generated with Claude Code

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions