Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,12 @@ inline __device__ void zeroPagedVCacheTail(QKVPreprocessingParams<T, KVCacheBuff
{
// Context owns the last physical page exclusively. Clear unused V rows because paged FMHA loads full pages and
// masked zero probabilities can still propagate NaNs through BMM2.
if constexpr (!GEN_PHASE && std::is_same_v<KVCacheBuffer, KVBlockArray> && std::is_same_v<T, TCache>)
#ifdef ENABLE_FP8
constexpr bool kFp8Cache = std::is_same_v<TCache, __nv_fp8_e4m3>;
#else
constexpr bool kFp8Cache = false;
#endif
if constexpr (!GEN_PHASE && std::is_same_v<KVCacheBuffer, KVBlockArray> && (std::is_same_v<T, TCache> || kFp8Cache))
{
if (params.generation_phase || !isUniqueTokenWriter || cacheSeqLen <= 0 || tokenIdxInKvCache != cacheSeqLen - 1)
{
Expand All @@ -210,12 +215,20 @@ inline __device__ void zeroPagedVCacheTail(QKVPreprocessingParams<T, KVCacheBuff
}

auto* vBlock = reinterpret_cast<TCache*>(params.kv_cache_buffer.getVBlockPtr(batchIdx, cacheSeqLen - 1));
auto* vBlockVec = reinterpret_cast<TVec*>(vBlock);
TVec const zero{};
for (int tokenInBlock = validTokensInLastBlock; tokenInBlock < tokensPerBlock; ++tokenInBlock)
{
int const vIdx = kvHeadIdx * tokensPerBlock * vecsPerHead + tokenInBlock * vecsPerHead + channelIdx;
vBlockVec[vIdx] = zero;
if constexpr (std::is_same_v<T, TCache>)
{
reinterpret_cast<TVec*>(vBlock)[vIdx] = TVec{};
}
else
{
// Match the packed FP8 stores used for the valid V tokens.
using CacheVec = typename mmha::packed_type<TCache, mmha::num_elems<TVec>::value>::type;
static_assert(sizeof(CacheVec) == sizeof(TVec) / sizeof(T));
reinterpret_cast<CacheVec*>(vBlock)[vIdx] = CacheVec{};
}
}
}
}
Expand Down
12 changes: 6 additions & 6 deletions cpp/tensorrt_llm/thop/trtllmGenQKVProcessOp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -407,8 +407,8 @@ trtllmGenContextPreprocess(torch::Tensor qkv_input, torch::Tensor workspace, tor
qkvParams.generation_phase = false;
qkvParams.q_only_input = qOnlyInput;
qkvParams.multi_processor_count = static_cast<int>(multi_processor_count);
qkvParams.rotary_vision_start = 0;
qkvParams.rotary_vision_length = 0;
qkvParams.rotary_vision_start = -1;
qkvParams.rotary_vision_length = -1;

switch (qkvDtype)
{
Expand Down Expand Up @@ -559,8 +559,8 @@ void trtllmGenContextPostprocess(torch::Tensor qkv_input, torch::Tensor workspac
qkvParams.quantized_fp8_output = fp8_context_fmha;
qkvParams.generation_phase = false;
qkvParams.multi_processor_count = static_cast<int>(multi_processor_count);
qkvParams.rotary_vision_start = 0;
qkvParams.rotary_vision_length = 0;
qkvParams.rotary_vision_start = -1;
qkvParams.rotary_vision_length = -1;

switch (qkvDtype)
{
Expand Down Expand Up @@ -745,8 +745,8 @@ trtllmGenGenerationPreprocess(torch::Tensor qkv_input, torch::Tensor workspace,
qkvParams.generation_phase = true;
qkvParams.q_only_input = qOnlyInput;
qkvParams.multi_processor_count = static_cast<int>(multi_processor_count);
qkvParams.rotary_vision_start = 0;
qkvParams.rotary_vision_length = 0;
qkvParams.rotary_vision_start = -1;
qkvParams.rotary_vision_length = -1;

switch (qkvDtype)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -286,7 +286,7 @@ def _page_size_exclusive_to_cute_dsl(meta: "TrtllmAttentionMetadata") -> bool:
if tokens_per_block in getattr(kv_cache_manager, "trtllm_gen_extra_tokens_per_block", ()):
return False
return not (
get_sm_version() in PrimsTSFmha.SUPPORTED_SMS
get_sm_version() in PrimsTSFmha.SUPPORTED_MLA_SMS
and tokens_per_block in PrimsTSFmha.SUPPORTED_PAGE_SIZES
and getattr(kv_cache_manager, "dtype", None) in (DataType.FP8, DataType.BF16)
)
Expand Down
Loading
Loading