Skip to content

Commit e4aaa93

Browse files
authored
Merge branch 'feat/deepseek_v4' into user/mingyangh/dsv4-oproj-fp8-fuse
2 parents df9dded + d6d1b48 commit e4aaa93

79 files changed

Lines changed: 4578 additions & 2373 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

cpp/include/tensorrt_llm/executor/executor.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -745,6 +745,7 @@ class Request
745745
~Request();
746746

747747
[[nodiscard]] VecTokens getInputTokenIds() const;
748+
[[nodiscard]] SizeType32 getNumInputTokens() const;
748749
[[nodiscard]] SizeType32 getMaxTokens() const;
749750
[[nodiscard]] bool getStreaming() const;
750751
[[nodiscard]] SamplingConfig getSamplingConfig() const;

cpp/tensorrt_llm/executor/request.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,11 @@ VecTokens Request::getInputTokenIds() const
7979
return mImpl->getInputTokenIds();
8080
}
8181

82+
SizeType32 Request::getNumInputTokens() const
83+
{
84+
return mImpl->getNumInputTokens();
85+
}
86+
8287
SizeType32 Request::getMaxTokens() const
8388
{
8489
return mImpl->getMaxNewTokens();

cpp/tensorrt_llm/executor/requestImpl.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,11 @@ class Request::Impl
120120
return mInputTokenIds;
121121
}
122122

123+
[[nodiscard]] SizeType32 getNumInputTokens() const
124+
{
125+
return static_cast<SizeType32>(mInputTokenIds.size());
126+
}
127+
123128
[[nodiscard]] SizeType32 getMaxNewTokens() const
124129
{
125130
return mMaxNewTokens;

cpp/tensorrt_llm/nanobind/executor/request.cpp

Lines changed: 65 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* SPDX-FileCopyrightText: Copyright (c) 2022-2025 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
2+
* SPDX-FileCopyrightText: Copyright (c) 2022-2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
33
* SPDX-License-Identifier: Apache-2.0
44
*
55
* Licensed under the Apache License, Version 2.0 (the "License");
@@ -26,6 +26,7 @@
2626
#include "tensorrt_llm/runtime/cudaStream.h"
2727

2828
#include <nanobind/nanobind.h>
29+
#include <nanobind/ndarray.h>
2930
#include <nanobind/stl/chrono.h>
3031
#include <nanobind/stl/function.h>
3132
#include <nanobind/stl/list.h>
@@ -645,47 +646,69 @@ void initRequestBindings(nb::module_& m)
645646
nb::cast<std::optional<tle::CacheSaltIDType>>(state[33]), nb::cast<std::optional<tle::IdType>>(state[34]));
646647
};
647648

