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
1 change: 1 addition & 0 deletions cpp/tensorrt_llm/common/attentionOp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3157,6 +3157,7 @@ int AttentionOp::initialize() noexcept
fixedParams.isSpecDecoding = mIsSpecDecodingEnabled;
fixedParams.hasAlibi = isALiBi();
fixedParams.useTllmGenSparseAttention = useTllmGenSparseAttention();
fixedParams.specDecodingTargetMaxGenLen = mSpecDecodingTargetMaxGenLen;

mXqaDispatcher.reset(new XqaDispatcher(fixedParams));

Expand Down
17 changes: 10 additions & 7 deletions cpp/tensorrt_llm/common/attentionOp.h
Original file line number Diff line number Diff line change
Expand Up @@ -491,6 +491,8 @@ class AttentionOp
bool mIsSpecDecTree = true;
bool mSpecDecodingIsGenerationLengthVariable = false;
int32_t mSpecDecodingMaxGenerationLength = 1;
// Static spec-dec tree length used by FMHA autotuning.
int32_t mSpecDecodingTargetMaxGenLen = 0;
bool mIsMLAEnabled = false;
bool mIsGenerationMLA = false;
bool mUseGenFlashMLA = false;
Expand Down Expand Up @@ -559,13 +561,14 @@ class AttentionOp
mCrossAttention, mMaxDistance, mPosShiftEnabled, mPagedContextFMHA, mFP8ContextFMHA, mFP8AttenOutput,
mFP8ContextMLA, mFP8GenerationMLA, mChunkPrefillBufferBatchSize, mDenseContextFMHA, mHasFullAttentionMask,
mIsSpecDecodingEnabled, mUseSpecDecoding, mIsSpecDecTree, mSpecDecodingIsGenerationLengthVariable,
mSpecDecodingMaxGenerationLength, mIsMLAEnabled, mIsGenerationMLA, mUseGenFlashMLA, mUseSparseAttention,
mUseTllmGenSparseAttentionPaged, mUseTllmGenSparseAttention, mMLAParams.data(), mCpSize, mCpRank, mCpGroup,
mNumAttnHeads, mNumAttnKVHeads, mNumKVHeadsOrigin, mAttnTpSize, mAttnTpRank, mAttnCpSize, mAttnCpRank,
mUlyssesMQABroadcast, mEnableContextFMHA, mFMHAForceFP32Acc, mMultiBlockMode, mEnableXQA, mUseKVCache,
mSkipAttn, mFuseFp4Quant, mNbMultiBlockSemaphores, mAttentionChunkSize.value_or(-1),
mSkipSoftmaxThresholdScaleFactorPrefill, mSkipSoftmaxThresholdScaleFactorDecode, mSageAttnNumEltsPerBlkQ,
mSageAttnNumEltsPerBlkK, mSageAttnNumEltsPerBlkV, mSageAttnQkInt8);
mSpecDecodingMaxGenerationLength, mSpecDecodingTargetMaxGenLen, mIsMLAEnabled, mIsGenerationMLA,
mUseGenFlashMLA, mUseSparseAttention, mUseTllmGenSparseAttentionPaged, mUseTllmGenSparseAttention,
mMLAParams.data(), mCpSize, mCpRank, mCpGroup, mNumAttnHeads, mNumAttnKVHeads, mNumKVHeadsOrigin,
mAttnTpSize, mAttnTpRank, mAttnCpSize, mAttnCpRank, mUlyssesMQABroadcast, mEnableContextFMHA,
mFMHAForceFP32Acc, mMultiBlockMode, mEnableXQA, mUseKVCache, mSkipAttn, mFuseFp4Quant,
mNbMultiBlockSemaphores, mAttentionChunkSize.value_or(-1), mSkipSoftmaxThresholdScaleFactorPrefill,
mSkipSoftmaxThresholdScaleFactorDecode, mSageAttnNumEltsPerBlkQ, mSageAttnNumEltsPerBlkK,
mSageAttnNumEltsPerBlkV, mSageAttnQkInt8);
};

private:
Expand Down
32 changes: 30 additions & 2 deletions cpp/tensorrt_llm/kernels/trtllmGenKernels/fmha/fmhaKernels.h
Original file line number Diff line number Diff line change
Expand Up @@ -990,6 +990,8 @@ class TllmGenFmhaKernel
options.mIsCustomSpecDecodingGen = !isContext && params.mMaxSeqLenQ > 1 && params.mIsSpecDecTree;
options.mIsCausalSpecDecodingGen = !isContext && params.mMaxSeqLenQ > 1 && !params.mIsSpecDecTree;
options.mNumSpecDecodingTokens = !isContext && params.mMaxSeqLenQ > 1 ? params.mMaxSeqLenQ : 0;
// Carry static tree length into FMHA kernel selection.
options.mSpecDecodingTargetMaxGenLen = params.mSpecDecodingTargetMaxGenLen;

options.mIsTrtllmLayout = true;
}
Expand All @@ -1013,17 +1015,43 @@ class TllmGenFmhaKernel
// loop. And the number of loops are not the same in different tasks.
sstream << "\"checksTaskSchedules\": false,\n";

bool hasCompileDefs = false;
auto writeCompileDef = [&](char const* compileDef)
{
if (!hasCompileDefs)
{
sstream << "\"compileDefs\": [";
hasCompileDefs = true;
}
else
{
sstream << ", ";
}
sstream << "\"" << compileDef << "\"";
};

if (options.mIsExportingCubin)
{
sstream << "\"compileDefs\": [\"-DTLLM_EXPORT_CUBIN\"],\n";
writeCompileDef("-DTLLM_EXPORT_CUBIN");
}

// Set compile flags for E2M1 KV kernel benchmark.
// NOTE(tizheng): This is to be removed after compiler fixes PTX exposure of QMUL4. See Fp4Utils.h for details.
if (options.mChecksResults == 0 && options.mDtypeKv == tg::Dtype::E2m1)
{
TLLM_LOG_INFO("Forcing -DTLLM_BENCHMARK_E2M1_KV_CACHE for E2m1 Kv. The results are not correct.");
sstream << "\"compileDefs\": [\"-DTLLM_BENCHMARK_E2M1_KV_CACHE\"],\n";
writeCompileDef("-DTLLM_BENCHMARK_E2M1_KV_CACHE");
}

// SwapsMmaAb NVRTC kernels already emit __launch_bounds__; avoid a CUDA 13 .reqntid/.maxntid conflict.
if (shouldUseNvrtc(options) && options.mFmhaKernelType == FmhaKernelType::SwapsMmaAbForGeneration)
{
writeCompileDef("-DTLLM_DISABLE_BLOCK_SIZE");
}

if (hasCompileDefs)
{
sstream << "],\n";
}

// Enable programmatic dependent launch.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -342,6 +342,7 @@ struct TllmGenFmhaRunnerParams
// When seqlensQPtr[i] < mPackedMaskMaxSeqLenQ, the packed mask tensor has
// row stride ceilDiv(mPackedMaskMaxSeqLenQ, 32) rather than ceilDiv(seqLenQ, 32).
int32_t mPackedMaskMaxSeqLenQ = 0;
int32_t mSpecDecodingTargetMaxGenLen = 0;

// set the attention mask type
TllmGenFmhaRunnerParams& setAttentionMaskType(std::int8_t maskType)
Expand Down
Loading
Loading