@@ -1866,12 +1866,15 @@ void invokeMLAContextFp8Quantize(MlaParams<T>& params, int total_kv_len, cudaStr
18661866 // Convert Q to FP8 in absorption mode.
18671867 if (params.absorption_mode )
18681868 {
1869+ // Q-sized grids can reduce idle blocks but also useful CTA parallelism.
1870+ static bool const useQLenForQuantGrid = getBoolEnv (" TRTLLM_MLA_Q_QUANT_GRID_USE_Q_LEN" );
1871+ int const quantGridLen = useQLenForQuantGrid ? params.acc_q_len : total_kv_len;
18691872
18701873 if (params.meta .rope_append )
18711874 {
18721875 constexpr int threads_per_block = 288 ;
18731876 constexpr int num_tokens_per_block = threads_per_block * 16 / 576 * sizeof (T);
1874- dim3 grid (int (tensorrt_llm::common::divUp (total_kv_len , num_tokens_per_block)), 1 , params.head_num );
1877+ dim3 grid (int (tensorrt_llm::common::divUp (quantGridLen , num_tokens_per_block)), 1 , params.head_num );
18751878
18761879 TLLM_LOG_DEBUG (
18771880 " Launching quantizeCopyInputToFp8Kernel with grid_size: (%d, %d, %d), threads_per_block: %d, "
@@ -1890,7 +1893,7 @@ void invokeMLAContextFp8Quantize(MlaParams<T>& params, int total_kv_len, cudaStr
18901893 {
18911894 constexpr int threads_per_block = 256 ;
18921895 constexpr int num_tokens_per_block = threads_per_block * 16 / 512 * sizeof (T);
1893- dim3 grid (int (tensorrt_llm::common::divUp (total_kv_len , num_tokens_per_block)), 1 , params.head_num );
1896+ dim3 grid (int (tensorrt_llm::common::divUp (quantGridLen , num_tokens_per_block)), 1 , params.head_num );
18941897
18951898 TLLM_LOG_DEBUG (
18961899 " Launching quantizeCopyInputToFp8Kernel with grid_size: (%d, %d, %d), threads_per_block: %d, "
0 commit comments