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
6 changes: 6 additions & 0 deletions cpp/tensorrt_llm/common/envUtils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -232,6 +232,12 @@ bool getEnvUseTileSizeKv64ForTrtllmGen()
return useTileSizeKv64;
}

bool getEnvUseStaticTileSchedulerForTrtllmGenContextFmha()
{
static bool const useStatic = getBoolEnv("TRTLLM_GEN_FMHA_CONTEXT_STATIC_TILE_SCHEDULER");
return useStatic;
}

bool getEnvEnablePDL()
{
static std::once_flag flag;
Expand Down
3 changes: 3 additions & 0 deletions cpp/tensorrt_llm/common/envUtils.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,9 @@ std::optional<int32_t> getEnvXqaBlocksPerSequence();
// Whether use tileSizeKv64 for multiCtasKvMode of trtllm-gen kernels.
bool getEnvUseTileSizeKv64ForTrtllmGen();

// Whether trtllm-gen context FMHA uses the static tile scheduler instead of the persistent one.
bool getEnvUseStaticTileSchedulerForTrtllmGenContextFmha();

// Tune the number of blocks per sequence for accuracy/performance purpose.
bool getEnvMmhaMultiblockDebug();

Expand Down
20 changes: 17 additions & 3 deletions cpp/tensorrt_llm/kernels/fmhaDispatcher.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,26 @@
#include "fmhaDispatcher.h"
#include "tensorrt_llm/common/config.h"
#include "tensorrt_llm/common/cudaUtils.h"
#include "tensorrt_llm/common/envUtils.h"

TRTLLM_NAMESPACE_BEGIN

namespace kernels
{

namespace
{
// Persistent is the default for performance. TRTLLM_GEN_FMHA_CONTEXT_STATIC_TILE_SCHEDULER=1 selects the static
// variant instead: the sm107 persistent context kernel can hang in a tcgen05 TMEM-dealloc guardrail trap
// (observed with the MLA HQk192/HV128 SeparateQkv kernel on Kimi-K3 prefill). Kernel support check and launch
// must agree on the scheduler, so both go through this helper.
TileScheduler contextTileScheduler()
{
return tensorrt_llm::common::getEnvUseStaticTileSchedulerForTrtllmGenContextFmha() ? TileScheduler::Static
: TileScheduler::Persistent;
}
} // namespace

////////////////////////////////////////////////////////////////////////////////////////////////////

QkvLayout AttentionInputLayoutToQkvLayout(AttentionInputLayout layout)
Expand Down Expand Up @@ -112,7 +126,7 @@ bool FmhaDispatcher::isSupported()
tllmRunnerParams.mQkvLayout = qkvLayout;
tllmRunnerParams.setAttentionMaskType(static_cast<std::int8_t>(mFixedParams.attentionMaskType));
tllmRunnerParams.mKernelType = FmhaKernelType::Context;
tllmRunnerParams.mTileScheduler = TileScheduler::Persistent;
tllmRunnerParams.mTileScheduler = contextTileScheduler();
tllmRunnerParams.mMultiCtasKvMode = false;
tllmRunnerParams.mNumHeadsQ = mFixedParams.numQHeads;
tllmRunnerParams.mNumHeadsKv = mFixedParams.numKvHeads;
Expand Down Expand Up @@ -200,8 +214,8 @@ void FmhaDispatcher::run(MHARunnerParams runnerParams)
tllmRunnerParams.mQkvLayout = qkvLayout;
tllmRunnerParams.setAttentionMaskType(static_cast<std::int8_t>(mFixedParams.attentionMaskType));
tllmRunnerParams.mKernelType = FmhaKernelType::Context;
// Always use persistent scheduler for better performance.
tllmRunnerParams.mTileScheduler = TileScheduler::Persistent;
// Persistent scheduler by default for better performance; see contextTileScheduler().
tllmRunnerParams.mTileScheduler = contextTileScheduler();
tllmRunnerParams.mMultiCtasKvMode = false;

tllmRunnerParams.qPtr = runnerParams.qPtr;
Expand Down