Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
62 commits
Select commit Hold shift + click to select a range
be9f6b5
Refactor some mistral_small model out of L40S because memory limit
yufeiwu-nv Mar 31, 2026
4e768a1
refact another
yufeiwu-nv Apr 1, 2026
4e41cba
improve robustness
yufeiwu-nv Apr 1, 2026
274926b
fix according to AI
yufeiwu-nv Apr 1, 2026
f8532a0
Merge branch 'main' into fix_L40S
yufeiwu-nv Apr 1, 2026
8bb12be
Merge branch 'main' into fix_L40S
yufeiwu-nv Apr 2, 2026
d730c6f
Adjust L40S test list
yufeiwu-nv Apr 2, 2026
0571ad1
Merge branch 'main' into fix_L40S
yufeiwu-nv Apr 2, 2026
6fe30f0
Merge branch 'main' into fix_L40S
yufeiwu-nv Apr 3, 2026
1f9147e
[None][feat] Support MLA generation in TrtllmGen attention backend (#…
yihwang-nv Apr 3, 2026
f85e986
[None][infra] Check in most recent lock file from nightly pipeline
tensorrt-cicd Apr 3, 2026
bb5a420
[None][infra] No warn_unused_ignores temporarily (#12728)
EmmaQiaoCh Apr 3, 2026
4d24c3d
[None][feat] Qwen3-Next MTP (#11370)
Apr 3, 2026
6860228
[None][doc] Blog19 for DWDP. (#12725)
wanqian-nv Apr 3, 2026
a521574
[https://nvbugs/5800591][chore] Unwaive a deepseek MTP test (#12327)
mikeiovine Apr 3, 2026
f12cc91
[None][doc] Add visual generation models to supported models page (#1…
chang-l Apr 3, 2026
057db73
[None][infra] Check in most recent lock file from nightly pipeline
tensorrt-cicd Apr 3, 2026
f245508
[TRTLLM-11146][feat] Extend python cache transceiver to support nemot…
bo-nv Apr 4, 2026
4e55b2b
[TRTLLM-11523][feat] Handle different chat template types (#12336)
2ez4bz Apr 4, 2026
e03685b
[None][infra] Check in most recent lock file from nightly pipeline
tensorrt-cicd Apr 4, 2026
b68e522
[#12257][fix] Use the first non-None result returned by hf download w…
kev-bi Apr 4, 2026
b78d868
[None][feat] Add multi-turn support for trtllm-bench (#12468)
cascade812 Apr 4, 2026
0841e0d
[None][fix] Replace assertions with warnings for unsupported logits/l…
yifjiang Apr 4, 2026
74fb0e3
[None][cleanup] Add supplemental ruff lint for legacy files via ruff-…
venkywonka Apr 4, 2026
4da8d33
[https://nvbugs/5864187][fix] Address H20 Weights Loading OOM for GPT…
dongfengy Apr 4, 2026
d14231d
[None][feat] Add fused DiT QK Norm + RoPE CUDA kernel for FLUX (#11869)
karljang Apr 4, 2026
cb375ac
[TRTLLM-9772][feat] Support cache reuse for SSM in KVCacheManagerV2 (…
lowsfer Apr 4, 2026
f207ee5
[None][fix] Harmony Parser Delta Grouping + Reuse Report + Better Tes…
dongfengy Apr 4, 2026
d7ec1cf
[None][feat] MLIR-based auto-generated elementwise fusion for AutoDep…
suyoggupta Apr 4, 2026
5469f54
[None][doc] Clean up latest news + blogs, update overview, highlight …
laikhtewari Apr 5, 2026
1f04d8b
[None][infra] Check in most recent lock file from nightly pipeline
tensorrt-cicd Apr 5, 2026
e1b1e58
[None][feat] Add --custom_tokenizer CLI option to trtllm-bench (#12586)
qiaoxj07 Apr 5, 2026
1eca31a
[https://nvbugs/6027560][fix] fix hang issues on DGX_B200-8_GPUs-PyTo…
bo-nv Apr 5, 2026
3bded61
[TRTLLM-11597][fix] fix disagg kvcache router for chat API and add di…
reasonsolo Apr 5, 2026
1abeb78
[None][fix] Fix Cuda event crash with perf metrics (#12639)
jthomson04 Apr 5, 2026
a838539
[None][fix] Update codes to support nemotron-h corner cases (#12620)
Wanli-Jiang Apr 5, 2026
be9e004
[None][infra] Waive 10 failed cases for main in post-merge 2636 (#12767)
ZhanruiSunCh Apr 5, 2026
e9cddcc
[https://nvbugs/6018051][fix] Add port conflict retry for disaggregat…
reasonsolo Apr 5, 2026
d6f190d
[None][infra] Check in most recent lock file from nightly pipeline
tensorrt-cicd Apr 6, 2026
8348b0c
[https://nvbugs/6025177][fix] Fix KV cache issue (#12673)
thorjohnsen Apr 6, 2026
29140b8
[TRTLLMINF-37][feat] Add CI agent failure analysis to L0_MergeRequest…
dpitman-nvda Apr 6, 2026
8f4e03f
[None][doc] Update C++ coding guidelines. (#12577)
hnover-nv Apr 6, 2026
3a341d0
[#12324][fix] Fixed wrong token suppressed with ignore_eos in torch s…
MrGeva Apr 6, 2026
c664e4d
[https://nvbugs/5849648][fix] Fix GPTOSS Chat Template for Disagg Tes…
dongfengy Apr 6, 2026
58108cf
[#11094][feat] AutoDeploy transform to fuse silu+mul (#12497)
MrGeva Apr 6, 2026
6e11a2d
[None][infra] Fix source code scanning (#12773)
yuanjingx87 Apr 6, 2026
0e8e1d0
[None][chore] Remove gpu-shell tool from ad-run-agent (#12418)
govind-ramnarayan Apr 6, 2026
103d002
[#9306][cleanup] Remove some fields with redefined defaults (#11671)
2ez4bz Apr 6, 2026
403a425
[None][infra] Check in most recent lock file from nightly pipeline
tensorrt-cicd Apr 7, 2026
b9c1ae8
[None][feat] reuse triton slicing kernel for GDN prefill transpose (#…
nv-guomingz Apr 7, 2026
1654d73
[None][feat] fix mamba metadata prefill bubble in chunked prefill ser…
nv-guomingz Apr 7, 2026
0a61d32
[https://nvbugs/5781731][fix] Unwaive Ray test (#9654)
dominicshanshan Apr 7, 2026
df8e443
[None][fix] Fix outdated argument of readme.md for executorExampleDis…
Fan-Yunfan Apr 7, 2026
a364e99
[None][feat] Trtllm-gen FMHA JIT support (#12612)
yunruis Apr 7, 2026
e97ebbb
[None][infra] Check in most recent lock file from nightly pipeline
tensorrt-cicd Apr 7, 2026
1fe8b3e
[None][feat] retune causalConv1d fwd dispatch for varlen and short se…
nv-guomingz Apr 7, 2026
6e8ad57
[TRTLLM-9948][infra] Move to use FlexCache in Austin for 5080 nodes (…
EmmaQiaoCh Apr 7, 2026
5405349
[TRTLLM-11768][fix] Config updates to enable NVFP4 (#12776)
2ez4bz Apr 7, 2026
d1f6dfc
[https://nvbugs/6008468][fix] Fix top-K logprobs size for PP (#12623)
pengbowang-nv Apr 7, 2026
05a3d9e
[None][Fix] Remove clone in fp8 quant. (#12687)
Tracin Apr 7, 2026
899be0a
increase stall handle time
yufeiwu-nv Apr 7, 2026
2451003
improve to 30 mins
yufeiwu-nv Apr 7, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
The diff you're trying to view is too large. We only load the first 3000 changed files.
12 changes: 6 additions & 6 deletions .claude/agents/ad-run-agent.md
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
---
name: ad-run-agent
description: Run AutoDeploy build and run command for a given model using gpu-shell
tools: Read, Grep, Glob, Bash, Write, Edit, gpu-shell
description: Run AutoDeploy build and run command for a given model
tools: Read, Grep, Glob, Bash, Write, Edit
model: sonnet
---

Run a model with AutoDeploy using gpu-shell. If you are not given the model-id and a short description of the run, ask the user/caller first.
Run a model with AutoDeploy. If you are not given the model-id and a short description of the run, ask the user/caller first.

## Prerequisites — Model Registry Entry

Expand Down Expand Up @@ -43,7 +43,7 @@ Look up the model in `examples/auto_deploy/model_registry/models.yaml` and find

**Step 2 — Check GPU availability via `nvidia-smi`:**

Run via gpu-shell:
Run via Bash:
```bash
nvidia-smi --query-gpu=index,memory.used,utilization.gpu --format=csv,noheader,nounits
```
Expand All @@ -57,7 +57,7 @@ A GPU is considered **free** if its memory usage is below ~1000 MiB and utilizat

### 1. Run the AD build and run command

Execute via gpu-shell since it requires GPU access:
Execute via Bash:
```bash
CUDA_VISIBLE_DEVICES=<SELECTED_GPUS> AD_DUMP_GRAPHS_DIR=<AD_DUMP_GRAPHS_DIR> \
python examples/auto_deploy/build_and_run_ad.py \
Expand Down Expand Up @@ -120,4 +120,4 @@ Then append the first entry.
- Always ask for the run description from the caller before starting.
- Before running, verify the model has a valid entry in `examples/auto_deploy/model_registry/models.yaml`. If missing, create one.
- If it failed, show the relevant error and suggest next steps.
- Remember to use your own tools — Read, Grep, Glob, Bash, Write, Edit, gpu-shell
- Remember to use your own tools — Read, Grep, Glob, Bash, Write, Edit
2 changes: 1 addition & 1 deletion .codex/agents/ad_debug_agent.toml
Original file line number Diff line number Diff line change
Expand Up @@ -39,5 +39,5 @@ Common pitfalls:
- HF safetensors weights may not match what the AD custom modeling code expects. Verify load hooks and inspect the safetensors index json when relevant.
- Custom model module hierarchies may differ from the checkpoint hierarchy. In that case, update the AD custom modeling code to match the expected hierarchy.

Use your own tools to read files, search, edit, and run shell commands. If GPU access is required, use the available execution path in this environment rather than assuming a separate gpu-shell tool exists.
Use your own tools to read files, search, edit, and run shell commands.
"""
2 changes: 1 addition & 1 deletion .codex/agents/ad_run_agent.toml
Original file line number Diff line number Diff line change
Expand Up @@ -64,5 +64,5 @@ If the worklog does not exist, create it with this header first:

Notes:
- If the run fails, show the relevant error and suggest next steps.
- Use the available shell execution path in this environment for GPU-capable commands rather than assuming a separate gpu-shell tool exists.
- Use the standard shell execution path for GPU-capable commands.
"""
1,522 changes: 1,443 additions & 79 deletions .pre-commit-config.yaml

Large diffs are not rendered by default.

353 changes: 299 additions & 54 deletions CODING_GUIDELINES.md

Large diffs are not rendered by default.

8 changes: 8 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,14 @@ mdformat.................................................................Passed

If any files were modified by this hook, you will need to stage and commit them again.

> **Note:** Python files are split into two groups. **Group A** files get full
> ruff formatting and linting. **Group B** (legacy) files get yapf/isort/autoflake
> formatting plus supplemental ruff lint rules via the `ruff-legacy` hook.
> The legacy hook is baseline-gated: pre-existing violations are tolerated, but
> new violations introduced by your change will block the commit.
> See [CODING_GUIDELINES.md](CODING_GUIDELINES.md#pre-commit-linting-supplemental-rules)
> for details on the two-group system and how to graduate files.

In addition, please try to keep pull requests (PRs) as concise as possible:
* Avoid committing commented-out code.
* Wherever possible, each PR should address a single concern. If there are several otherwise-unrelated things that should be fixed to reach a desired endpoint, our recommendation is to open several PRs and indicate the dependencies in the description. The more complex the changes are in a single PR, the more time it will take to review those changes.
Expand Down
20 changes: 13 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@

TensorRT LLM
===========================
<h4>TensorRT LLM provides users with an easy-to-use Python API to define Large Language Models (LLMs) and supports
state-of-the-art optimizations to perform inference efficiently on NVIDIA GPUs.</h4>
<h4>TensorRT LLM optimizes inference for LLMs and Visual Gen models with specialized kernels for common operations, an efficient runtime, and a pythonic framework that enables you to customize and extend the system.</h4>

[![Documentation](https://img.shields.io/badge/docs-latest-brightgreen.svg?style=flat)](https://nvidia.github.io/TensorRT-LLM/)
[![Ask DeepWiki](https://deepwiki.com/badge.svg)](https://deepwiki.com/NVIDIA/TensorRT-LLM)
Expand All @@ -22,6 +21,10 @@ state-of-the-art optimizations to perform inference efficiently on NVIDIA GPUs.<
## Tech Blogs

<!-- Use github markdown link to link for the latest blog since the doc build has not happened yet. When the doc build is updated, it should be updated to the webpage link. -->

* [04/03] DWDP: Distributed Weight Data Parallelism for High-Performance LLM Inference on NVL72
✨ [➡️ link](https://github.com/NVIDIA/TensorRT-LLM/blob/main/docs/source/blogs/tech_blog/blog19_DWDP_Distributed_Weight_Data_Parallelism_for_High_Performance_LLM_Inference_on_NVL72.md)

* [03/16] Optimizing MoE Communication with One-Sided AlltoAll Over NVLink
✨ [➡️ link](https://github.com/NVIDIA/TensorRT-LLM/blob/main/docs/source/blogs/tech_blog/blog18_Optimizing_MoE_Communication_with_One_Sided_AlltoAll_Over_NVLink.md)

Expand All @@ -34,6 +37,8 @@ state-of-the-art optimizations to perform inference efficiently on NVIDIA GPUs.<
* [01/09] Optimizing DeepSeek-V3.2 on NVIDIA Blackwell GPUs
✨ [➡️ link](https://nvidia.github.io/TensorRT-LLM/blogs/tech_blog/blog15_Optimizing_DeepSeek_V32_on_NVIDIA_Blackwell_GPUs)

<details close>
<summary>Previous Blogs</summary>
* [10/13] Scaling Expert Parallelism in TensorRT LLM (Part 3: Pushing the Performance Boundary)
✨ [➡️ link](https://nvidia.github.io/TensorRT-LLM/blogs/tech_blog/blog14_Scaling_Expert_Parallelism_in_TensorRT-LLM_part3.html)

Expand Down Expand Up @@ -69,8 +74,13 @@ state-of-the-art optimizations to perform inference efficiently on NVIDIA GPUs.<

* [05/16] Pushing Latency Boundaries: Optimizing DeepSeek-R1 Performance on NVIDIA B200 GPUs
✨ [➡️ link](https://nvidia.github.io/TensorRT-LLM/blogs/tech_blog/blog1_Pushing_Latency_Boundaries_Optimizing_DeepSeek-R1_Performance_on_NVIDIA_B200_GPUs.html)
</details>

## Latest News
* [04/03] 🎨 TensorRT LLM now supports diffusion models for visual generation [➡️ link](https://github.com/NVIDIA/TensorRT-LLM/blob/main/docs/source/models/visual-generation.md)

<details close>
<summary>Previous News</summary>
* [08/05] 🌟 TensorRT LLM delivers Day-0 support for OpenAI's latest open-weights models: GPT-OSS-120B [➡️ link](https://huggingface.co/openai/gpt-oss-120b) and GPT-OSS-20B [➡️ link](https://huggingface.co/openai/gpt-oss-20b)
* [07/15] 🌟 TensorRT LLM delivers Day-0 support for LG AI Research's latest model, EXAONE 4.0 [➡️ link](https://huggingface.co/LGAI-EXAONE/EXAONE-4.0-32B)
* [06/17] Join NVIDIA and DeepInfra for a developer meetup on June 26 ✨ [➡️ link](https://events.nvidia.com/scaletheunscalablenextgenai)
Expand Down Expand Up @@ -100,10 +110,6 @@ state-of-the-art optimizations to perform inference efficiently on NVIDIA GPUs.<
* [02/12] 🌟 How Scaling Laws Drive Smarter, More Powerful AI
[➡️ link](https://blogs.nvidia.com/blog/ai-scaling-laws/?ncid=so-link-889273&linkId=100000338837832)


<details close>
<summary>Previous News</summary>

* [2025/01/25] Nvidia moves AI focus to inference cost, efficiency [➡️ link](https://www.fierceelectronics.com/ai/nvidia-moves-ai-focus-inference-cost-efficiency?linkId=100000332985606)

* [2025/01/24] 🏎️ Optimize AI Inference Performance with NVIDIA Full-Stack Solutions [➡️ link](https://developer.nvidia.com/blog/optimize-ai-inference-performance-with-nvidia-full-stack-solutions/?ncid=so-twit-400810&linkId=100000332621049)
Expand Down Expand Up @@ -242,7 +248,7 @@ Serverless TensorRT LLM (LLaMA 3 8B) | Modal Docs [➡️ link](https://modal.co

## TensorRT LLM Overview

TensorRT LLM is an open-sourced library for optimizing Large Language Model (LLM) inference. It provides state-of-the-art optimizations, including custom attention kernels, inflight batching, paged KV caching, quantization (FP8, [FP4](https://www.nvidia.com/en-us/data-center/technologies/blackwell-architecture/), INT4 [AWQ](https://arxiv.org/abs/2306.00978), INT8 [SmoothQuant](https://arxiv.org/abs/2211.10438), ...), speculative decoding, and much more, to perform inference efficiently on NVIDIA GPUs.
TensorRT LLM is an open-sourced library for optimizing LLM and Visual Gen inference. It provides state-of-the-art optimizations, including custom kernels for common inference operations (attention, GEMMs, MoE, ...), algorithmic runtime optimizations (Prefill-Decode disaggregation, Wide Expert Parallelism, Speculative Decoding, etc), and much more, to perform inference efficiently on NVIDIA GPUs.

[Architected on PyTorch](https://github.com/NVIDIA/TensorRT-LLM/blob/release/1.1/docs/source/developer-guide/overview.md), TensorRT LLM provides a high-level Python [LLM API](https://nvidia.github.io/TensorRT-LLM/quick-start-guide.html#llm-api) that supports a wide range of inference setups - from single-GPU to multi-GPU or multi-node deployments. It includes built-in support for various parallelism strategies and advanced features. The LLM API integrates seamlessly with the broader inference ecosystem, including NVIDIA [Dynamo](https://github.com/ai-dynamo/dynamo) and the [Triton Inference Server](https://github.com/triton-inference-server/server).

Expand Down
2 changes: 2 additions & 0 deletions cpp/include/tensorrt_llm/common/cudaUtils.h
Original file line number Diff line number Diff line change
Expand Up @@ -236,6 +236,8 @@ template<> struct packed_as<half, 2> { using type =
template<> struct packed_as<float, 2> { using type = float2; };
template<> struct packed_as<int8_t, 2> { using type = int16_t; };
template<> struct packed_as<int32_t, 2> { using type = int2; };
template<> struct packed_as<uint, 2> { using type = uint2; };
template<> struct packed_as<uint, 4> { using type = uint4; };
template<> struct packed_as<half2, 1> { using type = half; };
template<> struct packed_as<float2, 1> { using type = float; };
#ifdef ENABLE_BF16
Expand Down
56 changes: 39 additions & 17 deletions cpp/tensorrt_llm/batch_manager/kvCacheManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,33 @@ std::vector<BlockPtr> getAllSequenceBlocks(BlockPtr lastBlock)
return sequenceBlocks;
}

// Compute maximum number of tokens that have been computed by prefill and generation.
// Accounts for chunked prefill to avoid storing state that hasn't been written to KV cache yet.
// We call LlmRequest::getContextRemainingLength to see how many tokens are still waiting to be computed in prefill.
// If this value is > 0 prefill is not finished yet, and number of computed tokens must be capped at the current context
// position. If it is == 0, we are in generation mode, and number of computed tokens equals number of unique tokens
// stored in request.
SizeType32 getMaterializedUniqueTokenCountForReuse(
VecUniqueTokens const& uniqueTokens, tensorrt_llm::batch_manager::LlmRequest const& llmRequest)
{
auto const totalUniqueTokenCount = static_cast<SizeType32>(uniqueTokens.size());
if (llmRequest.getContextRemainingLength() > 0)
{
return std::min(totalUniqueTokenCount, llmRequest.getContextCurrentPosition());
}
return totalUniqueTokenCount;
}

// Compute number of tokens that can be stored for reuse. The last computed token is never stored in KV cache, hence
// cannot be stored for reuse. Number of tokens that can be stored for reuse is thus the greater of 0 or
// getMaterializedUniqueTokenCountForReuse() - 1.
SizeType32 getUsableUniqueTokenCountForReuse(
VecUniqueTokens const& uniqueTokens, tensorrt_llm::batch_manager::LlmRequest const& llmRequest)
{
auto const materializedUniqueTokenCount = getMaterializedUniqueTokenCountForReuse(uniqueTokens, llmRequest);
return materializedUniqueTokenCount > 0 ? materializedUniqueTokenCount - 1 : 0;
}

} // namespace

namespace tensorrt_llm::batch_manager::kv_cache_manager
Expand Down Expand Up @@ -926,12 +953,9 @@ void BlockManager::storeContextBlocks(GenerationRequest& sequence, LlmRequest co
auto const& uniqueTokens = llmRequest.getUniqueTokens(beamIdx);
TLLM_LOG_DEBUG("storeContextBlocks for request %lu on window %d with %d unique tokens", llmRequest.mRequestId,
windowSize, uniqueTokens.size());
// only store the tokens that have been completed
size_t const completedTokens = llmRequest.getContextCurrentPosition();
auto usableSize = std::min(completedTokens, uniqueTokens.size() - 1);

auto const usableUniqueTokenCount = getUsableUniqueTokenCountForReuse(uniqueTokens, llmRequest);
auto blockedUniqueTokens
= chopVectorIntoBlocks<UniqueToken>(uniqueTokens, usableSize, getTokensPerBlock(), false);
= chopVectorIntoBlocks<UniqueToken>(uniqueTokens, usableUniqueTokenCount, getTokensPerBlock(), false);
auto blockKeys = buildBlockKeys(blockedUniqueTokens, llmRequest);
(void) manager.storeBlocks(std::move(blockKeys), cacheBlockIds[beamIdx]);
}
Expand Down Expand Up @@ -2369,17 +2393,17 @@ std::vector<KVCacheBlock::IdType> WindowBlockManager::storeBlocksForReuse(
auto constexpr beamIdx = 0;
auto const& uniqueTokens = llmRequest->getUniqueTokens(beamIdx);
auto const& cacheBlockIds = sequence.getCacheBlockIds(mWindowSize);
// TODO: get the caller to mark tokens as filled / not filled, so that the kv-cache manager doesn't
// have to guess. Only (length - 1) tokens of the sequence have their kv-state recorded in kv-cache. We assume
// the last token's state is not filled yet.
auto usableSize = static_cast<runtime::SizeType32>(uniqueTokens.size()) - 1;

auto usableUniqueTokenCount = getUsableUniqueTokenCountForReuse(uniqueTokens, *llmRequest);
if (isRecurrentState())
{
usableSize = std::min(llmRequest->getPromptLen() - 1, usableSize); // TODO: enable store for completed sequences
usableUniqueTokenCount = std::min(
llmRequest->getPromptLen() - 1, usableUniqueTokenCount); // TODO: enable store for completed sequences
}
TLLM_LOG_DEBUG("%s::storeBlocksForReuse: req=%lu, windowSize=%d, uniqueTokens.size()=%zu, usableSize=%zu",
mLogPrefix.c_str(), llmRequest->mRequestId, mWindowSize, uniqueTokens.size(), usableSize);
auto blockedUniqueTokens = chopVectorIntoBlocks<UniqueToken>(uniqueTokens, usableSize, mTokensPerBlock, true);
mLogPrefix.c_str(), llmRequest->mRequestId, mWindowSize, uniqueTokens.size(), usableUniqueTokenCount);
auto blockedUniqueTokens
= chopVectorIntoBlocks<UniqueToken>(uniqueTokens, usableUniqueTokenCount, mTokensPerBlock, true);
auto blockKeys = buildBlockKeys(blockedUniqueTokens, *llmRequest);

auto [numStored, pinnedBlockIds] = storeBlocks(std::move(blockKeys), cacheBlockIds[beamIdx], pinBlocks);
Expand Down Expand Up @@ -2414,11 +2438,9 @@ std::optional<KVCacheBlock::IdType> WindowBlockManager::releaseBlocks(
sequence.getRequestId());
}
auto const& uniqueTokens = llmRequest->getUniqueTokens(/*beamIdx=*/0);
// Only (length - 1) tokens of the sequence have their kv-state
// recorded in kv-cache. We assume the last token's state is not filled yet.
auto const usableSize = static_cast<runtime::SizeType32>(uniqueTokens.size()) - 1;
auto blockedUniqueTokens
= chopVectorIntoBlocks<UniqueToken>(uniqueTokens, usableSize, mTokensPerBlock, /*allowPartial=*/true);
auto const usableUniqueTokenCount = getUsableUniqueTokenCountForReuse(uniqueTokens, *llmRequest);
auto blockedUniqueTokens = chopVectorIntoBlocks<UniqueToken>(
uniqueTokens, usableUniqueTokenCount, mTokensPerBlock, /*allowPartial=*/true);
auto blockKeys = buildBlockKeys(blockedUniqueTokens, *llmRequest);

std::vector<KVCacheBlock::IdType> cacheBlockIds(allocatedBlocks.size());
Expand Down
33 changes: 29 additions & 4 deletions cpp/tensorrt_llm/kernels/causalConv1d/causalConv1d.cu
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* and https://github.com/Dao-AILab/causal-conv1d/blob/main/csrc/causal_conv1d_update.cu
* Copyright (c) 2024, Tri Dao.
*
* Copyright (c) 2022-2025, NVIDIA CORPORATION. All rights reserved.
* Copyright (c) 2022-2026, NVIDIA CORPORATION. All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -349,20 +349,45 @@ void causal_conv1d_fwd_launch(ConvParamsBase& params, cudaStream_t stream)
});
}

template <int kWidth, typename input_t, typename weight_t>
void causal_conv1d_fwd_dispatch(ConvParamsBase& params, cudaStream_t stream)
{
bool const isVarlen = params.query_start_loc_ptr != nullptr;
constexpr int kNarrowThreads = 64;
constexpr int kWideThreads = 128;
constexpr int kNElts = sizeof(input_t) == 4 ? 4 : 8;
constexpr int kShortSeqThreshold = kNarrowThreads * kNElts;
// Varlen prefill launches one block per sequence/channel pair, so the per-sequence
// work is usually much smaller than params.seqlen suggests. That path also disables
// the wide vector-load specialization, so the 128-thread kernel tends to overprovision
// threads for many short chunks. Prefer the narrower launch for varlen and for short
// fixed-length inputs; keep the wider launch for long dense sequences.
bool const preferNarrowKernel = isVarlen || params.seqlen <= kShortSeqThreshold;

if (preferNarrowKernel)
{
causal_conv1d_fwd_launch<kNarrowThreads, kWidth, input_t, weight_t>(params, stream);
}
else
{
causal_conv1d_fwd_launch<kWideThreads, kWidth, input_t, weight_t>(params, stream);
}
}

template <typename input_t, typename weight_t>
void causal_conv1d_fwd_cuda(ConvParamsBase& params, cudaStream_t stream)
{
if (params.width == 2)
{
causal_conv1d_fwd_launch<128, 2, input_t, weight_t>(params, stream);
causal_conv1d_fwd_dispatch<2, input_t, weight_t>(params, stream);
}
else if (params.width == 3)
{
causal_conv1d_fwd_launch<128, 3, input_t, weight_t>(params, stream);
causal_conv1d_fwd_dispatch<3, input_t, weight_t>(params, stream);
}
else if (params.width == 4)
{
causal_conv1d_fwd_launch<128, 4, input_t, weight_t>(params, stream);
causal_conv1d_fwd_dispatch<4, input_t, weight_t>(params, stream);
}
}

Expand Down
Loading
Loading