b12x-prewarm-tolerance.patch 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147
  1. --- a/vllm/model_executor/layers/sparse_attn_indexer.py
  2. +++ b/vllm/model_executor/layers/sparse_attn_indexer.py
  3. @@ -12,6 +12,9 @@
  4. from vllm.config import CUDAGraphMode
  5. from vllm.forward_context import get_forward_context
  6. from vllm.model_executor.custom_op import CustomOp
  7. +from vllm.logger import init_logger
  8. +
  9. +logger = init_logger(__name__)
  10. from vllm.platforms import current_platform
  11. from vllm.triton_utils import HAS_TRITON, tl, triton
  12. from vllm.utils.import_utils import has_deep_gemm
  13. @@ -1238,49 +1241,73 @@
  14. dcp_rank,
  15. cp_kv_cache_interleave_size,
  16. ) = _get_dcp_warmup_params()
  17. - _prewarm_b12x_paged_indexer_prefill(
  18. - q_quant=q_quant,
  19. - weights=weights,
  20. - kv_cache=kv_cache,
  21. - topk_tokens=int(topk_tokens),
  22. - profile_q_rows=profile_q_rows,
  23. - profile_k_rows=warmup_k_rows,
  24. - page_table_k_rows=profile_k_rows,
  25. - )
  26. - if dcp_world_size > 1:
  27. - dcp_profile_k_rows = _get_dcp_local_k_rows(
  28. - profile_k_rows,
  29. - dcp_world_size,
  30. - dcp_rank,
  31. - cp_kv_cache_interleave_size,
  32. - )
  33. - dcp_warmup_k_rows = _get_b12x_paged_indexer_profile_warmup_k_rows(
  34. - dcp_profile_k_rows
  35. + # glm52-gb10 patch (tony's NF3 fix pattern): on sm_121a some
  36. + # CuteDSL prewarm shapes fail atom_tma_partition ("Operation
  37. + # creation failed"). Prewarm is a precompile optimization only —
  38. + # tolerate per-variant failures and let runtime shapes compile
  39. + # on demand.
  40. + try:
  41. + _prewarm_b12x_paged_indexer_prefill(
  42. + q_quant=q_quant,
  43. + weights=weights,
  44. + kv_cache=kv_cache,
  45. + topk_tokens=int(topk_tokens),
  46. + profile_q_rows=profile_q_rows,
  47. + profile_k_rows=warmup_k_rows,
  48. + page_table_k_rows=profile_k_rows,
  49. )
  50. - if dcp_warmup_k_rows != warmup_k_rows:
  51. - _prewarm_b12x_paged_indexer_prefill(
  52. - q_quant=q_quant,
  53. - weights=weights,
  54. - kv_cache=kv_cache,
  55. - topk_tokens=int(topk_tokens),
  56. - profile_q_rows=profile_q_rows,
  57. - profile_k_rows=dcp_warmup_k_rows,
  58. - page_table_k_rows=dcp_profile_k_rows,
  59. + if dcp_world_size > 1:
  60. + dcp_profile_k_rows = _get_dcp_local_k_rows(
  61. + profile_k_rows,
  62. + dcp_world_size,
  63. + dcp_rank,
  64. + cp_kv_cache_interleave_size,
  65. )
  66. - _prewarm_b12x_dcp_topk_merge(
  67. - q_rows=profile_q_rows,
  68. - topk_tokens=int(topk_tokens),
  69. - dcp_world_size=dcp_world_size,
  70. - dcp_rank=dcp_rank,
  71. - cp_kv_cache_interleave_size=cp_kv_cache_interleave_size,
  72. - device=q_quant.device,
  73. - )
  74. - _prewarm_b12x_contiguous_prefill_variants(
  75. - q_quant=q_quant,
  76. - weights=weights,
  77. - topk_tokens=int(topk_tokens),
  78. - profile_q_rows=profile_q_rows,
  79. - )
  80. + dcp_warmup_k_rows = _get_b12x_paged_indexer_profile_warmup_k_rows(
  81. + dcp_profile_k_rows
  82. + )
  83. + if dcp_warmup_k_rows != warmup_k_rows:
  84. + _prewarm_b12x_paged_indexer_prefill(
  85. + q_quant=q_quant,
  86. + weights=weights,
  87. + kv_cache=kv_cache,
  88. + topk_tokens=int(topk_tokens),
  89. + profile_q_rows=profile_q_rows,
  90. + profile_k_rows=dcp_warmup_k_rows,
  91. + page_table_k_rows=dcp_profile_k_rows,
  92. + )
  93. + except Exception as _e:
  94. + logger.warning(
  95. + "glm52-gb10: b12x paged-indexer prewarm failed on this "
  96. + "platform (%s); continuing without precompiled variants.",
  97. + _e,
  98. + )
  99. + try:
  100. + _prewarm_b12x_dcp_topk_merge(
  101. + q_rows=profile_q_rows,
  102. + topk_tokens=int(topk_tokens),
  103. + dcp_world_size=dcp_world_size,
  104. + dcp_rank=dcp_rank,
  105. + cp_kv_cache_interleave_size=cp_kv_cache_interleave_size,
  106. + device=q_quant.device,
  107. + )
  108. + except Exception as _e:
  109. + logger.warning(
  110. + "glm52-gb10: b12x dcp topk-merge prewarm failed (%s); "
  111. + "continuing.", _e,
  112. + )
  113. + try:
  114. + _prewarm_b12x_contiguous_prefill_variants(
  115. + q_quant=q_quant,
  116. + weights=weights,
  117. + topk_tokens=int(topk_tokens),
  118. + profile_q_rows=profile_q_rows,
  119. + )
  120. + except Exception as _e:
  121. + logger.warning(
  122. + "glm52-gb10: b12x contiguous-prefill prewarm failed (%s); "
  123. + "continuing.", _e,
  124. + )
  125. else:
  126. # Reserve workspace for indexer during profiling run.
  127. current_workspace_manager().get_simultaneous(
  128. @@ -1830,6 +1857,19 @@
  129. self.max_model_len = max_model_len
  130. self.max_total_seq_len = max_total_seq_len
  131. self.topk_indices_buffer = topk_indices_buffer
  132. + if topk_scores_buffer is None and topk_indices_buffer is not None:
  133. + try:
  134. + from vllm.distributed.parallel_state import get_dcp_group
  135. +
  136. + dcp_world_size = get_dcp_group().world_size
  137. + except Exception:
  138. + dcp_world_size = 1
  139. + if dcp_world_size > 1 and use_b12x_sparse_indexer():
  140. + topk_scores_buffer = torch.empty(
  141. + topk_indices_buffer.shape,
  142. + dtype=torch.float32,
  143. + device=topk_indices_buffer.device,
  144. + )
  145. self.topk_scores_buffer = topk_scores_buffer
  146. self.skip_k_cache_insert = skip_k_cache_insert
  147. self.use_fp4_cache = use_fp4_cache