-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Dml dev #3347
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. Weβll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Dml dev #3347
Changes from all commits
6ac5b70
cd330f1
1ce1d43
057c1d4
a9ffab1
4c6a85f
2b90e4a
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -21,6 +21,7 @@ | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| """ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| import argparse | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| import copy | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| import os | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| import shutil | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| from itertools import product | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
@@ -110,6 +111,90 @@ | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| from .jit.xqa import gen_xqa_module, gen_xqa_module_mla | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| def get_default_config(): | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| """Get the full upstream AOT configuration.""" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| return { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| "fa2_head_dim": [(64, 64), (128, 128), (256, 256)], | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| "fa3_head_dim": [(192, 128), (128, 128), (64, 64), (256, 256)], | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| "f16_dtype": [torch.float16, torch.bfloat16], | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| "f8_dtype": [torch.float8_e4m3fn], | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| "use_sliding_window": [False, True], | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| "use_logits_soft_cap": [False, True], | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| "add_comm": True, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| "add_gemma": True, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| "add_oai_oss": True, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| "add_moe": True, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| "add_act": True, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| "add_misc": True, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| "add_xqa": True, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| def get_edge_fm_fast_config(): | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| """ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Get the trimmed AOT configuration used for fast local builds in edge-fm. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| This keeps only the kernels currently exercised in the repo: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| - single/batch prefill/decode attention on common 64/128 head dims | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| - activation / norm / rope / page / sampling / topk helpers | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| It intentionally excludes heavyweight optional families such as XQA, MoE, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| communication kernels, FP8 attention variants, and large head-dim matrices | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| that are not used in edge-fm today. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| """ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| return { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| "fa2_head_dim": [(64, 64), (128, 128)], | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| "fa3_head_dim": [(64, 64), (128, 128)], | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| "f16_dtype": [torch.float16, torch.bfloat16], | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| "f8_dtype": [], | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+139
to
+149
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The logic for determining the default build profile (checking for CI environments to decide between "full" and "edge_fm") is currently duplicated in
Suggested change
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| "use_sliding_window": [False], | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| "use_logits_soft_cap": [False], | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| "add_comm": False, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| "add_gemma": False, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| "add_oai_oss": False, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| "add_moe": False, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| "add_act": True, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| "add_misc": True, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| "add_xqa": False, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| def normalize_build_profile(profile: Optional[str]) -> str: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| profile_name = (profile or os.environ.get("FLASHINFER_AOT_BUILD_PROFILE") or "full") | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| profile_name = profile_name.strip().lower().replace("-", "_") | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| aliases = { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| "default": "full", | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| "minimal": "edge_fm", | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| "fast": "edge_fm", | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| "dev": "edge_fm", | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| "edgefm": "edge_fm", | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| return aliases.get(profile_name, profile_name) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| def get_config_for_profile(profile: Optional[str]) -> dict: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| normalized = normalize_build_profile(profile) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| if normalized == "full": | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| return get_default_config() | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| if normalized == "edge_fm": | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| return get_edge_fm_fast_config() | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| raise ValueError( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| f"Unknown FLASHINFER AOT build profile: {profile!r}. " | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| "Supported values: full, edge_fm." | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| def resolve_build_config( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| config: Optional[dict] = None, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| profile: Optional[str] = None, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ) -> Tuple[str, dict]: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| normalized = normalize_build_profile(profile) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| final_config = copy.deepcopy(get_config_for_profile(normalized)) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| if config is not None: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| final_config.update(config) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| return normalized, final_config | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| def gen_fa2( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| dtype_qo: torch.dtype, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| dtype_kv: torch.dtype, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
@@ -750,6 +835,7 @@ def compile_and_package_modules( | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| build_dir: Path, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| project_root: Path, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| config: dict = None, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| profile: Optional[str] = None, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| verbose: bool = False, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| skip_prebuilt: bool = True, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ) -> None: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
@@ -764,11 +850,7 @@ def compile_and_package_modules( | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| verbose: Whether to print verbose build output | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| skip_prebuilt: Whether to skip pre-built modules | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| """ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| # Start with default config and override with user config | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| final_config = get_default_config() | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| if config is not None: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| final_config.update(config) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| config = final_config | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| build_profile, config = resolve_build_config(config, profile) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| # Cuda Arch | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| if "FLASHINFER_CUDA_ARCH_LIST" not in os.environ: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| raise RuntimeError("Please explicitly set env var FLASHINFER_CUDA_ARCH_LIST.") | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
@@ -797,6 +879,7 @@ def compile_and_package_modules( | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| if out_dir is not None: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| print(" out_dir:", out_dir) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| print(" build_dir:", build_dir) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| print(" build_profile:", build_profile) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| print(" fa2_head_dim:", config["fa2_head_dim"]) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| print(" fa3_head_dim:", config["fa3_head_dim"]) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| print(" f16_dtype:", config["f16_dtype"]) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
@@ -865,25 +948,6 @@ def parse_head_dim(head_dim: str) -> Tuple[int, int]: | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| return qo, kv | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| def get_default_config(): | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| """Get default AOT configuration""" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| return { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| "fa2_head_dim": [(64, 64), (128, 128), (256, 256)], | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| "fa3_head_dim": [(192, 128), (128, 128), (64, 64), (256, 256)], | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| "f16_dtype": [torch.float16, torch.bfloat16], | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| "f8_dtype": [torch.float8_e4m3fn], | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| "use_sliding_window": [False, True], | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| "use_logits_soft_cap": [False, True], | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| "add_comm": True, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| "add_gemma": True, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| "add_oai_oss": True, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| "add_moe": True, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| "add_act": True, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| "add_misc": True, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| "add_xqa": True, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| def detect_sm_capabilities(): | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| """Detect SM capabilities""" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| compilation_context = CompilationContext() | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
@@ -914,9 +978,9 @@ def has_sm(compute: str, version: str) -> bool: | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| def register_default_modules() -> int: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| def register_default_modules(profile: Optional[str] = None) -> int: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| """Register the default set of modules""" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| config = get_default_config() | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| _, config = resolve_build_config(profile=profile) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| sm_capabilities = detect_sm_capabilities() | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| jit_specs = gen_all_modules( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
@@ -942,6 +1006,11 @@ def main(): | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| parser = argparse.ArgumentParser( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| description="Ahead-of-Time (AOT) build all modules" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| parser.add_argument( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| "--profile", | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| help="AOT build profile (full or edge_fm). " | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| "Aliases: dev/fast/minimal -> edge_fm", | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| parser.add_argument("--out-dir", type=Path, help="Output directory") | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| parser.add_argument("--build-dir", type=Path, help="Build directory") | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| parser.add_argument( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
@@ -995,7 +1064,7 @@ def main(): | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| # Start with default configuration | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| project_root = Path(__file__).resolve().parents[1] | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| config = get_default_config() | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| build_profile, config = resolve_build_config(profile=args.profile) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| build_dir = jit_env.FLASHINFER_WORKSPACE_DIR | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| out_dir: Optional[Path] = None | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
@@ -1038,6 +1107,7 @@ def main(): | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| build_dir=build_dir, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| project_root=project_root, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| config=config, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| profile=build_profile, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| verbose=True, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| skip_prebuilt=False, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -270,6 +270,23 @@ __global__ void SingleDecodeWithKVCacheKernel(const __grid_constant__ Params par | |
| block.sync(); | ||
|
|
||
| uint32_t chunk_start = kv_chunk_idx * kv_chunk_size; | ||
| // Early-exit for blocks beyond the actual sequence length. This happens | ||
| // when the grid is sized for max_kv_len (CUDA graph) but the real kv_len | ||
| // is shorter. Write zero output and very-negative lse so MergeStates | ||
| // treats this chunk as having no contribution. | ||
| if (chunk_start >= seq_len) { | ||
| if (tz == 0) { | ||
| DTypeO* o_ptr = o + (kv_chunk_idx * num_qo_heads + qo_head_idx) * head_dim + tx * vec_size; | ||
| #pragma unroll | ||
| for (uint32_t i = 0; i < vec_size; ++i) { | ||
| o_ptr[i] = DTypeO(0); | ||
| } | ||
| if (lse != nullptr && tx == 0) { | ||
| lse[kv_chunk_idx * num_qo_heads + qo_head_idx] = -5e4; | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The magic number |
||
| } | ||
| } | ||
| return; | ||
| } | ||
| kv_chunk_size = min(kv_chunk_size, seq_len - chunk_start); | ||
| uint32_t chunk_end = chunk_start + kv_chunk_size; | ||
|
|
||
|
|
@@ -628,6 +645,15 @@ constexpr uint32_t get_heuristic_num_threads(uint32_t group_size, uint32_t sizeo | |
| } else { | ||
| return 512U; | ||
| } | ||
| } else if (group_size == 6U) { | ||
| // GQA=6 on sm80 otherwise falls back to a 96-thread CTA (bdz=1), which | ||
| // leaves very little room to hide the decode kernel's memory latency. | ||
| return 288U; | ||
| } else if (group_size == 7U) { | ||
| // GQA=7 has the same problem as GQA=6 on sm80: the default 128-thread CTA | ||
| // only yields bdz=1 for head_dim=128. Use a larger CTA so group_size=7 | ||
| // can keep multiple z-slices in flight and avoid the slow fallback path. | ||
| return 336U; | ||
| } else { | ||
| return 128U; | ||
| } | ||
|
|
@@ -664,7 +690,9 @@ cudaError_t SingleDecodeWithKVCacheDispatched(Params params, typename Params::DT | |
| using DTypeO = typename Params::DTypeO; | ||
| const uint32_t num_qo_heads = params.num_qo_heads; | ||
| const uint32_t num_kv_heads = params.num_kv_heads; | ||
| const uint32_t seq_len = params.kv_len; | ||
| // When max_kv_len is set (CUDA graph mode), use it for grid sizing so that | ||
| // the grid topology stays fixed across replays with different actual kv_len. | ||
| const uint32_t seq_len = (params.max_kv_len > 0) ? params.max_kv_len : params.kv_len; | ||
|
|
||
| constexpr uint32_t vec_size = std::max(16UL / sizeof(DTypeKV), HEAD_DIM / 32UL); | ||
| constexpr uint32_t bdx = HEAD_DIM / vec_size; | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This logic for determining the default build profile is duplicated. If
normalize_build_profileinflashinfer/aot.pyis updated to handle CI-aware defaults, this block can be simplified to rely on that centralized logic.