649+
// Convert input_token_ids to VecTokens. Fast path: a 1-D contiguous int32
650+
// ndarray is memcpy'd into the vector (no per-element PyLong cast, which is
651+
// O(ISL) on the GIL-held submit path). Anything else (list[int], etc.) falls
652+
// back to the default nanobind sequence cast, so this is fully back-compatible.
653+
// This complements PR #15134 (which bytes-encodes Request *pickling*); here we
654+
// target Request *construction* on the RpcWorker.submit / _enqueue_request path.
655+
auto toVecTokens = [](nb::handle ids) -> tle::VecTokens
656+
{
657+
nb::ndarray<int32_t const, nb::ndim<1>, nb::c_contig> arr;
658+
if (nb::try_cast(ids, arr, /*convert=*/false))
659+
{
660+
tle::VecTokens out(arr.shape(0));
661+
if (arr.shape(0) > 0)
662+
{
663+
std::memcpy(out.data(), arr.data(), arr.shape(0) * sizeof(int32_t));
664+
}
665+
return out;
666+
}
667+
return nb::cast<tle::VecTokens>(ids);
668+
};
669+
648670
nb::class_<tle::Request> request(m, "Request", nb::dynamic_attr());
649671
request
650-
.def(nb::init<tle::VecTokens, // inputTokenIds
651-
tle::SizeType32, // maxTokens
652-
bool, // streaming
653-
tle::SamplingConfig const&, // samplingConfig
654-
tle::OutputConfig const&, // outputConfig
655-
std::optional<tle::SizeType32> const&, // endId
656-
std::optional<tle::SizeType32> const&, // padId
657-
std::optional<std::vector<SizeType32>>, // positionIds
658-
std::optional<std::list<tle::VecTokens>>, // badWords
659-
std::optional<std::list<tle::VecTokens>>, // stopWords
660-
std::optional<tle::Tensor>, // embeddingBias
661-
std::optional<tle::ExternalDraftTokensConfig>, // externalDraftTokensConfig
662-
std::optional<tle::PromptTuningConfig>, // pTuningConfig
663-
std::optional<tle::MultimodalInput>, // multimodalInput
664-
std::optional<tle::Tensor>, // multimodalEmbedding
665-
std::optional<tle::MropeConfig>, // mRopeConfig
666-
std::optional<tle::LoraConfig>, // loraConfig
667-
std::optional<tle::LookaheadDecodingConfig>, // lookaheadConfig
668-
std::optional<tle::KvCacheRetentionConfig>, // kvCacheRetentionConfig
669-
std::optional<std::string>, // logitsPostProcessorName
670-
std::optional<tle::LogitsPostProcessor>, // logitsPostProcessor
671-
std::optional<tle::VecTokens>, // encoderInputTokenIds
672-
std::optional<tle::IdType>, // clientId
673-
bool, // returnAllGeneratedTokens
674-
tle::PriorityType, // priority
675-
tle::RequestType, // type
676-
std::optional<tle::ContextPhaseParams>, // contextPhaseParams
677-
std::optional<tle::Tensor>, // encoderInputFeatures
678-
std::optional<tle::SizeType32>, // encoderOutputLength
679-
std::optional<tle::Tensor>, // crossAttentionMask
680-
SizeType32, // numReturnSequences
681-
std::optional<tle::EagleConfig>, // eagleConfig
682-
std::optional<tle::Tensor>, // skipCrossAttnBlocks
683-
std::optional<tle::GuidedDecodingParams>, // guidedDecodingParams
684-
std::optional<tle::SizeType32>, // languageAdapterUid
685-
std::optional<tle::MillisecondsType>, // allottedTimeMs
686-
std::optional<tle::CacheSaltIDType>, // cacheSaltID
687-
std::optional<tle::IdType> // disaggRequestId
688-
>(),
672+
.def(
673+
"__init__",
674+
[toVecTokens](tle::Request* self,
675+
nb::handle input_token_ids, // list[int] or int32 ndarray
676+
tle::SizeType32 max_tokens, bool streaming, tle::SamplingConfig const& sampling_config,
677+
tle::OutputConfig const& output_config, std::optional<tle::SizeType32> const& end_id,
678+
std::optional<tle::SizeType32> const& pad_id, std::optional<std::vector<SizeType32>> position_ids,
679+
std::optional<std::list<tle::VecTokens>> bad_words, std::optional<std::list<tle::VecTokens>> stop_words,
680+
std::optional<tle::Tensor> embedding_bias,
681+
std::optional<tle::ExternalDraftTokensConfig> external_draft_tokens_config,
682+
std::optional<tle::PromptTuningConfig> prompt_tuning_config,
683+
std::optional<tle::MultimodalInput> multimodal_input, std::optional<tle::Tensor> multimodal_embedding,
684+
std::optional<tle::MropeConfig> mrope_config, std::optional<tle::LoraConfig> lora_config,
685+
std::optional<tle::LookaheadDecodingConfig> lookahead_config,
686+
std::optional<tle::KvCacheRetentionConfig> kv_cache_retention_config,
687+
std::optional<std::string> logits_post_processor_name,
688+
std::optional<tle::LogitsPostProcessor> logits_post_processor,
689+
std::optional<tle::VecTokens> encoder_input_token_ids, std::optional<tle::IdType> client_id,
690+
bool return_all_generated_tokens, tle::PriorityType priority, tle::RequestType type,
691+
std::optional<tle::ContextPhaseParams> context_phase_params,
692+
std::optional<tle::Tensor> encoder_input_features, std::optional<tle::SizeType32> encoder_output_length,
693+
std::optional<tle::Tensor> cross_attention_mask, SizeType32 num_return_sequences,
694+
std::optional<tle::EagleConfig> eagle_config, std::optional<tle::Tensor> skip_cross_attn_blocks,
695+
std::optional<tle::GuidedDecodingParams> guided_decoding_params,
696+
std::optional<tle::SizeType32> language_adapter_uid,
697+
std::optional<tle::MillisecondsType> allotted_time_ms,
698+
std::optional<tle::CacheSaltIDType> cache_salt_id, std::optional<tle::IdType> disagg_request_id)
699+
{
700+
new (self) tle::Request(toVecTokens(input_token_ids), max_tokens, streaming, sampling_config,
701+
output_config, end_id, pad_id, std::move(position_ids), std::move(bad_words), std::move(stop_words),
702+
std::move(embedding_bias), std::move(external_draft_tokens_config), std::move(prompt_tuning_config),
703+
std::move(multimodal_input), std::move(multimodal_embedding), std::move(mrope_config),
704+
std::move(lora_config), std::move(lookahead_config), std::move(kv_cache_retention_config),
705+
std::move(logits_post_processor_name), std::move(logits_post_processor),
706+
std::move(encoder_input_token_ids), client_id, return_all_generated_tokens, priority, type,
707+
std::move(context_phase_params), std::move(encoder_input_features), encoder_output_length,
708+
std::move(cross_attention_mask), num_return_sequences, std::move(eagle_config),
709+
std::move(skip_cross_attn_blocks), std::move(guided_decoding_params), language_adapter_uid,
710+
allotted_time_ms, cache_salt_id, disagg_request_id);
711+
},
689712
// clang-format off
690713
nb::arg("input_token_ids"),
691714
nb::arg("max_tokens"),
@@ -726,8 +749,9 @@ void initRequestBindings(nb::module_& m)
726749
nb::arg("allotted_time_ms") = nb::none(),
727750
nb::arg("cache_salt_id") = nb::none(),
728751
nb::arg("disagg_request_id") = nb::none()
729-
) // clang-format on
752+
) // clang-format on
730753
.def_prop_ro("input_token_ids", &tle::Request::getInputTokenIds)
754+
.def_prop_ro("num_input_tokens", &tle::Request::getNumInputTokens)
731755
.def_prop_ro("max_tokens", &tle::Request::getMaxTokens)
732756
.def_prop_rw("streaming", &tle::Request::getStreaming, &tle::Request::setStreaming)
733757
.def_prop_rw("sampling_config", &tle::Request::getSamplingConfig, &tle::Request::setSamplingConfig)

