b12x_next-compact-n64-m64.patch 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839
  1. diff -ru b12x_next/moe/fused_moe/_tuning.py b12x_next/moe/fused_moe/_tuning.py
  2. --- b12x_next/moe/fused_moe/_tuning.py 2026-09-24 18:47:49
  3. +++ b12x_next/moe/fused_moe/_tuning.py 2026-09-24 18:47:49
  4. @@ -250,6 +250,19 @@
  5. )
  6. +# ds41 patch (b12x_next only): compact N64 (N % 128 == 64) W4A8 admits the M64 tile for prefill-sized
  7. +# capacities. Decode capacities stay on M16; the heuristic still selects M16 everywhere, so M64 runs
  8. +# only through an explicit override. M32 is NOT admitted: its fused n64 path returns wrong results
  9. +# (rel-L2 1.37 vs the M16 path, 2026-09-24 Spark_02).
  10. +_COMPACT_N64_M64_MIN_TOKENS = 128
  11. +
  12. +
  13. +def _compact_n64_tiles(query):
  14. + if query.num_tokens >= _COMPACT_N64_M64_MIN_TOKENS:
  15. + return (16, 64)
  16. + return (16,)
  17. +
  18. +
  19. def _compact_w4a8_query(query):
  20. return (
  21. query.quant_mode == "w4a8_mx"
  22. @@ -346,9 +359,13 @@
  23. if (
  24. query.quant_mode == "w4a8_mx" and query.source_format == "fp4_e8m0_k32"
  25. and query.intermediate_size % 128 == 64 and config.backend == "dynamic"
  26. - and (config.dynamic_tile_m != 16 or config.dynamic_route_mode != "grouped")
  27. + and (config.dynamic_tile_m not in _compact_n64_tiles(query)
  28. + or config.dynamic_route_mode != "grouped")
  29. ):
  30. - raise ValueError("compact N64 W4A8 dynamic execution requires grouped M16 routing")
  31. + raise ValueError(
  32. + "compact N64 W4A8 dynamic execution requires grouped M16 routing "
  33. + f"(M64 from {_COMPACT_N64_M64_MIN_TOKENS} tokens)"
  34. + )
  35. if config.backend not in {"micro", "dynamic", "w4a16"}:
  36. raise ValueError(f"unsupported MoE backend {config.backend!r}")
  37. if query.quant_mode == "w4a16":