102 文件大包:attention 后端分发、tilelang_ops 算子库(cuda 25 / asc 33)、采样、量化、RoPE · 本组 102 个文件 · 25,098 行 · ast 提取 @ 774ce24 · 2026-10-21
模块综述——算子层的非 TileLang 部分 9 文件:attention_backend.py(147 行)prefill_attn_varlen_sparse/decode_mla_mqa_sparse 两个稀疏注意力入口(批不变路径也在其中);sampler.py(684 行)Sampler 全采样逻辑(top-p/top-k/惩罚/确定性);sampler_utils.py(197 行)prompt logprobs 分块计算;rotary_embedding.py(285 行)RoPE+YaRN 全套;linear.py(186 行)bf16_gemm_nt 与 FP8 cast 粒度;mtp_info_pool.py(79 行)MTP 提案的 GPU 常驻池(slot 0 留 padding);layernorm/vocab_parallel_embedding 是薄适配。
| 符号 | 行数 · 说明(ast 提取) | |
| _pad_attention_heads | 16 | 把 tensor 的 head 维补零到 FlashMLA 允许的头数;已支持时原样返回(第三个返回值为 None) |
| prefill_attn_varlen_sparse | 49 | Args: query: [total_q, num_heads_q, head_dim], bf16 kv_a_with_mqa: [total_k, 1, head_dim], bf16 |
| decode_mla_mqa_sparse | 70 | Args: query: [total_q, num_heads_q, head_dim], bf16 key_cache: [num_blocks, block_size, 1, bytes |
| (已列出全部 3 个顶层符号) | ||
| 符号 | 行数 · 说明(ast 提取) | |
| class RMSNorm | 50 | Root mean square normalization. Computes x -> w * x / sqrt(E[x^2] + eps) where w is the learned |
| └ __init__ | 16 | |
| └ forward | 26 | |
| (已列出全部 1 个顶层符号 + 2 个方法) | ||
| 符号 | 行数 · 说明(ast 提取) | |
| get_fp8_casting_granularity | 2 | |
| get_fp8_cast_params | 8 | |
| bf16_gemm_nt | 7 | |
| class ReplicatedLinear | 150 | Replicated linear layer. Args: input_size: input dimension of the linear layer. output_size: out |
| └ __init__ | 35 | |
| └ _allocate_output | 13 | |
| └ _has_aligned_output_stride | 3 | |
| └ _flatten_output | 7 | |
| └ _align_output | 6 | |
| └ apply_weight_bf16 | 23 | |
| └ apply_weight_fp8 | 27 | |
| └ apply_weight | 11 | |
| └ forward | 6 | |
| (已列出全部 4 个顶层符号 + 9 个方法) | ||
| 符号 | 行数 · 说明(ast 提取) | |
| get_nextn_pad_token_ids | 3 | Return placeholder draft token IDs matching pool slot 0. |
| class MTPInfoPool | 65 | Stable GPU storage for MTP proposals indexed by scheduler slots. Each slot owns ``nextn`` rows. |
| └ __init__ | 28 | |
| └ store | 25 | Store batched MTP predictions in their scheduler slots. ``logprobs`` a |
| (已列出全部 2 个顶层符号 + 2 个方法) | ||
| 符号 | 行数 · 说明(ast 提取) | |
| _build_cos_sin_cache | 7 | |
| class RotaryEmbedding | 63 | Original rotary positional embedding. |
| └ __init__ | 17 | |
| └ _compute_inv_freq | 9 | Compute the inverse frequency. |
| └ _compute_cos_sin_cache | 5 | Compute the cos and sin cache. |
| └ forward | 23 | |
| _yarn_find_correction_dim | 7 | |
| _yarn_find_correction_range | 10 | |
| _yarn_linear_ramp_mask | 13 | |
| yarn_get_mscale | 4 | |
| class YaRNScalingRotaryEmbedding | 66 | RotaryEmbedding extended with YaRN method. Credits to Peng et al. github.com/jquesnelle/yarn |
| └ __init__ | 35 | |
| └ _compute_inv_freq | 24 | |
| get_rope | 61 | |
| (已列出全部 8 个顶层符号 + 6 个方法) | ||
| 符号 | 行数 · 说明(ast 提取) | |
| class Sampler | 625 | 从模型 hidden states 采样下一个 token,支持 MTP(Multi-Token Prediction)投机采样。 核心流程: 1. 取出需要采样的 hidden states |
| └ __init__ | 17 | |
| └ forward | 186 | |
| └ _get_so_mask | 107 | TODO 暂定每一轮固定预测 max MTP value 个,只验证 cur step MTP value 个 |
| └ _verification | 185 | |
| └ _prefill_golden_gen | 38 | Prefill 路径的采样(golden 覆盖、top info、sum_smaller_probs);decode(含 nextn=0)走 |
| └ _prepare_top_info | 13 | |
| └ _update_golden_tokens | 34 | 对 flat sample result 应用 golden token,并还原 force-topk token id。 golden_o |
| (已列出全部 1 个顶层符号 + 7 个方法) | ||
| 符号 | 行数 · 说明(ast 提取) | |
| get_logits | 9 | |
| split_prompt_logprobs | 19 | Split the flat prompt-logprob result back into requests. |
| _compute_prompt_logprobs_chunk | 27 | |
| compute_prompt_logprobs | 30 | Compute prompt logprobs in bounded chunks; only CP rank 0 materializes the result. Every CP rank |
| process_sampling | 84 | Apply temperature, top-p/top-k and log-softmax, with optional sampling and MTP rejection. Args: |
| (已列出全部 5 个顶层符号) | ||
| 符号 | 行数 · 说明(ast 提取) | |
| candidate_block_max_tl | 218 | |
| get_candidate_compact_lens_tl | 50 | |
| restore_candidate_indices_inplace_tl | 68 | |
| (已列出全部 3 个顶层符号) | ||
| 符号 | 行数 · 说明(ast 提取) | |
| compress_and_update_state_prefill_tl | 189 | |
| compress_and_update_state_decode_tl | 204 | |
| (已列出全部 2 个顶层符号) | ||
| 符号 | 行数 · 说明(ast 提取) | |
| compute_seqlens_k_zos_tl | 45 | |
| (已列出全部 1 个顶层符号) | ||
| 符号 | 行数 · 说明(ast 提取) | |
| confidence_head_fused_tl | 83 | |
| dflash_input_store_tl | 48 | |
| (已列出全部 2 个顶层符号) | ||
| 符号 | 行数 · 说明(ast 提取) | |
| copy_dflash_decode_input_tl | 115 | Fill the DFlash graph's per-request inputs: rows [0, src_req_cnt) from src, the rest from paddin |
| (已列出全部 1 个顶层符号) | ||
| 符号 | 行数 · 说明(ast 提取) | |
| convert_kv_index_tl | 40 | |
| (已列出全部 1 个顶层符号) | ||
| 符号 | 行数 · 说明(ast 提取) | |
| _get_lse_block_size | 9 | |
| accumulate_search_chunk | 52 | |
| fused_sample_tl | 591 | 融合 temperature-softmax、top-p/top-k 过滤及 sampling/reject sampling |
| (已列出全部 3 个顶层符号) | ||
| 符号 | 行数 · 说明(ast 提取) | |
| _fused_norm_rope_hadamard_cast_store_kvcache_kernel | 705 | Branch SIMD pipeline with the missing reference stages/extensions. |
| fused_norm_rope_hadamard_cast_store_kvcache_tl | 161 | Translate the shared public ABI into branch compile-time descriptors. |
| (已列出全部 2 个顶层符号) | ||
| 符号 | 行数 · 说明(ast 提取) | |
| gather_tl | 92 | Args: D: row length in elements (== row bytes when dtype is int8) dtype: x/y element dtype (torc |
| (已列出全部 1 个顶层符号) | ||
| 符号 | 行数 · 说明(ast 提取) | |
| gather_engram_tokens_zos_tl | 117 | |
| (已列出全部 1 个顶层符号) | ||
| 符号 | 行数 · 说明(ast 提取) | |
| gather_input_ids_zos_tl | 73 | |
| (已列出全部 1 个顶层符号) | ||
| 符号 | 行数 · 说明(ast 提取) | |
| load_kv_index_tl | 100 | |
| get_fused_dflash_get_input_tl | 149 | Build the fixed-stride draft-token inputs of every request. ftp < 0 marks a padding request: its |
| (已列出全部 2 个顶层符号) | ||
| 符号 | 行数 · 说明(ast 提取) | |
| replace_input_embeds_tl | 120 | Ascend NPU: in-place fill of multimodal embeddings. One vector core per batch of ``B`` consecuti |
| rgb_pad_to_patches_tl | 94 | Ascend NPU: concatenated plain RGB (HWC uint8) pixel data -> normalized bf16 patch tensors, cent |
| batch_downsample_tl | 153 | Ascend NPU: d x d spatial pooling / concatenation of ViT patch features. One output patch per pe |
| (已列出全部 3 个顶层符号) | ||
| 符号 | 行数 · 说明(ast 提取) | |
| kv_index_cat_tl | 63 | Ascend kernel: out[:, :window_size] = kv_index; out[:, window_size:] = kv_ca_index + total_k_swa |
| (已列出全部 1 个顶层符号) | ||
| 符号 | 行数 · 说明(ast 提取) | |
| build_reciprocal_table | 14 | Build the reciprocal lookup table in one vector register. |
| make_kv_scale_impl | 47 | Encode group maxima and return their exact FP32 inverse scales. |
| make_kv_quant_impl | 100 | Build macros consuming two fp32 registers holding 128 BF16 values. ``compute_scales`` returns an |
| (已列出全部 3 个顶层符号) | ||
| 符号 | 行数 · 说明(ast 提取) | |
| load_paged_kv_cache_tl | 329 | |
| (已列出全部 1 个顶层符号) | ||
| 符号 | 行数 · 说明(ast 提取) | |
| load_pair | 8 | |
| pack_bf16 | 3 | |
| store_pair | 6 | |
| _tile_rows | 12 | |
| norm_tl | 378 | |
| (已列出全部 5 个顶层符号) | ||
| 符号 | 行数 · 说明(ast 提取) | |
| prepare_cp_mirror_tl | 313 | Ascend NPU - one fused kernel: hierarchical prefix sums + scatter. A single grid-extent launch w |
| yoco_cp_boundary_fused_tl | 182 | Ascend NPU - prepare YOCO full-to-compact CP redistribution indices. Phase 1 builds per-rank kep |
| (已列出全部 2 个顶层符号) | ||
| 符号 | 行数 · 说明(ast 提取) | |
| copy_block_tables_tl | 54 | |
| prepare_v4_decode_metadata_tl | 180 | |
| (已列出全部 2 个顶层符号) | ||
| 符号 | 行数 · 说明(ast 提取) | |
| class Config | 36 | Compile-time layout for two-level sampling. Fold `bd`-column chunks into `acc_slots` sums indexe |
| └ n_chunks | 2 | |
| └ n_slots | 2 | |
| └ n_slots_aligned | 2 | |
| └ n_slots_threads | 2 | |
| └ scale | 2 | |
| accumulate | 32 | |
| inclusive_scan | 31 | Scan integer prefixes in place over a multiple of 64 elements inside T.SimdVF(). Carry sums acro |
| locate | 8 | |
| sample_offset | 6 | |
| sample_select | 15 | |
| draw_random | 17 | |
| random_sampling_tl | 76 | Build an Ascend two-level fixed-point sampler (see Config). Encode weights at scale 2**31 and fo |
| (已列出全部 8 个顶层符号 + 5 个方法) | ||
| 符号 | 行数 · 说明(ast 提取) | |
| split_fp32 | 5 | Split a Python float into two FP32 values whose sum approximates it. |
| naive_rsqrt | 3 | Compute reciprocal square root directly with FP32 SIMD operations. |
| compensated_rsqrt | 20 | Refine an rsqrt estimate against the high and low parts of its input. |
| compensated_div_add | 22 | Return high and low parts of a / c0 + c1. |
| make_rstd_impl | 19 | Build RSTD with compensated input construction and a naive rsqrt estimate. |
| (已列出全部 5 个顶层符号) | ||
| 符号 | 行数 · 说明(ast 提取) | |
| prepare_verification_metadata_tl | 56 | |
| expand_sampling_params_tl | 35 | |
| map_lookup_tl | 74 | |
| remap_draft_topk_tl | 107 | |
| get_accept_result_tl | 50 | |
| finalize_verification_tl | 285 | |
| (已列出全部 6 个顶层符号) | ||
| 符号 | 行数 · 说明(ast 提取) | |
| compute_seqlens_q_by_confidence_rates_tl | 106 | |
| (已列出全部 1 个顶层符号) | ||
| 符号 | 行数 · 说明(ast 提取) | |
| _state_cache_copy_tl | 55 | |
| select_state_slice_tl | 7 | |
| load_state_to_cache_tl | 7 | |
| (已列出全部 3 个顶层符号) | ||
| 符号 | 行数 · 说明(ast 提取) | |
| store_kv_cache_tl | 284 | Build a store: BF16 input[n,D], uint8 cache[pages,B,bytes], int32 slots[n]. Plain BF16 uses a BF |
| (已列出全部 1 个顶层符号) | ||
| 符号 | 行数 · 说明(ast 提取) | |
| store_mtp_info_tl | 59 | |
| (已列出全部 1 个顶层符号) | ||
| 符号 | 行数 · 说明(ast 提取) | |
| apply_token_bitmask_by_step_inplace_tl | 86 | |
| (已列出全部 1 个顶层符号) | ||
| 符号 | 行数 · 说明(ast 提取) | |
| sum_smaller_probs_tl | 85 | |
| (已列出全部 1 个顶层符号) | ||
| 符号 | 行数 · 说明(ast 提取) | |
| expand_swa_index_tl | 51 | |
| (已列出全部 1 个顶层符号) | ||
| 符号 | 行数 · 说明(ast 提取) | |
| class KVCacheFormat | 82 | Logical and physical contents of one token in a KV cache. ``sf_format`` describes the encoded sc |
| └ __post_init__ | 11 | |
| └ num_elements | 2 | |
| └ quantized_bytes | 5 | |
| └ num_scales | 4 | |
| └ sf_dtype | 8 | Physical dtype of one scale factor, or None for an unscaled cache. |
| └ sf_element_size | 2 | |
| └ sf_bytes | 3 | Number of physical scale-factor bytes stored for each token. |
| └ sf_storage_elements | 5 | |
| └ bytes_per_token | 2 | |
| └ stride_alignment | 3 | Data token-stride alignment in bytes, capped by the shared block's 32B |
| get_kv_cache_format | 17 | Infer a KV-cache format, using ``sf_format`` to resolve ambiguous byte layouts. |
| resolve_kv_cache_layout | 22 | Infer a cache layout and validate an explicitly supplied one. |
| class KVCacheTensors | 4 | 0 个方法 |
| alloc_kv_load_output | 33 | Allocate the natural load result for a cache format. |
| alloc_kv_cache | 18 | Allocate block-aligned byte storage for a quantized paged cache. |
| sf_data_as_int32 | 8 | View packed UE8M0 scale bytes in the int32 form used by load kernels. |
| fp4_cache_kernel_kwargs | 9 | Return logical FP4 value/scale strides for TileLang factories. |
| split_kv_cache | 33 | Return block size and typed views of a paged KV cache's sections. |
| ref_cast_from_bf16 | 27 | Reference cast from BF16 values to the three logical cache sections. |
| ref_cast_to_bf16 | 25 | Reference cast from the three logical cache sections back to BF16. |
| _supported_test_layout | 2 | |
| kv_cache_benchmark_operation | 9 | |
| kv_cache_benchmark_id | 3 | |
| test_main_cache_layout | 18 | Main descriptors cannot opt back into block-wide sections or a BF16 tail. |
| test_reject_mixed_cache_shape | 5 | Former mixed main-cache byte widths must not resolve to a current format. |
| (已列出全部 16 个顶层符号 + 10 个方法) | ||
| 符号 | 行数 · 说明(ast 提取) | |
| candidate_block_max | 37 | Compute block scores and valid block counts for candidate selection. Each score is the maximum v |
| candidate_block_max_ref | 24 | Return unpadded [num_rows, num_blocks] scores and [num_rows] valid counts. |
| get_candidate_compact_lens | 24 | Return compact token counts for the selected candidate blocks. Args: candidate_blocks: [num_rows |
| get_candidate_compact_lens_ref | 9 | |
| restore_candidate_indices_inplace | 40 | Restore compact token indices to sequence-local or gathered indices in place. Args: compact_indi |
| restore_candidate_indices_inplace_ref | 16 | |
| _check_inputs | 8 | |
| test_candidate_block_max | 12 | |
| test_restore_candidate_indices_inplace | 12 | |
| test_get_candidate_compact_lens | 7 | |
| test_candidate_block_max_benchmark | 31 | |
| test_get_candidate_compact_lens_benchmark | 23 | |
| test_restore_candidate_indices_inplace_benchmark | 35 | |
| (已列出全部 13 个顶层符号) | ||
| 符号 | 行数 · 说明(ast 提取) | |
| is_power_of_two | 2 | |
| ceil_div | 2 | |
| align | 2 | |
| customized_finfo_amax | 7 | |
| (已列出全部 4 个顶层符号) | ||
| 符号 | 行数 · 说明(ast 提取) | |
| _enable_fast_math | 4 | compress 内核固定开启 fast math |
| compress_and_update_state_prefill | 52 | Args: score: [total_q | cp_size * cp_mirror_len, dim], fp32 latent: [total_q | cp_size * cp_mirr |
| compress_and_update_state_decode | 43 | Args: score: [total_q, dim], fp32 latent: [total_q, dim], fp32 state_cache: [num_state_slots, st |
| _get_cuseqlen | 2 | |
| _make_compressed_meta | 9 | Build (cu_compressed_seqlens_q, compressed_batch_mapping); each seq reserves >= 1 entry. |
| _make_strided_state_cache | 7 | Random state_cache carved out of a bigger per-slot buffer, so that stride(0) exceeds the state r |
| compress_and_update_state_prefill_ref | 65 | |
| compress_and_update_state_decode_ref | 37 | |
| _test_compress_state_prefill | 95 | Test the prefill compress kernel against the Python reference. prefill_store_extra_size > 0 sele |
| _test_compress_state_decode | 68 | |
| test_compress_state_prefill | 7 | |
| test_compress_state_decode | 8 | |
| _make_prefill_bench_inputs | 40 | |
| test_compress_prefill_benchmark | 51 | |
| _make_decode_bench_inputs | 31 | |
| test_compress_decode_benchmark | 47 | |
| (已列出全部 16 个顶层符号) | ||
| 符号 | 行数 · 说明(ast 提取) | |
| compute_seqlens_k_zos | 23 | Compute seqlens_k for ZOS decode step (in-place on GPU). Fuses into a single kernel: seqlens_k[i |
| compute_seqlens_k_zos_ref | 18 | Reference: original Python implementation from _compute_seqlens_k. |
| test_compute_seqlens_k_zos | 32 | |
| test_compute_seqlens_k_zos_bench | 29 | |
| (已列出全部 4 个顶层符号) | ||
| 符号 | 行数 · 说明(ast 提取) | |
| _bind_worker_gpu | 14 | Bind each xdist worker to a GPU via CUDA_VISIBLE_DEVICES. Mirrors the old pytest_benchmark_plugi |
| pytest_collect_file | 24 | Collect test files directly under tilelang_ops/ so the directory can be passed to pytest directl |
| pytest_runtest_call | 13 | Skip tests hitting kernels the selected backend has not implemented. ops.KernelUnavailableError |
| (已列出全部 3 个顶层符号) | ||
| 符号 | 行数 · 说明(ast 提取) | |
| candidate_block_max_tl | 108 | |
| get_candidate_compact_lens_tl | 36 | |
| restore_candidate_indices_inplace_tl | 44 | |
| (已列出全部 3 个顶层符号) | ||
| 符号 | 行数 · 说明(ast 提取) | |
| _num_threads | 4 | Round a per-thread work target to a power-of-two number of full warps. |
| _compute_dim_block | 9 | Return (DIM_BLOCK, NUM_DIM_BLOCKS, threads) for C1/C2 compute. Use power-of-two tiles that divid |
| compress_and_update_state_prefill_tl | 147 | |
| compress_and_update_state_decode_tl | 106 | |
| (已列出全部 4 个顶层符号) | ||
| 符号 | 行数 · 说明(ast 提取) | |
| compute_seqlens_k_zos_tl | 24 | |
| (已列出全部 1 个顶层符号) | ||
| 符号 | 行数 · 说明(ast 提取) | |
| confidence_head_fused_tl | 61 | |
| dflash_input_store_tl | 38 | |
| (已列出全部 2 个顶层符号) | ||
| 符号 | 行数 · 说明(ast 提取) | |
| copy_dflash_decode_input_tl | 70 | Fill the DFlash graph's per-request inputs: rows [0, src_req_cnt) from src, the rest from paddin |
| (已列出全部 1 个顶层符号) | ||
| 符号 | 行数 · 说明(ast 提取) | |
| convert_kv_index_tl | 28 | |
| (已列出全部 1 个顶层符号) | ||
| 符号 | 行数 · 说明(ast 提取) | |
| fused_sample_tl | 506 | |
| (已列出全部 1 个顶层符号) | ||
| 符号 | 行数 · 说明(ast 提取) | |
| fused_norm_rope_hadamard_cast_store_kvcache_tl | 603 | Build an optional norm -> RoPE -> Hadamard -> quantize pipeline. |
| (已列出全部 1 个顶层符号) | ||
| 符号 | 行数 · 说明(ast 提取) | |
| gather_tl | 56 | |
| (已列出全部 1 个顶层符号) | ||
| 符号 | 行数 · 说明(ast 提取) | |
| gather_engram_tokens_zos_tl | 64 | |
| (已列出全部 1 个顶层符号) | ||
| 符号 | 行数 · 说明(ast 提取) | |
| gather_input_ids_zos_tl | 34 | |
| (已列出全部 1 个顶层符号) | ||
| 符号 | 行数 · 说明(ast 提取) | |
| load_kv_index_tl | 52 | Expand per-row (offset, len) into kv index rows; columns >= len are -1. Modes for column j < len |
| get_fused_dflash_get_input_tl | 62 | Build the fixed-stride draft-token inputs of every request. One CTA per (request, draft slot). f |
| (已列出全部 2 个顶层符号) | ||
| 符号 | 行数 · 说明(ast 提取) | |
| replace_input_embeds_tl | 42 | One block per token: if input_ids[bx] is the image token, overwrite the embed row with images_em |
| rgb_pad_to_patches_tl | 125 | Convert concatenated plain RGB (HWC uint8) pixel data to normalized patch tensors, center-paddin |
| batch_downsample_tl | 78 | One block per output patch: gather the d x d source window of ViT patch features (zero-filling r |
| (已列出全部 3 个顶层符号) | ||
| 符号 | 行数 · 说明(ast 提取) | |
| kv_index_cat_tl | 69 | |
| (已列出全部 1 个顶层符号) | ||
| 符号 | 行数 · 说明(ast 提取) | |
| load_paged_kv_cache_tl | 152 | Build a compact-range paged-cache load kernel from ``layout``. |
| (已列出全部 1 个顶层符号) | ||
| 符号 | 行数 · 说明(ast 提取) | |
| norm_tl | 309 | |
| (已列出全部 1 个顶层符号) | ||
| 符号 | 行数 · 说明(ast 提取) | |
| detect_outlier_and_abort_tl | 32 | |
| (已列出全部 1 个顶层符号) | ||
| 符号 | 行数 · 说明(ast 提取) | |
| prepare_cp_mirror_tl | 160 | Output-parallel scatter with the prefix scan in one TileLang entry. |
| yoco_cp_boundary_fused_tl | 135 | YOCO flat scatter with the prefix scan in one TileLang entry. |
| (已列出全部 2 个顶层符号) | ||
| 符号 | 行数 · 说明(ast 提取) | |
| prepare_v4_decode_metadata_tl | 140 | ratio 集合全部是编译期常量, 不写死具体倍率: - ca_ratios: 所有压缩倍率 (dense ∪ sparse), 驱动 positions_c / slot_mapping_s |
| copy_block_tables_tl | 32 | |
| (已列出全部 2 个顶层符号) | ||
| 符号 | 行数 · 说明(ast 提取) | |
| ue8m0_exp_scale | 5 | Round scale up to a power of two: returns -ceil(log2(scale)), the exponent of the quantization m |
| (已列出全部 1 个顶层符号) | ||
| 符号 | 行数 · 说明(ast 提取) | |
| class Config | 27 | Compile-time layout for two-level sampling: a row is folded into `bd` per-lane sums (over n_chun |
| └ n_chunks | 2 | |
| └ n_slots | 2 | |
| └ slot_chunks | 2 | |
| └ scale | 2 | |
| float_to_fixed | 13 | floor(x * 2**scale_bits) as fixed point; x must be in [0, 1]. The uint64 path computes this exac |
| block_cumsum_parts | 3 | |
| block_cumsum | 23 | Inclusive integer scan using warp segments and block-wide carries. |
| accumulate | 7 | |
| sample_offset | 63 | Coarse search: pick the random target r within [0, total), then locate the BD-lane offset k0 it |
| sample_select | 35 | Fine search over the gathered arithmetic sequence slot_probs (raw f32 probs for columns k0 + m*B |
| random_sampling_tl | 52 | One CTA per row, two-level weighted sampling (see Config). Level 1 folds the row into BD fixed-p |
| (已列出全部 8 个顶层符号 + 4 个方法) | ||
| 符号 | 行数 · 说明(ast 提取) | |
| prepare_verification_metadata_tl | 28 | |
| expand_sampling_params_tl | 33 | |
| map_lookup_tl | 52 | |
| remap_draft_topk_tl | 65 | |
| get_accept_result_tl | 51 | |
| finalize_verification_tl | 124 | |
| (已列出全部 6 个顶层符号) | ||
| 符号 | 行数 · 说明(ast 提取) | |
| compute_seqlens_q_by_confidence_rates_tl | 70 | |
| (已列出全部 1 个顶层符号) | ||
| 符号 | 行数 · 说明(ast 提取) | |
| select_state_slice_tl | 54 | Create a tilelang kernel for selecting state slice from cache to tensor. This implements the gat |
| load_state_to_cache_tl | 57 | Tilelang kernel for loading state from tensor to cache. This implements the scatter operation fr |
| (已列出全部 2 个顶层符号) | ||
| 符号 | 行数 · 说明(ast 提取) | |
| _amax_to_ue8m0_scales | 7 | Convert bf16 amax values to fp8 quant multipliers and ue8m0 scales. |
| store_kv_cache_tl | 169 | Build a paged-cache store kernel specialized by its logical layout. |
| (已列出全部 2 个顶层符号) | ||
| 符号 | 行数 · 说明(ast 提取) | |
| store_mtp_info_tl | 47 | |
| (已列出全部 1 个顶层符号) | ||
| 符号 | 行数 · 说明(ast 提取) | |
| apply_token_bitmask_by_step_inplace_tl | 42 | |
| (已列出全部 1 个顶层符号) | ||
| 符号 | 行数 · 说明(ast 提取) | |
| sum_smaller_probs_tl | 42 | |
| (已列出全部 1 个顶层符号) | ||
| 符号 | 行数 · 说明(ast 提取) | |
| expand_swa_index_tl | 27 | |
| (已列出全部 1 个顶层符号) | ||
| 符号 | 行数 · 说明(ast 提取) | |
| confidence_head_fused | 37 | Fused ``sigmoid(cat([hidden, markov_emb], -1) @ weight / temperature)``. Args: hidden: [n, n_emb |
| _sigmoid_with_temperature | 3 | |
| confidence_head_fused_ref | 21 | |
| test_confidence_head | 19 | |
| test_confidence_head_benchmark | 22 | |
| dflash_input_store | 26 | Fused mean-reduce over the hc_mult dim and copy into out. Args: hidden_states: [..., hc_mult, n_ |
| dflash_input_store_ref | 8 | |
| test_dflash_input_store | 22 | |
| test_dflash_input_store_benchmark | 25 | |
| (已列出全部 9 个顶层符号) | ||
| 符号 | 行数 · 说明(ast 提取) | |
| _mtp_sampling_tensors | 10 | |
| _mtp_decode_tensors | 5 | |
| copy_dflash_decode_input | 28 | Fill the DFlash decode inputs of a CUDA graph in one TileLang launch. Args: dst: Destination wit |
| copy_dflash_decode_input_ref | 12 | |
| _make_sampling_input | 16 | |
| _make_mtp_decode_input | 14 | |
| test_copy_dflash_decode_input | 14 | |
| test_copy_dflash_decode_input_benchmark | 19 | |
| (已列出全部 8 个顶层符号) | ||
| 符号 | 行数 · 说明(ast 提取) | |
| convert_kv_index | 28 | Map topk logical token indices to physical kv-cache slot indices via block_tables. Args: topk_id |
| convert_kv_index_ref | 12 | |
| _make_convert_kv_index_inputs | 17 | |
| test_convert_kv_index | 8 | |
| test_convert_kv_index_benchmark | 19 | |
| (已列出全部 5 个顶层符号) | ||
| 符号 | 行数 · 说明(ast 提取) | |
| fused_sample | 101 | Apply temperature, top-p/top-k, log-softmax, and optional sampling. Args: logits: [Q, vocab_size |
| apply_top_p_top_k_ref | 30 | Apply stable top-p followed by stable top-k, masking logits in place. Args: logits: [num_tokens, |
| fused_sample_ref | 96 | Run the PyTorch reference implementation of :func:`fused_sample`. Args: logits: [Q, vocab_size], |
| generate_logits | 30 | |
| _make_top_p | 8 | |
| _make_top_k | 6 | |
| _make_draft_inputs | 20 | |
| _check_top_p_top_k | 55 | Validate the top-p/top-k boundary for one logprob output. |
| generate_test_params | 21 | |
| make_param_id | 3 | |
| _check_fused_sample | 118 | |
| _check_reject_sampling_distribution | 90 | |
| _check_zero_residual | 32 | |
| _check_signed_zero | 28 | |
| _correctness_cases | 51 | |
| test_fused_sample | 13 | |
| test_fused_sample_benchmark | 75 | |
| (已列出全部 17 个顶层符号) | ||
| 符号 | 行数 · 说明(ast 提取) | |
| class NormArgs | 5 | RMSNorm parameters for the last dimension. |
| class RopeArgs | 9 | RoPE parameters; rotary_dim values start at offset. |
| class HadamardArgs | 2 | 0 个方法 |
| class CastArgs | 25 | Per-channel quantization parameters. fmt is e4m3 FP8 or packed e2m1 FP4. UE8M0 scales are return |
| └ from_cache_format | 7 | |
| class ContiguousOutArgs | 3 | 0 个方法 |
| class KVCacheOutArgs | 6 | 0 个方法 |
| _resolve_cache_layout | 6 | |
| _validate_cache_cast | 5 | |
| _restore_single_head_axis | 5 | |
| _restore_single_head_axis | 5 | |
| _restore_single_head_axis | 9 | |
| _alloc_quant | 38 | |
| fused_norm_rope_hadamard_cast_store_kvcache | 171 | Optionally fuse attention-row transforms and their final store. Args: x: [num_tokens, num_heads, |
| hadamard_transform_ref | 25 | Pure-PyTorch Walsh-Hadamard transform along the last dimension. Requires a power-of-two last dim |
| fused_norm_rope_hadamard_cast_store_kvcache_ref | 179 | Unfused production reference for the optional transform pipeline. |
| class _FusedTransformCase | 100 | 2 个方法 |
| └ operation | 60 | Return a canonical, field-derived test and benchmark identifier. The f |
| └ cast_args | 10 | |
| _benchmark_io_bytes | 18 | |
| _allocate_cache | 12 | |
| _make_case | 92 | |
| _clone_out_args | 26 | |
| _assert_result_equal | 12 | |
| test_fused_norm_rope_hadamard_cast_store_kvcache | 60 | |
| test_fused_norm_rope_hadamard_cast_store_kvcache_benchmark | 34 | |
| (已列出全部 23 个顶层符号 + 3 个方法) | ||
| 符号 | 行数 · 说明(ast 提取) | |
| _flat_dense_int8 | 12 | |
| gather | 37 | Row gather ``x[index]`` with out-of-range indices zero-filled. Args: x: [n, ...], any dtype (cop |
| test_gather | 14 | |
| test_gather_benchmark | 26 | |
| (已列出全部 4 个顶层符号) | ||
| 符号 | 行数 · 说明(ast 提取) | |
| gather_engram_tokens_zos | 46 | Gather ngram_token_ids using two-source logic, branching fresh/prev inside the kernel. With next |
| gather_engram_tokens_zos_ref | 60 | CPU reference for testing. |
| test_gather_engram_tokens_zos | 62 | |
| test_gather_engram_tokens_zos_bench | 51 | |
| (已列出全部 4 个顶层符号) | ||
| 符号 | 行数 · 说明(ast 提取) | |
| gather_input_ids_zos | 23 | Gather input_ids from fresh_tokens or prev sampled/predict tokens. For each (seq i, token j) wit |
| gather_input_ids_zos_ref | 63 | Gather input_ids from fresh_tokens or prev sampled/predict tokens. Pure GPU implementation, no C |
| test_gather_input_ids_zos | 45 | |
| test_gather_input_ids_zos_bench | 41 | |
| (已列出全部 4 个顶层符号) | ||
| 符号 | 行数 · 说明(ast 提取) | |
| get_kv_ca_index_prefill_ref | 12 | |
| get_kv_ca_index_prefill | 15 | Args: kv_ca_index_offset_len: [n, 2], int32, (offset, len) per row Returns: kv_ca_index: [n, kv_ |
| get_kv_ca_index_decode_ref | 17 | |
| get_kv_ca_index_decode | 18 | Args: kv_ca_index_offset_len: [n, 2], int32, (offset, len) per row, offset in token units block_ |
| get_kv_swa_index_decode_ref | 15 | |
| get_kv_swa_index_decode | 16 | Args: kv_swa_index_offset_len: [n, 2], int32, (offset, len) per row Returns: kv_swa_index: [n, w |
| test_kv_index | 18 | |
| get_fused_dflash_get_input_ref | 56 | PyTorch reference implementation. Returns (newx_slot_mapping, positions_out, input_ids, valid_to |
| get_fused_dflash_get_input | 66 | Fill dflash draft-token inputs in one fused kernel. One CTA per (request, draft slot). Each requ |
| _make_dflash_inputs | 13 | Random (slot_mapping_swa, positions, ftp, last_valid_offset) for fused_dflash tests; the last pa |
| test_fused_dflash_get_input | 32 | |
| test_fused_dflash_get_input_benchmark | 30 | |
| test_kv_index_benchmark | 42 | |
| test_kv_ca_index_decode_benchmark | 18 | |
| test_kv_swa_index_decode_benchmark | 17 | |
| test_kv_ca_index_prefill_benchmark | 17 | |
| (已列出全部 16 个顶层符号) | ||
| 符号 | 行数 · 说明(ast 提取) | |
| replace_input_embeds | 30 | In-place fill of multimodal embeddings: the i-th token equal to image_token_id (in sequence orde |
| rgb_pad_to_patches | 55 | Convert concatenated plain RGB (HWC uint8) pixel data to normalized bf16 patch tensors, center-p |
| replace_input_embeds_ref | 20 | Pure PyTorch reference implementation for replace_input_embeds. |
| build_image_data | 59 | Build test data for image embed ops. Args: num_tokens: total number of tokens in input_embeds hi |
| _mixed_img_sizes | 14 | Split total_img_tokens across num_imgs images with *different* (mixed) even sizes, so per-image |
| _build_test_data | 14 | build_image_data with the tests' default config: 2 images (mixed sizes), 3 pad token types. imag |
| test_replace_input_embeds | 19 | |
| test_replace_input_embeds_benchmark | 35 | |
| _crops_from_sizes | 8 | Build (images_spatial_crop, cu_seqlens_vit, total_seqlens_vit) from an explicit list of per-imag |
| _rect_crops | 14 | Mixed, non-square (n_vit_w, n_vit_h) sizes so that w/h transposition and per-image indexing bugs |
| test_rgb_pad_to_patches | 37 | |
| _build_rgb_data | 37 | Build concatenated plain-RGB (HWC uint8) test data for rgb_pad_to_patches. images_spatial_crop u |
| test_rgb_pad_to_patches_benchmark | 38 | |
| rgb_pad_to_patches_ref | 55 | Pure PyTorch reference for rgb_pad_to_patches. Build a grid-sized uint8 canvas filled with pad_c |
| batch_downsample | 68 | Per-image d x d spatial downsample of ViT patch features: channel-concat (downsample_mlp_gelu / |
| batch_downsample_ref | 38 | Per-image unfold(concat)/ 有效块均值(pool);pool 与 kernel 同用 fp32 sum * (1/count) 的舍入 |
| _downsample_crops | 3 | 混合整除 / ragged / 零占位(缓存图 dummy)行:一次覆盖 ragged 补零分支与 images_id 定位 |
| test_batch_downsample | 12 | |
| test_batch_downsample_benchmark | 12 | |
| (已列出全部 19 个顶层符号) | ||
| 符号 | 行数 · 说明(ast 提取) | |
| kv_index_cat | 42 | Args: kv_index: [total_q, window_size], int32 kv_ca_index: [total_q, topk_tokens], int32 total_k |
| kv_index_cat_ref | 13 | |
| test_kv_index_cat | 15 | |
| test_kv_index_cat_benchmark | 17 | |
| (已列出全部 4 个顶层符号) | ||
| 符号 | 行数 · 说明(ast 提取) | |
| load_paged_kv_cache | 81 | Load compact physical-block ranges through one cache-layout API. Args: kv_cache: [num_blocks, bl |
| load_paged_kv_cache_ref | 79 | PyTorch reference for :func:`load_paged_kv_cache`. |
| _make_cache | 14 | |
| _make_load_segments | 24 | |
| _make_merged_index_load_segments | 18 | |
| test_load_paged_kv_cache | 44 | |
| test_load_paged_kv_cache_benchmark | 58 | |
| (已列出全部 7 个顶层符号) | ||
| 符号 | 行数 · 说明(ast 提取) | |
| _check_vectorized_strides | 5 | |
| _alloc_fp8_sf | 40 | 分配 fp8 cast 的 sf,返回 (对外视图, kernel 实参)。布局与 tile_kernels.quant 一致: - row-major: float32 (B, M, d_s |
| norm | 188 | RMSNorm 前向,可选融合 residual 加与 fp8 cast。 Args: x: [B, d] 或 [B, M, d],bf16/fp32 weight: [d],与 x 同 dt |
| norm_ref | 18 | RMSNorm reference: x -> w * x / sqrt(E[x^2] + eps). |
| _out_form_id | 4 | |
| _make_inputs | 7 | |
| _shared_sf_ref | 10 | 把 row-major packed sf [M, packs] 转成 shared_l1_acts_sf 参照([rows, packs] M-major,pad 行为 0): 与 Deep |
| test_norm | 120 | |
| test_norm_benchmark | 78 | |
| (已列出全部 9 个顶层符号) | ||
| 符号 | 行数 · 说明(ast 提取) | |
| class KernelUnavailableError | 4 | Selected backend lacks this kernel factory; conftest.py turns it into a test skip on non-cuda ba |
| __getattr__ | 2 | |
| (已列出全部 2 个顶层符号) | ||
| 符号 | 行数 · 说明(ast 提取) | |
| detect_outlier_and_abort | 17 | Queue a CUDA assertion for NaN, infinity, or values outside (-MAX_ABS, MAX_ABS). The check runs |
| (已列出全部 1 个顶层符号) | ||
| 符号 | 行数 · 说明(ast 提取) | |
| prepare_cp_mirror | 66 | Prepare mirror-CP indices with one TileLang entry and an output-parallel scatter. Both backends |
| yoco_cp_boundary_fused | 45 | Prepare YOCO CP boundary indices through one TileLang entry. Args: cu_seqlens_q: [batch_size + 1 |
| prepare_cp_mirror_ref | 32 | Pure Python reference that directly expands the zigzag definition. |
| yoco_cp_boundary_fused_ref | 27 | Pure Python reference for YOCO consumer CP boundary redistribution. |
| _make_cu_seqlens | 13 | |
| _mirror_cp_sizes | 3 | |
| _yoco_contrib_pad_len | 9 | |
| test_prepare_cp_mirror | 30 | |
| test_prepare_cp_mirror_benchmark | 39 | |
| test_yoco_cp_boundary_fused | 20 | |
| test_yoco_cp_boundary_fused_benchmark | 30 | |
| (已列出全部 11 个顶层符号) | ||
| 符号 | 行数 · 说明(ast 提取) | |
| prepare_v4_decode_metadata | 87 | Compute V4 decode metadata on GPU via TileLang. Main kernel: one CTA per sequence; block_tables_ |
| prepare_v4_decode_metadata_ref | 175 | Compute V4 decode metadata on GPU via pure PyTorch (no CPU-GPU sync). |
| _build_compact_block_tables | 13 | Build random compact block tables; returns (block_tables_in, block_tables_offsets, actual_max_bl |
| test_prepare_v4_decode_metadata | 136 | |
| test_prepare_v4_decode_metadata_bench | 84 | |
| (已列出全部 5 个顶层符号) | ||
| 符号 | 行数 · 说明(ast 提取) | |
| random_sampling | 28 | Sample one column per row, weighted by probs with each row summing to at most 1. Deterministic i |
| _seeds | 2 | |
| _pos | 2 | |
| i64 | 2 | |
| urshift | 3 | |
| _hash_to_uniform | 10 | SplitMix64 hash of seed -> uniform f64 in [0, 1); int64 ops emulate uint64. |
| random_sampling_ref | 15 | Pure-PyTorch sampler: hash (seq_seeds, 3 * sample_positions + case) to a uniform and invert the |
| _make_probs | 12 | |
| test_random_sampling | 60 | |
| test_random_sampling_benchmark | 22 | |
| _gof_distributions | 12 | |
| _draw_counts | 9 | |
| test_random_sampling_gof | 31 | |
| test_random_sampling_degenerate | 13 | |
| test_random_sampling_extreme_scale | 13 | |
| test_random_sampling_tiny_prob | 18 | |
| test_random_sampling_batch_invariant | 23 | |
| (已列出全部 17 个顶层符号) | ||
| 符号 | 行数 · 说明(ast 提取) | |
| prepare_verification_metadata_ref | 13 | |
| prepare_verification_metadata | 26 | Build metadata for request rows packed along the ``total_q`` dimension. Args: ftp: [req_cnt], in |
| expand_sampling_params_ref | 11 | |
| expand_sampling_params | 41 | Expand per-request sampling parameters to packed ``total_q`` rows. Args: params: SamplingKernelI |
| map_lookup_ref | 16 | |
| map_lookup | 33 | Look up each row's value by matching a key or by a column index. Args: key: [rows, width], int32 |
| remap_draft_topk | 39 | Align previous draft info to the current target top-k space. Args: draft_topk_index: [pool_rows, |
| remap_draft_topk_ref | 19 | |
| get_accept_result_ref | 22 | Apply golden-token overrides and prefix acceptance to raw decisions. |
| get_accept_result | 49 | Apply golden-token overrides and prefix acceptance to raw decisions. Args: raw_accept: [total_q] |
| class FinalizedVerification | 16 | 0 个方法 |
| finalize_verification_ref | 80 | Finalize each request and produce packed verified and request payloads. |
| finalize_verification | 179 | Finalize packed verification rows and request-level sampled payloads. ``total_q`` rows contain c |
| compute_confidence_error_ref | 6 | |
| test_prepare_verification_metadata | 12 | |
| test_expand_sampling_params | 21 | |
| _random_topk_indices | 6 | |
| test_map_lookup | 25 | |
| test_remap_draft_topk | 15 | |
| test_get_accept_result | 37 | |
| _first_rejected_rows_for_test | 6 | |
| test_finalize_verification | 94 | |
| test_map_lookup_benchmark | 25 | |
| test_remap_draft_topk_benchmark | 21 | |
| test_prepare_verification_metadata_benchmark | 18 | |
| test_expand_sampling_params_benchmark | 29 | |
| test_get_accept_result_benchmark | 36 | |
| test_finalize_verification_benchmark | 62 | |
| (已列出全部 28 个顶层符号) | ||
| 符号 | 行数 · 说明(ast 提取) | |
| compute_seqlens_q_by_confidence_rates | 22 | Distribute total_q tokens across sequences based on MTP confidence rates. Fuses remap scatter: c |
| compute_seqlens_q_by_confidence_rates_ref | 64 | Distribute total_q tokens across sequences based on MTP confidence rates. Fuses remap scatter: c |
| test_compute_seqlens_q_by_confidence_rates | 22 | |
| test_compute_seqlens_q_benchmark | 23 | |
| (已列出全部 4 个顶层符号) | ||
| 符号 | 行数 · 说明(ast 提取) | |
| select_state_slice | 23 | Gather the window ending at last_hit_position from circular state_cache into state_tensor. Args: |
| select_state_slice_ref | 9 | |
| load_state_to_cache | 23 | Scatter state_tensor into the window ending at last_hit_position of circular state_cache. Args: |
| load_state_to_cache_ref | 9 | |
| _make_state_tensors | 16 | Create random uint8 (state_tensor, state_cache) whose layer stride is padded up to a multiple of |
| test_select_state_slice | 15 | |
| test_load_state_to_cache | 15 | |
| test_select_state_slice_benchmark | 21 | |
| test_load_state_to_cache_benchmark | 21 | |
| (已列出全部 9 个顶层符号) | ||
| 符号 | 行数 · 说明(ast 提取) | |
| _flatten_kv | 8 | |
| store_kv_cache | 46 | Store BF16 tokens through one format-inferred paged-cache API. Args: kv: [n, ..., layout.num_ele |
| _slot_scatter | 11 | ``cache[block, offset] = values``,在 Ascend 上绕开 IndexPutV2 的 32 位偏移回绕 |
| _masked_cache_store | 21 | |
| store_kv_cache_ref | 33 | PyTorch reference for :func:`store_kv_cache`. |
| _store_test_slots | 32 | Unique valid slots; random and sequential use the same set [0, n). |
| _guarded_store_cache | 45 | Independent actual/reference byte backings, including every canary/gap. |
| test_store_cache | 60 | |
| test_store_cache_benchmark | 32 | |
| (已列出全部 9 个顶层符号) | ||
| 符号 | 行数 · 说明(ast 提取) | |
| store_mtp_info | 68 | Write one contiguous ``nextn`` block per request into MTP pools. Args: write_slots: [req_cnt], i |
| store_mtp_info_ref | 24 | PyTorch reference implementation of :func:`store_mtp_info`. |
| test_store_mtp_info | 57 | |
| test_store_mtp_info_benchmark | 55 | |
| (已列出全部 4 个顶层符号) | ||
| 符号 | 行数 · 说明(ast 提取) | |
| apply_token_bitmask_by_step_inplace | 26 | Args: logits: [total_q, vocab_size], fp32, packed by request, in-place output bitmask: [num_requ |
| apply_token_bitmask_by_step_inplace_ref | 22 | |
| test_apply_token_bitmask_by_step_inplace_without_ftp | 13 | |
| test_apply_token_bitmask_by_step_inplace | 16 | |
| test_apply_token_bitmask_by_step_inplace_without_ftp_benchmark | 22 | |
| test_apply_token_bitmask_by_step_inplace_benchmark | 24 | |
| (已列出全部 6 个顶层符号) | ||
| 符号 | 行数 · 说明(ast 提取) | |
| get_sum_smaller_probs | 19 | Inclusive CDF after sorting tokens by ascending probability. Per row, sum probabilities through |
| sum_smaller_probs_ref | 14 | |
| test_sum_smaller_probs | 11 | |
| test_sum_smaller_probs_benchmark | 19 | |
| (已列出全部 4 个顶层符号) | ||
| 符号 | 行数 · 说明(ast 提取) | |
| expand_swa_index | 23 | Expand two KV segments per token into dense prefill SWA indices. Args: pivots: Contiguous int32 |
| expand_swa_index_ref | 10 | Original PyTorch expansion of int32 [num_tokens, 4] into [num_tokens, width]. |
| _make_pivots | 21 | |
| test_expand_swa_index | 12 | |
| test_expand_swa_index_benchmark | 16 | |
| (已列出全部 5 个顶层符号) | ||
| 符号 | 行数 · 说明(ast 提取) | |
| class VocabParallelEmbedding | 15 | 2 个方法 |
| └ __init__ | 10 | |
| └ forward | 3 | |
| class ParallelLMHead | 4 | 1 个方法 |
| └ forward | 3 | |
| (已列出全部 2 个顶层符号 + 3 个方法) | ||