jenkins/L0_Test.groovy

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3358,7 +3358,7 @@ def launchTestJobs(pipeline, testFilter)
33583358
fullSet += SBSATestConfigs.keySet()
33593359

33603360
SBSASlurmTestConfigs = [
3361-
"GB200-4_GPUs-PyTorch-DS-1": ["auto:gb200-x4", "l0_gb200_multi_gpus_ds", 1, 1, 4],
3361+
"GB200-4_GPUs-PyTorch-DS-1": ["auto:gb200-x4-split", "l0_gb200_multi_gpus_ds", 1, 1, 4],
33623362
]
33633363
fullSet += SBSASlurmTestConfigs.keySet()
33643364

tensorrt_llm/_torch/attention_backend/flashinfer.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,12 @@
2323
except RuntimeError:
2424
# Override TORCH_CUDA_ARCH_LIST for JIT compilation of flashinfer kernels
2525
# since the existed TORCH_CUDA_ARCH_LIST may be too general and flashinfer requires sm75+.
26-
capability = torch.cuda.get_device_capability()
27-
arch_list = f"{capability[0]}.{capability[1]}"
28-
os.environ["TORCH_CUDA_ARCH_LIST"] = arch_list
26+
# Guard on a visible GPU: with CUDA_VISIBLE_DEVICES="" (pure client) the
27+
# capability query would force a CUDA context at import time.
28+
if torch.cuda.is_available():
29+
capability = torch.cuda.get_device_capability()
30+
arch_list = f"{capability[0]}.{capability[1]}"
31+
os.environ["TORCH_CUDA_ARCH_LIST"] = arch_list
2932

3033
from tensorrt_llm._utils import prefer_pinned
3134

tensorrt_llm/_torch/attention_backend/sparse/deepseek_v4/deepseek_v4.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1174,6 +1174,14 @@ def _run_overlapped_indexer_prepare(
11741174
self.k_cache_update_event.record()
11751175
else:
11761176
weights, k_fp8, k_scale = pre_aux
1177+
# pre_aux tensors were allocated on aux_stream; record on the
1178+
# consuming stream so the caching allocator can't recycle them mid-use.
1179+
cur_stream = torch.cuda.current_stream()
1180+
weights.record_stream(cur_stream)
1181+
if k_fp8 is not None:
1182+
k_fp8.record_stream(cur_stream)
1183+
if k_scale is not None:
1184+
k_scale.record_stream(cur_stream)
11771185
q = self._qk_projection_and_rope(qr, position_ids)
11781186

11791187
q_fp8, q_scale = self._quantize_q(q)

0 commit comments

Comments
 (0)