运行时#
bufferManager.h#
-
namespace tensorrt_llm
-
namespace runtime
-
class BufferManager#
- #include <bufferManager.h>
一个用于管理主机和设备内存的辅助类。
公共类型
-
using CudaStreamPtr = std::shared_ptr<CudaStream>#
-
using CudaMemPoolPtr = std::shared_ptr<CudaMemPool>#
公共函数
-
explicit BufferManager(CudaStreamPtr stream, bool trimPool = false)#
构造一个 BufferManager。
- 参数:
cudaStream – [in] 用于 GPU 上所有操作(分配、释放、复制等)的 cuda 流。
-
inline ~BufferManager()#
析构函数。
- IBufferPtr gpu(
- std::size_t size,
- nvinfer1::DataType type = kBYTE_TYPE,
使用 cudaMallocAsync 在 GPU 上分配给定大小的
IBuffer
。
- ITensorPtr gpu(
- nvinfer1::Dims dims,
- nvinfer1::DataType type = kBYTE_TYPE,
使用 cudaMallocAsync 在 GPU 上分配给定维度的
ITensor
。
- IBufferPtr allocate(
- MemoryType memoryType,
- std::size_t size,
- nvinfer1::DataType type = kBYTE_TYPE,
分配给定大小和内存类型的
IBuffer
。
- ITensorPtr allocate(
- MemoryType memoryType,
- nvinfer1::Dims dims,
- nvinfer1::DataType type = kBYTE_TYPE,
分配给定维度和内存类型的
ITensor
。
- inline IBufferPtr emptyBuffer(
- MemoryType memoryType,
- nvinfer1::DataType type = kBYTE_TYPE,
创建给定内存类型的空
IBuffer
。以后可以调整其大小。
- inline ITensorPtr emptyTensor(
- MemoryType memoryType,
- nvinfer1::DataType type = kBYTE_TYPE,
创建给定内存类型的空
ITensor
。以后可以重塑其维度。
-
void copy(void const *src, IBuffer &dst, MemoryType srcType) const#
将
src
复制到dst
。
-
void copy(IBuffer const &src, void *dst, MemoryType dstType) const#
将
src
复制到dst
。
-
IBufferPtr copyFrom(IBuffer const &src, MemoryType memoryType) const#
将
src
复制到一个新的IBuffer
中,新 buffer 的内存类型可能不同。
-
ITensorPtr copyFrom(ITensor const &src, MemoryType memoryType) const#
将
src
复制到一个新的ITensor
中,新 tensor 的内存类型可能不同。
-
template<typename T>
inline IBufferPtr copyFrom( - std::vector<T> const &src,
- MemoryType memoryType,
将
src
复制到一个新的IBuffer
中,新 buffer 的内存类型可能不同。
-
template<typename T>
inline ITensorPtr copyFrom( - T *src,
- nvinfer1::Dims dims,
- MemoryType memoryType,
将
src
复制到一个新的ITensor
中,新 tensor 的内存类型可能不同。
-
template<typename T>
inline ITensorPtr copyFrom( - std::vector<T> const &src,
- nvinfer1::Dims dims,
- MemoryType memoryType,
将
src
复制到一个新的ITensor
中,新 tensor 的内存类型可能不同。
-
CudaStream const &getStream() const#
获取底层的 cuda 流。
-
std::size_t memoryPoolReserved() const#
内存池保留的当前内存大小。
-
std::size_t memoryPoolUsed() const#
内存池使用的当前内存大小。
-
std::size_t memoryPoolFree() const#
内存池中当前可用的内存大小。
-
void memoryPoolTrimTo(std::size_t size)#
尝试将内存池保留的内存大小修剪到
size
字节。此操作会与流隐式同步。
公共静态函数
- static IBufferPtr gpuSync(
- std::size_t size,
- nvinfer1::DataType type = kBYTE_TYPE,
在 GPU 上使用 cudaMalloc 分配给定大小的
IBuffer
。
- static ITensorPtr gpuSync(
- nvinfer1::Dims dims,
- nvinfer1::DataType type = kBYTE_TYPE,
在 GPU 上使用 cudaMalloc 分配给定维度的
ITensor
。
- static IBufferPtr cpu(
- std::size_t size,
- nvinfer1::DataType type = kBYTE_TYPE,
在 CPU 上分配给定大小的
IBuffer
。
- static ITensorPtr cpu(
- nvinfer1::Dims dims,
- nvinfer1::DataType type = kBYTE_TYPE,
在 CPU 上分配给定维度的
ITensor
。
- static IBufferPtr pinned(
- std::size_t size,
- nvinfer1::DataType type = kBYTE_TYPE,
在 CPU 上分配给定大小的固定
IBuffer
。
- static ITensorPtr pinned(
- nvinfer1::Dims dims,
- nvinfer1::DataType type = kBYTE_TYPE,
在 CPU 上分配给定维度的固定
ITensor
。
- static IBufferPtr pinnedPool(
- std::size_t size,
- nvinfer1::DataType type = kBYTE_TYPE,
在 CPU 的默认内存池中分配给定大小的固定
IBuffer
。
- static ITensorPtr pinnedPool(
- nvinfer1::Dims dims,
- nvinfer1::DataType type = kBYTE_TYPE,
在 CPU 的默认内存池中分配给定维度的固定
ITensor
。
- static IBufferPtr managed(
- std::size_t size,
- nvinfer1::DataType type = kBYTE_TYPE,
在 UVM 中分配给定大小的
IBuffer
。
- static ITensorPtr managed(
- nvinfer1::Dims dims,
- nvinfer1::DataType type = kBYTE_TYPE,
在 UVM 中分配给定维度的
ITensor
。
- static ITensorPtr ipcNvls( )#
为 NVLS 分配给定维度的
ITensor
。
友元
- friend class ::BufferManagerTest
-
using CudaStreamPtr = std::shared_ptr<CudaStream>#
-
class BufferManager#
-
namespace runtime
common.h#
宏定义
-
FMT_DIM#
-
namespace tensorrt_llm
-
namespace runtime
类型定义
-
using SizeType32 = std::int32_t#
-
using SizeType64 = std::int64_t#
-
using TokenIdType = std::int32_t#
-
using LoraTaskIdType = std::uint64_t#
-
using TokenExtraIdType = std::uint64_t#
-
using VecTokenExtraIds = std::vector<TokenExtraIdType>#
-
using VecUniqueTokens = std::vector<UniqueToken>#
-
struct UniqueToken#
公共函数
-
inline bool operator==(UniqueToken const &other) const noexcept#
-
inline bool operator==(UniqueToken const &other) const noexcept#
-
using SizeType32 = std::int32_t#
-
namespace runtime
cudaEvent.h#
-
namespace tensorrt_llm
-
namespace runtime
-
class CudaEvent#
公共类型
-
using pointer = cudaEvent_t#
公共函数
-
inline explicit CudaEvent(unsigned int flags = cudaEventDisableTiming)#
创建一个新的 CUDA 事件。该事件将在析构函数中被销毁。
- 参数:
flags – 事件创建标志。默认情况下,事件计时被禁用。
-
inline explicit CudaEvent(pointer event, bool ownsEvent = true)#
将现有 CUDA 事件传递给此对象。
- 参数:
event – 要传递给此对象的事件。
ownsEvent – 此对象是否拥有该事件并在析构函数中销毁它。
-
inline void synchronize() const#
同步事件。
私有类型
-
using EventPtr = std::unique_ptr<element_type, Deleter>#
-
using pointer = cudaEvent_t#
-
class CudaEvent#
-
namespace runtime
cudaStream.h#
-
namespace tensorrt_llm
-
namespace runtime
-
class CudaStream#
公共函数
- inline explicit CudaStream(
- unsigned int flags = cudaStreamNonBlocking,
- int priority = 0,
在当前设备上创建一个新的 CUDA 流。此流将在析构函数中销毁。
- 参数:
flags – 流创建标志。请参阅 cudaStreamCreateWithFlags 了解可以传递的有效标志列表。
priority – 流的优先级。数字越小代表优先级越高。请参阅 cudaDeviceGetStreamPriorityRange 了解可以传递的有意义的流优先级的更多信息。
- inline explicit CudaStream(
- cudaStream_t stream,
- int device,
- bool ownsStream = true,
将现有 CUDA 流传递给此对象。
- 参数:
stream – 要传递给此对象的流。
device – 创建此流的设备。
ownsStream – 此对象是否拥有该流并在析构函数中销毁它。
-
inline explicit CudaStream(cudaStream_t stream)#
使用现有 CUDA 流或通过传递 nullptr 使用默认流进行构造。
-
inline int getDevice() const#
返回创建此流的设备。
-
inline cudaStream_t get() const#
返回与此对象关联的流。
-
inline void synchronize() const#
同步此流。
友元
- friend class CudaStreamBindings
-
class CudaStream#
-
namespace runtime
decodingInput.h#
-
namespace tensorrt_llm
-
namespace runtime
-
class DecodingInput#
- #include <decodingInput.h>
表示解码器的输入。
此输入类型被假定为不可变。它表示解码器最初接收到的内容,并始终可以这样引用。
公共函数
- inline DecodingInput(
- SizeType32 maxLength,
- SizeType32 maxAttentionWindow,
- SizeType32 sinkTokenLength,
- SizeType32 batchSize,
- TensorConstPtr logits,
- TensorPtr endIds,
- TensorConstPtr batchSlots,
公共成员
-
SizeType32 step#
强制参数 我们正在进行的解码步骤的索引。仅在 Python 运行时中使用。
-
SizeType32 maxLength#
要解码的最大 token 数量。
-
SizeType32 maxAttentionWindow#
解码时要考虑的最大注意力窗口长度。
-
SizeType32 sinkTokenLength#
用作注意力汇聚点的 token 数量,https://arxiv.org/html/2309.17453v3。
-
SizeType32 batchSize#
批次中的样本数量。
-
std::vector<SizeType32> beamWidths#
每个请求的束宽度,[batchSize]。
-
SizeType32 maxStopWordsLen#
`stopWordsLens` 张量中的最大值。
-
SizeType32 maxBadWordsLen#
`badWordsLens` 张量中的最大值。
-
TensorConstPtr logits#
模型前向计算的输出,是词汇表上的概率分布 [batchSize, beamWidth, vocabSizePadded],位于 gpu 上。
-
std::optional<std::vector<TensorConstPtr>> logitsVec#
对 logits 的另一种视图,[batchSize][beamWidth, vocabSizePadded],位于 gpu 上。
-
TensorConstPtr endIds#
结束 ID,[batchSize * beamWidth],位于 gpu 上。
-
TensorConstPtr batchSlots#
线性批次 ID 到序列槽位的地址映射,[batchSize],位于 pinned 内存,类型为 int32_t。
-
TensorConstPtr finishReasons#
可选参数 当前迭代的完成状态(如果为 true,则跳过请求的解码步骤),[batchSize, beamWidth],位于 gpu 上。
-
TensorConstPtr sequenceLimitLength#
批次中每个序列的最大序列长度,[batchSize],位于 gpu 上。
-
TensorConstPtr embeddingBias#
-
TensorConstPtr lengths#
-
TensorConstPtr badWordsPtrs#
-
TensorConstPtr badWordsLens#
-
TensorConstPtr stopWordsPtrs#
-
TensorConstPtr stopWordsLens#
-
TensorConstPtr noRepeatNgramSize#
-
std::optional<MedusaInputs> medusaInputs#
-
std::optional<ExplicitDraftTokensInputs> explicitDraftTokensInputs#
-
std::optional<LookaheadInputs> lookaheadInputs#
-
std::optional<ExternalDraftTokensInputs> externalDraftTokensInputs#
-
std::optional<EagleInputs> eagleInputs#
-
struct EagleInputs#
公共函数
- inline EagleInputs(
- TensorConstPtr nextDraftTokens,
- TensorConstPtr nextDraftLens,
- TensorConstPtr nextDraftPaths,
- TensorConstPtr lastDraftTokens,
- TensorConstPtr lastDraftLens,
- TensorConstPtr lastDraftPaths,
- TensorConstPtr acceptedTokens,
- TensorConstPtr acceptedLens,
- TensorConstPtr acceptedPathIds,
- TensorConstPtr chunkedContextNextTokens,
- TensorConstPtr seqSlots,
公共成员
-
TensorConstPtr nextDraftTokens#
-
TensorConstPtr nextDraftLens#
-
TensorConstPtr nextDraftPaths#
-
TensorConstPtr lastDraftTokens#
-
TensorConstPtr lastDraftLens#
-
TensorConstPtr lastDraftPaths#
-
TensorConstPtr acceptedTokens#
-
TensorConstPtr acceptedLens#
-
TensorConstPtr acceptedPathIds#
-
TensorConstPtr chunkedContextNextTokens#
-
TensorConstPtr seqSlots#
-
class ExplicitDraftTokensInputs#
公共成员
-
TensorConstPtr nextDraftTokens#
-
TensorConstPtr nextFlatTokens#
-
TensorConstPtr nextDraftIndices#
-
TensorConstPtr nextDraftProbs#
-
TensorConstPtr lastDraftTokens#
-
TensorConstPtr lastDraftIndices#
-
TensorConstPtr masks#
-
TensorConstPtr packedPositionIds#
-
TensorConstPtr bestPathLengths#
-
TensorConstPtr bestPathIndices#
-
TensorConstPtr nextGenerationLengths#
-
TensorConstPtr lastPositionIdsBase#
-
TensorConstPtr lastGenerationLengths#
-
TensorConstPtr maxGenLengthDevice#
-
TensorConstPtr seqSlots#
-
TensorConstPtr nextDraftTokens#
-
class ExternalDraftTokensInputs#
-
struct LookaheadInputs#
-
class MedusaInputs#
公共成员
-
TensorConstPtr medusaPaths#
[batchSize, maxTokensPerStep, maxMedusaHeads + 1],在 GPU 上
-
TensorConstPtr medusaTreeIds#
[batchSize, maxTokensPerStep],在 GPU 上
-
std::vector<std::vector<TensorPtr>> medusaLogits#
[batchSize][maxAcceptedDraftTokensPerStep][maxDraftTokens + 1, vocabSizePadded],在 GPU 上
-
TensorConstPtr medusaTargetTokensPerStep#
[batchSize],在 GPU 上
-
TensorConstPtr medusaPaths#
-
class DecodingInput#
-
namespace runtime
decodingOutput.h#
-
namespace tensorrt_llm
-
namespace batch_manager
-
namespace runtime
-
class DecodingOutput#
-
公共成员
-
BeamHypotheses beamHypotheses#
-
std::optional<SpeculativeDecodingOutputs> speculativeDecodingOutputs#
-
std::optional<ExplicitDraftTokensBuffers::Inputs> explicitDraftTokensBuffers#
-
std::optional<LookaheadDecodingBuffers> lookaheadOutputs#
-
std::optional<EagleBuffers::Inputs> eagleBuffers#
公共静态属性
-
static float constexpr kNegativeInfinity = -1e20f#
-
class BeamHypotheses#
公共函数
-
void empty(BufferManager const &manager)#
- void reshape(
- SizeType32 batchSize,
- SizeType32 beamWidth,
- SizeType32 maxSequenceLength,
-
void release()#
-
void init(BufferManager const &manager, TokenIdType endId)#
-
BeamHypotheses slice(SizeType32 batchIndex, SizeType32 size) const#
-
void empty(BufferManager const &manager)#
-
class SpeculativeDecodingOutputs#
-
BeamHypotheses beamHypotheses#
-
class DecodingOutput#
-
namespace batch_manager
eagleBuffers.h#
-
namespace tensorrt_llm
-
namespace batch_manager
-
namespace runtime
-
class EagleBuffers#
公共类型
-
using LlmRequestPtr = std::shared_ptr<tensorrt_llm::batch_manager::LlmRequest>#
-
using RequestVector = std::vector<LlmRequestPtr>#
-
using SizeType32 = runtime::SizeType32#
-
using TensorMap = runtime::StringPtrMap<runtime::ITensor>#
公共函数
- EagleBuffers(
- SizeType32 maxBatchSize,
- SizeType32 maxBeamWidth,
- runtime::BufferManager const &manager,
- runtime::ModelConfig const &modelConfig,
- runtime::WorldConfig const &worldConfig,
- executor::DecodingConfig const &decodingConfig,
- void reshape(
- SizeType32 numCtxSequences,
- SizeType32 numGenSequences,
- runtime::ModelConfig const &modelConfig,
- void setFromInputs(
- RequestVector const &contextRequests,
- RequestVector const &genRequests,
- runtime::ITensor const &requestTypes,
- ITensor const &seqSlots,
- EagleBuffers::Inputs const &decoderBuffers,
- runtime::BufferManager const &manager,
- runtime::ModelConfig const &modelConfig,
- runtime::WorldConfig const &worldConfig,
- void insertInputTensors(
- TensorMap &inputBuffers,
- TensorMap &outputBuffers,
- runtime::WorldConfig const &worldConfig,
私有函数
-
template<typename T>
void setFromInputs( - RequestVector const &contextRequests,
- RequestVector const &genRequests,
- SizeType32 vocabSizePadded,
- ITensor const &seqSlots,
- EagleBuffers::Inputs const &draftBuffers,
- runtime::EagleModule const &eagleModule,
- runtime::BufferManager const &manager,
私有成员
-
std::size_t scanReduceTempStorageBytes = {0}#
-
float mDefaultPosteriorThreshold = {0.09f}#
-
bool mDoGreedySampling = {true}#
-
class EngineOutputs#
-
class Inputs#
公共函数
- void create(
- SizeType32 maxNumSequences,
- BufferManager const &manager,
- ModelConfig const &modelConfig,
- WorldConfig const &worldConfig,
公共成员
-
TensorPtr specDecodingPackedMasks#
[最大批量大小, 最大解码令牌数, 向上取整(最大解码令牌数 / 32)] 或 [生成序列数量, 最大解码令牌数, 向上取整(最大解码令牌数 / 32)]
-
TensorPtr allLayersScores#
[最大批量大小, Eagle层数, 最大解码草稿令牌数 * 最大解码草稿令牌数] 或 [序列数量, Eagle层数, 最大解码草稿令牌数 * 最大解码草稿令牌数]
-
using LlmRequestPtr = std::shared_ptr<tensorrt_llm::batch_manager::LlmRequest>#
-
class EagleBuffers#
-
namespace batch_manager
explicitDraftTokensBuffers.h#
-
namespace tensorrt_llm
-
namespace runtime
-
class ExplicitDraftTokensBuffers#
公共类型
-
using SizeType32 = runtime::SizeType32#
-
using TensorMap = runtime::StringPtrMap<runtime::ITensor>#
公共函数
- ExplicitDraftTokensBuffers(
- SizeType32 maxBatchSize,
- SizeType32 maxBeamWidth,
- runtime::BufferManager const &manager,
- runtime::ModelConfig const &modelConfig,
- runtime::WorldConfig const &worldConfig,
- void reshape(
- SizeType32 numCtxSequences,
- SizeType32 numGenSequences,
- runtime::ModelConfig const &modelConfig,
- void setFromInputs(
- SizeType32 numCtxSequences,
- SizeType32 numGenSequences,
- runtime::ITensor const &requestTypes,
- ITensor const &seqSlots,
- ExplicitDraftTokensBuffers::Inputs const &decoderBuffers,
- ITensor const &contextPositionIds,
- runtime::ModelConfig const &modelConfig,
- runtime::WorldConfig const &worldConfig,
- runtime::BufferManager const &manager,
- runtime::CudaStream const &stream,
- void insertInputTensors(
- TensorMap &inputBuffers,
- TensorMap &outputBuffers,
- runtime::WorldConfig const &worldConfig,
公共成员
-
tensorrt_llm::runtime::ExplicitDraftTokensBuffers::EngineInputs engineInputs#
-
class tensorrt_llm::runtime::ExplicitDraftTokensBuffers::EngineOutputs engineOutputs#
-
std::size_t scanTempStorageBytes = {0}#
私有函数
-
template<typename T>
void setFromInputs( - SizeType32 numCtxSequences,
- SizeType32 numGenSequences,
- SizeType32 vocabSizePadded,
- ITensor const &seqSlots,
- ExplicitDraftTokensBuffers::Inputs const &draftBuffers,
- ITensor const &contextPositionIds,
- runtime::ExplicitDraftTokensModule const &explicitDraftTokensModule,
- runtime::CudaStream const &stream,
-
class EngineInputs : public tensorrt_llm::runtime::ExplicitDraftTokensBuffers::Inputs#
-
class EngineOutputs#
公共成员
-
class Inputs#
由 tensorrt_llm::runtime::ExplicitDraftTokensBuffers::EngineInputs 继承
公共函数
- void create(
- SizeType32 maxNumSequences,
- runtime::BufferManager const &manager,
- runtime::ModelConfig const &modelConfig,
- runtime::WorldConfig const &worldConfig,
公共成员
-
TensorPtr randomDataValidation#
[maxBatchSize, maxNumPaths, maxPathDraftLen] 或 [numGenSequences, maxNumPaths, maxPathDraftLen]
-
TensorPtr draftTokens#
[maxBatchSize, maxNumPaths, maxPathLen] 或 [numGenSequences, maxNumPaths, maxPathLen]
-
TensorPtr draftIndices#
[maxBatchSize, maxNumPaths, maxPathLen] 或 [numGenSequences, maxNumPaths, maxPathLen]
-
TensorPtr draftProbs#
[maxBatchSize, maxNumPaths, maxPathDraftLen, vocabSize] 或 [numGenSequences, maxNumPaths, maxPathDraftLen, vocabSize]
-
using SizeType32 = runtime::SizeType32#
-
class ExplicitDraftTokensBuffers#
-
namespace runtime
generationInput.h#
-
namespace tensorrt_llm
-
namespace runtime
-
class GenerationInput : public tensorrt_llm::runtime::GenericGenerationInput<ITensor::SharedPtr, PromptTuningParams>#
公共类型
-
using Base = GenericGenerationInput<ITensor::SharedPtr, PromptTuningParams>#
公共函数
- inline explicit GenerationInput(
- SizeType32 const endId,
- SizeType32 const padId,
- TensorPtr ids,
- TensorPtr lengths,
- bool packed = false,
-
using Base = GenericGenerationInput<ITensor::SharedPtr, PromptTuningParams>#
-
template<typename TTensor, typename PromptTuningParams>
class GenericGenerationInput# - #include <generationInput.h>
endId
,是标记输入序列结束的 token ID(也称为EOS
或序列结束)。例如,对于词汇量为50,257
个 token 的 GPT2 模型,它是50,256
,padId
,是用于填充的 token ID(即,对于填充序列,填充输入长度或之后位置的槽位)。它可以设置为与endId
相同的值,ids
,是输入 ID 的张量。该张量必须分配在 GPU 上。当输入张量被填充时,ids
的形状是[batchSize, maxInputLength]
,其中batchSize
和maxInputLength
必须遵守传递给GptSession
构造函数的sessionConfig
中的最大尺寸。当输入被打包时,ids
的形状是[numTokens]
,其中numTokens
是批处理中不同序列长度的总和,lengths
,是输入序列长度的张量。该张量必须分配在 GPU 上并包含batchSize
个值,packed
,指示ids
张量是打包的还是填充的。在此版本中,该标志必须与通过ModelConfig
类的实例传递给构造函数的值匹配。在未来的版本中,session 可能会变得更加灵活,并自动填充或打包输入,
embeddingBiasOpt
,是 GPU 上的一个浮点值张量,包含在采样期间添加到 logits 的偏差(作为模型的最后一步,在从隐藏状态到 logits 的投影之后)。该张量必须包含vocabSize
个元素(如传递给构造函数的modelConfig
参数中所定义),badWordsList
,是 GPU 上的一个整数张量,编码了必须从生成序列中禁止的单词列表。其形状如以下所述为[2, badWordsLength]
,或者当批处理中每个序列有不同列表时为[batchSize, 2, badWordsLength]
,stopWordsList
,是 GPU 上的一个整数张量,编码了触发序列生成结束的单词列表。其形状如以下所述为[2, stopWordsLength]
,或者当批处理中每个序列有不同列表时为[batchSize, 2, stopWordsLength]
,maxNewTokens
,是要生成的最大 token 数量。
badWordsList
和stopWordsList
张量具有相同的形状[2, length]
。我们以一个包含三个单词的示例来说明这些列表的表示。第一个单词包含 token[5, 7, 3]
,第二个包含[9, 2]
,第三个由 token[6, 2, 4, 1]
组成。总共有 9 个 token。这就是长度。张量的形状是[2, 9]
。张量的第一行必须包含这 9 个 token ID,第二行必须存储单词长度的 包容性前缀和,如下图所示0 3 5 9 | | | | V V V V [ 5, 7, 3, 9, 2, 6, 2, 4, 1] [ 3, 5, 9, -1, -1, -1, -1, -1, -1]
如果所有单词都只包含一个 token,则张量的最内层维度必须增加 1(例如,对于由单个 token 组成的 4 个单词,长度必须是 5 而不是 4 — 形状是
[2, 5]
)。公共函数
- inline explicit GenericGenerationInput(
- SizeType32 const endId,
- SizeType32 const padId,
- TensorPtr ids,
- TensorPtr lengths,
- bool packed = false,
公共成员
-
SizeType32 endId#
强制参数。
-
SizeType32 padId#
-
bool packed#
-
std::optional<SizeType32> maxNewTokens#
-
PromptTuningParams promptTuningParams#
Ptuning 参数。
-
class GenerationInput : public tensorrt_llm::runtime::GenericGenerationInput<ITensor::SharedPtr, PromptTuningParams>#
-
namespace runtime
generationOutput.h#
-
namespace tensorrt_llm
-
namespace runtime
-
class GenerationOutput : public tensorrt_llm::runtime::GenericGenerationOutput<ITensor::SharedPtr>#
-
template<typename TTensor>
class GenericGenerationOutput# - #include <generationOutput.h>
ids
,是包含输出 token ID 的张量。其形状为[batchSize, beamWidth, maxSeqLength]
,其中maxSeqLength
是maxInputLength
和maxNewTokens
之和。生成后,它包含每个序列的输入 token 的副本,后跟输出 token。当序列短于maxSeqLength
时,会在序列末尾添加填充 token。
注意,此版本的 TensorRT-LLM 中该张量的形状与其先前版本中的形状不同,先前版本中为.
logProbs
,是 GPU 上用于存储生成 token 的对数概率 (log-prob) 的浮点值张量。其形状为[maxNewTokens, batchSize, beamWidth]
。其形状在未来版本中可能会更改,以匹配输出ids
张量的形状。contextLogits
,是 GPU 上用于存储 context logits 的值张量(数据类型与计算类型相同)。其形状为[batchSize, maxSequenceLength, vocabSizePadded]
。如果使用remove_input_padding
,其形状为[packedSize, vocabSizePadded]
。仅当 TensorRT 引擎构建时启用了gather_context_logits
或gather_all_token_logits
参数,此缓冲区才会被填充。推理完成后,您可以在
GenerationOutput.contextLogits
中获取 context logits,这些是 GPU 上的变量。具体获取方法请参考 gptSessionBenchmark.cpp 的示例。需要指出的是,启用此计算可能会影响性能(语言建模头部 (LM head) 必须对所有 context token 执行矩阵乘法,而不仅仅是对最后一个 token)。
generationLogits
,是 GPU 上用于存储生成 logits 的值张量(数据类型与计算类型相同)。其形状为[batchSize, beamWidth, maxOutputLen, vocabSizePadded]
。仅当 TensorRT 引擎构建时启用了gather_generation_logits
或gather_all_token_logits
参数,此缓冲区才会被填充。生成 logits 也可以在推理完成后通过
GenerationOutput.generationLogits
获取。onTokenGenerated
,是在生成循环中调用的回调函数,用于在循环继续执行的同时将新生成的 token 传递给调用者。该回调函数的实现必须接受输出ids
张量、生成step
以及一个布尔标志,该标志指示生成是否完成。
公共类型
-
using Callback = std::function<void(TensorPtr const &ids, SizeType32 step, bool finished)>#
-
class GenerationOutput : public tensorrt_llm::runtime::GenericGenerationOutput<ITensor::SharedPtr>#
-
namespace runtime
gptDecoderBatched.h#
-
namespace tensorrt_llm
-
namespace batch_manager
-
namespace runtime
-
class GptDecoderBatched : public tensorrt_llm::runtime::IGptDecoderBatched#
- #include <gptDecoderBatched.h>
支持动态批处理的 GPT 解码器类。
公共类型
-
using CudaStreamPtr = std::shared_ptr<CudaStream>#
-
using LlmRequestPtr = std::shared_ptr<tensorrt_llm::batch_manager::LlmRequest>#
-
using RequestVector = std::vector<LlmRequestPtr>#
公共函数
- GptDecoderBatched(
- CudaStreamPtr stream,
- SpeculativeDecodingMode const &speculativeDecodingMode,
- nvinfer1::DataType dtype,
- virtual void setup(
- executor::DecodingMode const &mode,
- SizeType32 maxBatchSize,
- SizeType32 maxBeamWidth,
- SizeType32 maxAttentionWindow,
- SizeType32 sinkTokenLength,
- SizeType32 maxSequenceLength,
- SizeType32 maxTokensPerStep,
- nvinfer1::DataType dtype,
- ModelConfig const &modelConfig,
- WorldConfig const &worldConfig,
在调用
forward()
之前设置解码器
- virtual void disableLookahead(
- RequestVector const &genRequests,
- TensorPtr const &batchSlots,
禁用 Lookahead 解码。
- virtual CudaEvent forwardAsync(
- decoder_batch::Output &output,
- decoder_batch::Input const &input,
对所有请求运行一个步骤,不阻塞主机进程,并返回事件以进行同步。
- virtual void forward(
- decoder_batch::Output &output,
- decoder_batch::Input const &input,
对所有请求运行一个步骤,并在主机上等待完成。
- virtual CudaEvent finalize(
- decoder::DecoderState const &decoderState,
- SizeType32 batchSlot,
- SamplingConfig const &samplingConfig,
- bool streaming,
收集请求
batchSlot
的最终 Beam Search 结果。结果仅在返回事件后可用。
-
inline decoder::DecoderState &getDecoderState()#
-
inline decoder::DecoderState const &getDecoderState() const#
-
inline CudaStreamPtr getDecoderStream() const#
-
inline IGptDecoder &getUnderlyingDecoder() const#
-
inline BufferManager const &getBufferManager() const#
私有类型
-
using GptDecoderPtr = std::unique_ptr<IGptDecoder>#
私有函数
-
void setExplicitDraftTokensInputs(decoder_batch::Input const &input)#
设置显式草稿 token 的输入。
-
void setEagleInputs(decoder_batch::Input const &input)#
设置用于 eagle 解码的输入。
- void forwardDispatch(
- decoder_batch::Output &output,
- decoder_batch::Input const &input,
为每个引擎步骤调用解码器以处理令牌。
- void prepareForward(
- SizeType32 step,
- decoder_batch::Output &output,
- decoder_batch::Input const &input,
准备解码器步骤的输入和输出。
私有成员
-
CudaStreamPtr mRuntimeStream#
-
CudaStreamPtr mDecoderStream#
-
BufferManager mBufferManager#
-
GptDecoderPtr mDecoder#
-
std::shared_ptr<decoder::DecoderState> mDecoderState#
-
using CudaStreamPtr = std::shared_ptr<CudaStream>#
-
class GptDecoderBatched : public tensorrt_llm::runtime::IGptDecoderBatched#
-
namespace batch_manager
gptSession.h#
-
namespace tensorrt_llm
-
namespace batch_manager
-
namespace kv_cache_manager
-
namespace kv_cache_manager
-
namespace runtime
-
class GptSession#
-
公共函数
- GptSession(
- Config const &sessionConfig,
- ModelConfig const &modelConfig,
- WorldConfig const &worldConfig,
- RawEngine const &rawEngine,
- LoggerPtr logger = nullptr,
- 参数:
sessionConfig – 会话配置,
modelConfig – 模型描述,
worldConfig – 环境描述,
rawEngine – 编译后的 TensorRT 引擎,
logger – 可选的日志记录器。
- inline GptSession(
- Config const &sessionConfig,
- ModelConfig const &modelConfig,
- WorldConfig const &worldConfig,
- void const *engineBuffer,
- std::size_t engineSize,
- LoggerPtr logger = nullptr,
- inline GptSession(
- Config const &sessionConfig,
- ModelConfig const &modelConfig,
- WorldConfig const &worldConfig,
- std::vector<uint8_t> const &engineBuffer,
- LoggerPtr logger = nullptr,
- GptSession(
- Config const &sessionConfig,
- ModelConfig const &modelConfig,
- WorldConfig const &worldConfig,
- std::string const &engineFile,
- LoggerPtr logger = nullptr,
-
BufferManager const &getBufferManager() const#
-
BufferManager::CudaStreamPtr getRuntimeStreamPtr() const#
-
inline ModelConfig const &getModelConfig() const#
-
inline WorldConfig const &getWorldConfig() const#
-
inline int getDevice() const noexcept#
-
inline bool getNormalizeLogProbs() const noexcept#
-
inline bool getGatherGenerationLogits() const#
- GenerationOutput &outputs,
- GenerationInput const &inputs,
- SamplingConfig const &samplingConfig,
- std::shared_ptr<GenerationProfiler> const generationProfiler = nullptr,
此函数执行生成循环。
给定要读取的输入张量和要填充的输出张量,该成员函数可以生成结果,或者每个序列已达到完成状态(因为生成过程将运行生成循环,直到达到最大令牌数,或者遇到“序列结束”令牌或“停止词”列表中的某个词)。该函数的伪代码如下所示(成员函数名称已更改以保持说明简单)
// Have all the sequences in the batch reached completion? bool allFinished = false; // Until all sequences are finished or the number of steps reaches the limit... for (int step = 0; !allFinished && step < maxNewTokens; ++step) { // Trigger the computation of the logits... computeLogits(...); // Run the sampling to produce a token (for each active sequence) from the logits. allFinished = generateTokensFromLogits(...); // Callback to stream the output tokens while the generation loop continues. onTokenGenerated(...); }
-
void setLayerProfiler()#
设置 LayerProfiler 以收集每层的性能信息。
-
std::string getLayerProfileInfo() const#
打印每层的性能分析信息。
私有类型
-
using BaseKVCacheManager = batch_manager::kv_cache_manager::BaseKVCacheManager#
-
using KvCacheConfig = batch_manager::kv_cache_manager::KvCacheConfig#
-
using TokenGeneratedCallback = std::function<void(SizeType32 step, bool finished)>#
私有函数
-
inline bool useCudaGraphs()#
- std::vector<GenerationOutput> µBatchesOutputs,
- std::vector<GenerationInput> const µBatchesInputs,
- SamplingConfig const &samplingConfig,
- TokenGeneratedCallback const &onTokenGenerated,
- std::shared_ptr<GenerationProfiler> const generationProfiler,
-
void createContexts()#
-
void createBuffers(SizeType32 numMicroBatches)#
- void createDecoders(
- SizeType32 batchSize,
- SizeType32 beamWidth,
- SizeType32 maxAttentionWindow,
- SizeType32 sinkTokenLength,
- SizeType32 maxSequenceLength,
- nvinfer1::DataType logitsType,
- bool decoderPerRequest,
- SizeType32 numMicroBatches,
- executor::DecodingMode const &decodingMode,
- void createKvCacheManager(
- SizeType32 batchSize,
- SizeType32 beamWidth,
- SizeType32 maxAttentionWindow,
- SizeType32 sinkTokenLength,
- SizeType32 maxSequenceLength,
- KvCacheConfig const &config,
- void createCustomAllReduceWorkspace(
- SizeType32 batchSize,
- SizeType32 beamWidth,
- SizeType32 maxSequenceLength,
- void executeContextStep(
- std::vector<GenerationInput> const &generationBatchesInputs,
- std::vector<SizeType32> const &generationBatchesOffsets,
- BaseKVCacheManager const *kvCacheManager,
- SizeType32 executeGenerationStep(
- SizeType32 step,
- std::vector<GenerationInput> const µBatchesInputs,
- std::vector<GenerationOutput> µBatchesOutputs,
- std::vector<SizeType32> const µBatchOffsets,
- BaseKVCacheManager *kvCacheManager,
- std::vector<bool> µBatchesFinished,
- void decoderStepAsync(
- SizeType32 decoderStep,
- SizeType32 microBatchId,
在最后一个 PP 级别执行解码器,在其他 PP 级别接收解码器输出。
- bool shouldStopSync(
- SizeType32 batchSize,
- SizeType32 beamWidth,
- SizeType32 microBatchId,
与解码器同步并返回
shouldStop
标志。
- void finalize(
- SizeType32 microBatchId,
- SamplingConfig const &samplingConfig,
在最后一个 PP 级别收集最终输出 ID 和 log prob,并将其发送到第一个 PP 级别。
主机上的接收是异步的,因此在访问前需要进行同步。
- void kvCacheAddSequences(
- SizeType32 beamWidth,
- SizeType32 microBatchId,
- SizeType32 firstBatchIdx,
- ITensor::SharedPtr initDecoder(
- ITensor &outputIds,
- GenerationInput const &inputs,
- GenerationOutput const &outputs,
- SamplingConfig const &samplingConfig,
- SizeType32 microBatchId,
填充 outputIds 并返回对 newTokens 张量的引用。
- TokenGeneratedCallback createOnTokenGeneratedCallback(
- GenerationOutput &outputs,
-
bool shouldUseKVCacheManager() const#
私有成员
-
ModelConfig const mModelConfig#
-
WorldConfig const mWorldConfig#
-
int mDevice = {-1}#
-
std::shared_ptr<NcclCommunicator> mPipelineComm#
-
std::shared_ptr<CudaStream> mCommStream#
-
std::shared_ptr<AllReduceBuffers> mAllReduceBuffers#
-
SizeType32 mDecoderMaxSequenceLength = {}#
-
std::vector<SizeType32> mDecoderMaxAttentionWindowVec = {}#
-
SizeType32 mDecoderMaxAttentionWindow = {}#
-
SizeType32 mDecoderSinkTokenLength = {}#
-
std::shared_ptr<TllmRuntime> mRuntime#
-
std::shared_ptr<BaseKVCacheManager> mKvCacheManager#
-
MicroBatchConfig mMicroBatchConfig#
-
std::vector<std::shared_ptr<IStatefulGptDecoder>> mDecoders#
-
std::vector<std::shared_ptr<RuntimeBuffers>> mBuffers#
-
bool mCudaGraphMode = {false}#
-
std::vector<CudaGraphExecutor> mCudaGraphInstances#
-
bool mNormalizeLogProbs = {true}#
-
bool mGatherGenerationLogits = {false}#
友元
- friend class batch_manager::TrtGptModelV1
-
class Config#
- #include <gptSession.h>
会话执行和缓冲区大小的配置。可以在调用
generate
时使用的批量大小和束搜索宽度小于配置的参数。maxBatchSize
将被微批量数量划分,以初始化每个批量缓冲区。公共函数
- inline Config(
- SizeType32 maxBatchSize,
- SizeType32 maxBeamWidth,
- SizeType32 maxSequenceLength,
- float gpuWeightsPercent = 1.0,
公共成员
-
SizeType32 maxBatchSize#
-
SizeType32 maxBeamWidth#
-
SizeType32 maxSequenceLength#
-
bool useGpuDirectStorage = {false}#
-
float gpuWeightsPercent#
-
bool decoderPerRequest = {false}#
-
bool cudaGraphMode = {false}#
-
KvCacheConfig kvCacheConfig = {}#
-
std::optional<SizeType32> ctxMicroBatchSize = std::nullopt#
-
std::optional<SizeType32> genMicroBatchSize = std::nullopt#
-
std::optional<executor::DecodingMode> decodingMode = std::nullopt#
-
bool normalizeLogProbs = true#
-
bool gatherGenerationLogits = false#
-
class CudaGraphExecutor#
公共函数
-
CudaGraphExecutor() = default#
-
inline ~CudaGraphExecutor()#
-
inline bool hasInstance()#
-
void clear()#
- void prepareNextGraph(
- TllmRuntime const &runtime,
- SizeType32 nextContextId,
-
void launch(CudaStream const &stream)#
私有函数
-
void create(cudaGraph_t const &graph)#
-
bool update(cudaGraph_t const &graph)#
-
void uploadToStream(CudaStream const &stream)#
私有成员
-
cudaGraphExec_t mInstance#
-
CudaGraphExecutor() = default#
-
class GenerationProfiler#
- #include <gptSession.h>
用于对推理请求的生成阶段进行性能分析的可选分析器类。
公共静态属性
-
static constexpr unsigned int flags = {cudaEventDefault}#
-
static constexpr unsigned int flags = {cudaEventDefault}#
-
class MicroBatchConfig#
公共函数
-
inline MicroBatchConfig()#
- explicit MicroBatchConfig(
- SizeType32 maxBatchSize,
- SizeType32 pipelineParallelism,
- std::optional<SizeType32> genMicroBatchSize,
- std::optional<SizeType32> ctxMicroBatchSize,
-
inline constexpr SizeType32 numCtxPerGen() const#
- inline constexpr SizeType32 getGenGraphId(
- SizeType32 flipFlopId,
- SizeType32 generationBatchId,
在每个生成批次之间切换使用两个图实例。
公共成员
-
SizeType32 numCtxBatches#
-
SizeType32 numGenBatches#
-
SizeType32 ctxBatchSize#
-
SizeType32 genBatchSize#
-
inline MicroBatchConfig()#
-
class GptSession#
-
namespace batch_manager
gptDecoder.h#
-
namespace tensorrt_llm
-
namespace layers#
-
namespace runtime
函数
- inline runtime::ITensor::SharedConstPtr getDefaultBatchSlots(
- runtime::SizeType32 batchSize,
用于生成批次槽 [0, 1, ..., batchSize - 1] 的辅助函数,适用于未向解码器明确提供批次槽的路径。
-
template<typename T>
class GptDecoder : public virtual tensorrt_llm::runtime::IGptDecoder# 公共类型
-
using CudaStreamPtr = BufferManager::CudaStreamPtr#
公共函数
- executor::DecodingMode const &mode,
- size_t maxBatchSize,
- size_t maxBeamWidth,
- size_t vocabSize,
- size_t vocabSizePadded,
- size_t maxSequenceLength,
- CudaStreamPtr const &stream,
- std::shared_ptr<SpeculativeDecodingModule const> speculativeDecodingModule = nullptr,
- virtual void setup(
- SamplingConfig const &samplingConfig,
- size_t batchSize,
- TensorConstPtr const &batchSlots,
- std::optional<DecodingOutput> const &output = std::nullopt,
- std::optional<std::vector<decoder_batch::Request> const> const &requests = std::nullopt,
- virtual void forwardAsync(
- DecodingOutput &output,
- DecodingInput const &input,
- virtual void forwardSync(
- DecodingOutput &output,
- DecodingInput const &input,
-
inline virtual SamplingConfig const &getSamplingConfig() const override#
- virtual void disableLookahead(
- std::optional<SamplingConfig> const &samplingConfig,
- SizeType32 batchSize,
- TensorConstPtr batchSlots,
私有成员
-
std::shared_ptr<BufferManager> mManager#
-
std::shared_ptr<tensorrt_llm::layers::DynamicDecodeLayer<T>> mDynamicDecodeLayer#
-
std::shared_ptr<tensorrt_llm::runtime::DecodingLayerWorkspace> mDecodingLayerWorkspace#
-
SamplingConfig mSamplingConfig#
-
size_t mMaxBatchSize#
-
size_t mVocabSize#
-
size_t mVocabSizePadded#
-
executor::DecodingMode mDecodingMode#
-
using CudaStreamPtr = BufferManager::CudaStreamPtr#
-
class IGptDecoder#
被子类 tensorrt_llm::runtime::GptDecoder< T > 继承
公共类型
-
using TensorConstPtr = runtime::ITensor::SharedConstPtr#
公共函数
-
virtual ~IGptDecoder() = default#
- virtual void setup(
- SamplingConfig const &samplingConfig,
- size_t batchSize,
- TensorConstPtr const &batchSlots,
- std::optional<DecodingOutput> const &output = std::nullopt,
- std::optional<std::vector<decoder_batch::Request> const> const &requests = std::nullopt,
- virtual void forwardAsync(
- DecodingOutput &output,
- DecodingInput const &input,
- virtual void forwardSync(
- DecodingOutput &output,
- DecodingInput const &input,
-
virtual SamplingConfig const &getSamplingConfig() = 0#
- virtual void disableLookahead(
- std::optional<SamplingConfig> const &samplingConfig,
- SizeType32 batchSize,
- TensorConstPtr batchSlots,
公共静态函数
- executor::DecodingMode const &mode,
- nvinfer1::DataType dtype,
- size_t maxBatchSize,
- size_t maxBeamWidth,
- size_t vocabSize,
- size_t vocabSizePadded,
- size_t maxSequenceLength,
- BufferManager::CudaStreamPtr const &stream,
- std::shared_ptr<SpeculativeDecodingModule const> const &speculativeDecodingModule = nullptr,
-
using TensorConstPtr = runtime::ITensor::SharedConstPtr#
-
namespace layers#
iGptDecoderBatched.h#
-
namespace tensorrt_llm
-
namespace batch_manager
-
namespace runtime
-
class IGptDecoderBatched#
- #include <iGptDecoderBatched.h>
支持动态批处理的 GPT 解码器类。
被子类 tensorrt_llm::runtime::GptDecoderBatched 继承
公共类型
-
using CudaStreamPtr = std::shared_ptr<CudaStream>#
-
using LlmRequestPtr = std::shared_ptr<tensorrt_llm::batch_manager::LlmRequest>#
-
using RequestVector = std::vector<LlmRequestPtr>#
公共函数
- virtual void setup(
- executor::DecodingMode const &mode,
- SizeType32 maxBatchSize,
- SizeType32 maxBeamWidth,
- SizeType32 maxAttentionWindow,
- SizeType32 sinkTokenLength,
- SizeType32 maxSequenceLength,
- SizeType32 maxTokensPerStep,
- nvinfer1::DataType dtype,
- ModelConfig const &modelConfig,
- WorldConfig const &worldConfig,
在调用
forward()
之前设置解码器
- virtual void disableLookahead(
- RequestVector const &genRequests,
- TensorPtr const &batchSlots,
禁用 Lookahead 解码。
- virtual CudaEvent forwardAsync(
- decoder_batch::Output &output,
- decoder_batch::Input const &input,
对所有请求运行一个步骤,不阻塞主机进程,并返回事件以进行同步。
- virtual void forward(
- decoder_batch::Output &output,
- decoder_batch::Input const &input,
对所有请求运行一个步骤,并在主机上等待完成。
- virtual CudaEvent finalize(
- decoder::DecoderState const &decoderState,
- SizeType32 batchSlot,
- SamplingConfig const &samplingConfig,
- bool streaming,
收集请求
batchIdx
的最终束搜索结果。结果只在事件返回后可用。
-
using CudaStreamPtr = std::shared_ptr<CudaStream>#
-
namespace decoder#
-
namespace decoder_batch#
-
class Input#
-
公共函数
- inline explicit Input(
- std::vector<std::vector<TensorConstPtr>> const &logits,
- SizeType32 maxDecoderSteps,
-
inline explicit Input(std::vector<TensorConstPtr> const &logits)#
公共成员
-
std::vector<std::vector<TensorConstPtr>> logits#
强制参数。
[maxDecoderSteps][batchSize][1, beamWidth, vocabSizePadded],在 GPU 上
-
SizeType32 maxDecoderSteps#
活动 slot 的解码 token 的最大数量。
-
std::vector<std::vector<TensorPtr>> predictedDraftLogits#
[maxBatchSize][maxAcceptedDraftTokensPerStep][maxDraftTokens + 1, vocabSizePadded]
-
std::optional<ExplicitDraftTokensBuffers::EngineOutputs> explicitDraftTokensInputs#
显式草稿令牌数据。
-
std::optional<ExplicitDraftTokensBuffers::EngineInputs> explicitDraftTokensLastInputs#
-
std::optional<EagleBuffers::EngineOutputs> eagleInputs#
std::optional<EagleBuffers::EngineOutputs> eagleInputs#
-
Eagle 数据。
-
std::optional<EagleBuffers::Inputs> eagleLastInputs#
-
公共函数
-
class Output#
-
class Output#
-
class Input#
-
class IGptDecoderBatched#
-
namespace batch_manager
Output() = default#
-
namespace tensorrt_llm
-
namespace runtime
-
TensorPtr cacheIndirection#
公共函数
- gptJsonConfig.h#
- class GptJsonConfig#,
- inline GptJsonConfig(,
- std::string name,
- std::string version,
- SizeType32 pipelineParallelism,
- std::string precision,
- SizeType32 tensorParallelism,
- SizeType32 contextParallelism,
- SizeType32 gpusPerNode,
-
ModelConfig modelConfig
-
std::optional<RuntimeDefaults> runtimeDefaults = std::nullopt
-
inline ModelConfig const &getModelConfig() const#
-
inline ModelConfig &getModelConfigMutable()#
-
inline std::string const &getName() const#
-
inline std::string const &getVersion() const#
-
inline std::string const &getPrecision() const#
-
inline SizeType32 constexpr getTensorParallelism() const#
-
inline SizeType32 constexpr getPipelineParallelism() const#
-
inline SizeType32 constexpr getContextParallelism() const#
-
inline SizeType32 constexpr getGpusPerNode() const#
- inline SizeType32 constexpr getWorldSize() const#
- WorldConfig const &worldConfig,
- inline std::optional<RuntimeDefaults> getRuntimeDefaults() const#,
- std::string const &model
- WorldConfig const &worldConfig,
公共静态函数
-
inline std::string engineFilename(
-
) const#
-
static GptJsonConfig parse(std::string const &json)#
私有成员
-
static GptJsonConfig parse(std::istream &json)#
-
static GptJsonConfig parse(std::filesystem::path const &path)#
-
std::string const mName#
-
std::string const mVersion#
-
std::string const mPrecision#
-
SizeType32 const mTensorParallelism#
-
SizeType32 const mPipelineParallelism#
-
SizeType32 const mContextParallelism#
-
SizeType32 const mGpusPerNode#
-
TensorPtr cacheIndirection#
-
namespace runtime
ModelConfig mModelConfig#
-
namespace tensorrt_llm
-
namespace batch_manager
-
namespace runtime
-
std::optional<RuntimeDefaults> mRuntimeDefaults#
- iStatefulGptDecoder.h#
支持动态批处理的 GPT 解码器类。
class IStatefulGptDecoder#
公共函数
- using CudaStreamPtr = std::shared_ptr<CudaStream>#
- executor::DecodingMode const &mode,
- SizeType32 maxBatchSize,
- SizeType32 maxBeamWidth,
- SizeType32 maxAttentionWindow,
- SizeType32 sinkTokenLength,
- SizeType32 maxSequenceLength,
- nvinfer1::DataType dtype,
- ModelConfig const &modelConfig,
- WorldConfig const &worldConfig,
- virtual void setup(
- GenerationInput const &inputs,
- GenerationOutput const &outputs,
- SamplingConfig const &samplingConfig,
- ModelConfig const &modelConfig,
在调用
forward()
之前设置解码器,也调用 reshapeBuffers。
- virtual void forwardAsync( ) = 0#
在不阻塞主机线程的情况下,为所有请求运行一步。
-
virtual void forwardSync() = 0#
等待对
forwardAsync
的最后一次调用完成。
-
virtual void finalize(SamplingConfig const &samplingConfig) const = 0#
收集所有请求的最终束搜索结果。
-
virtual TensorPtr getIds() const = 0#
- 返回:
[batchSize, beamWidth, maxSequenceLength],所有 token id,在 GPU 上
-
virtual TensorPtr getGatheredIds() const = 0#
- 返回:
[batchSize, beamWidth, maxSequenceLength] 在 gatherTree 后的 token id
-
virtual TensorPtr getLogProbs() const = 0#
- 返回:
[batchSize, maxBeamWidth, maxSequenceLength],对数概率(每个 beam),在 GPU 上
-
virtual TensorPtr getNewTokens(SizeType32 iter = 0) const = 0#
获取上一次 forward 传递中一步生成的 token。
- 参数:
**iter** – 要获取 token 的迭代次数,范围在 [0; maxTokensPerStep) 内
- 返回:
[batchSize, beamWidth],在
iter
中生成的 token(每个 beam),在 GPU 上
-
virtual ~IStatefulGptDecoder() = default#
保护函数
-
IStatefulGptDecoder() = default#
-
std::optional<RuntimeDefaults> mRuntimeDefaults#
-
namespace batch_manager
iBuffer.h#
-
namespace tensorrt_llm
-
namespace runtime
类型定义
枚举
函数
-
template<typename T>
T const *bufferCast(IBuffer const &buffer)# 获取指向缓冲区底层常量数据的类型化指针。
- 模板参数:
**T** – 底层数据的类型。
- 参数:
**buffer** – 要获取指针的缓冲区。
- 返回:
指向常量
T
的指针。
-
template<typename T>
T *bufferCast(IBuffer &buffer)# 获取指向缓冲区底层数据的类型化指针。
- 模板参数:
**T** – 底层数据的类型。
- 参数:
**buffer** – 要获取指针的缓冲区。
- 返回:
指向
T
的指针。
-
)#
检索指向 bufferPtr 指向的缓冲区底层数据的 T 类型指针,如果 bufferPtr 为空则返回 nullptr。
- 模板参数:
**T** – 底层数据的类型。
- 参数:
**bufferPtr** – 可能为空的共享指针。
- 返回:
指向 T 的指针,可能为 nullptr。
- IBuffer::SharedConstPtr const &bufferPtr,
检索指向 bufferPtr 指向的缓冲区底层常量数据的 T 类型指针,如果 bufferPtr 为空则返回 nullptr。
- 模板参数:
**T** – 底层数据的类型。
- 参数:
**bufferPtr** – 可能为空的共享指针。
- 返回:
指向常量 T 的指针,可能为 nullptr。
-
)#
检索指向 optionalBufferPtr 中包含的缓冲区指针指向的缓冲区底层数据的 T 类型指针,如果 optional 没有值,则返回 nullptr。
- 模板参数:
**T** – 底层数据的类型。
- 参数:
optionalBufferPtr – 可能为空的 optional 对象。
- 返回:
指向 T 的指针,可能为 nullptr。
- std::optional<IBuffer::SharedConstPtr> const &optionalBufferPtr,
检索指向 optionalBufferPtr 中包含的缓冲区指针指向的缓冲区底层数据的 T const 类型指针,如果 optional 没有值,则返回 nullptr。
- 模板参数:
**T** – 底层数据的类型。
- 参数:
optionalBufferPtr – 可能为空的 optional 对象。
- 返回:
指向常量 T 的指针,可能为 nullptr。
-
class BufferDataType#
- #include <iBuffer.h>
围绕
nvinfer1::DataType
的包装器,提供对指针类型的支持。公共函数
- inline constexpr BufferDataType(
- nvinfer1::DataType dataType,
- bool _unsigned = false,
- bool pointer = false,
-
inline constexpr bool isPointer() const noexcept#
-
inline constexpr bool isUnsigned() const#
-
inline constexpr std::size_t getSize() const noexcept#
-
inline constexpr std::size_t getSizeInBits() const noexcept#
-
template<typename T>
class BufferRange : public tensorrt_llm::common::ArrayView<T># 公共类型
-
using Base = tensorrt_llm::common::ArrayView<T>#
-
using Base = tensorrt_llm::common::ArrayView<T>#
-
template<nvinfer1::DataType kDataType, bool kIsUnsigned = false, bool kIsPointer = false>
struct DataTypeTraits# - #include <iBuffer.h>
用于将 TensorRT 数据类型转换为 C++ 数据类型。
-
template<nvinfer1::DataType kDataType, bool kUnsigned>
struct DataTypeTraits<kDataType, kUnsigned, true>#
-
template<bool kUnsigned>
struct DataTypeTraits<nvinfer1::DataType::kBOOL, kUnsigned># 公共类型
-
using type = bool#
-
using type = bool#
-
template<bool kUnsigned>
struct DataTypeTraits<nvinfer1::DataType::kUINT8, kUnsigned># 公共类型
-
using type = std::uint8_t#
-
using type = std::uint8_t#
-
class IBuffer#
继承自 tensorrt_llm::runtime::ITensor
公共类型
公共函数
-
virtual void *data() = 0#
返回指向底层数组的指针。
-
virtual void const *data() const = 0#
返回指向底层数组的指针。
-
inline virtual void *data(std::size_t index)#
返回指向底层数组中给定元素索引处的指针。
-
inline virtual void const *data(std::size_t index) const#
返回指向底层数组中给定元素索引处的指针。
-
virtual std::size_t getSize() const = 0#
返回缓冲区的大小(元素个数)。
-
inline virtual std::size_t getSizeInBytes() const#
返回缓冲区的大小(以字节为单位)。
-
virtual std::size_t getCapacity() const = 0#
返回缓冲区的容量。
-
virtual char const *getDataTypeName() const#
-
virtual MemoryType getMemoryType() const = 0#
返回缓冲区的内存类型。
-
virtual char const *getMemoryTypeName() const#
-
virtual void resize(std::size_t newSize) = 0#
调整缓冲区大小。如果新大小小于或等于当前容量,则此操作无效。
-
virtual void release() = 0#
释放缓冲区。它将被重置为 nullptr。
-
virtual ~IBuffer() = default#
公共静态函数
- SharedPtr buffer,
- std::size_t offset,
- std::size_t size,
在底层
buffer
上创建一个切片视图。该视图将具有与buffer
相同的数据类型。- 参数:
buffer – 要查看的缓冲区。
offset – 视图的偏移量。
size – 视图的大小。
- 返回:
buffer
的一个视图。
-
template<typename TConstPtr, std::enable_if_t<std::is_const_v<PointerElementType<TConstPtr>>, int> = 0>
static inline UniqueConstPtr slice( - TConstPtr &&tensor,
- std::size_t offset,
- std::size_t size,
-
template<typename TConstPtr, std::enable_if_t<std::is_const_v<PointerElementType<TConstPtr>>, int> = 0>
static inline UniqueConstPtr slice( - TConstPtr &&tensor,
- std::size_t offset,
返回底层
tensor
的一个视图,该视图可以独立调整大小。- 参数:
tensor – 要查看的张量。
- 返回:
tensor
的一个视图。
返回底层
tensor
的一个具有不同大小的视图。- 参数:
tensor – 要查看的张量。
size – 视图的大小。
- 返回:
tensor
的一个视图。
-
template<typename TConstPtr, std::enable_if_t<std::is_const_v<PointerElementType<TConstPtr>>, int> = 0>
static inline UniqueConstPtr view( - TConstPtr &&tensor,
- std::size_t size,
- static UniquePtr wrap(
- void *data,
- DataType type,
- std::size_t size,
- std::size_t capacity,
将给定的
data
封装在IBuffer
中。IBuffer
不拥有底层data
,且不能调整大小超过capacity
。- 参数:
data – 要封装的数据。
type –
data
的数据类型。size – 缓冲区的大小。
capacity – 缓冲区的容量。
- 返回:
一个
IBuffer
。
-
template<typename T>
static inline UniquePtr wrap( - T *data,
- std::size_t size,
- std::size_t capacity,
-
static MemoryType memoryType(void const *data)#
确定指针的内存类型。
-
virtual void *data() = 0#
-
template<MemoryType T>
struct MemoryTypeString#
-
template<>
struct MemoryTypeString<MemoryType::kCPU># 公共静态属性
-
static auto constexpr value = "CPU"#
-
static auto constexpr value = "CPU"#
-
template<>
struct MemoryTypeString<MemoryType::kGPU># 公共静态属性
-
static auto constexpr value = "GPU"#
-
static auto constexpr value = "GPU"#
-
template<>
struct MemoryTypeString<MemoryType::kPINNED># 公共静态属性
-
static auto constexpr value = "PINNED"#
-
static auto constexpr value = "PINNED"#
-
template<>
struct MemoryTypeString<MemoryType::kPINNEDPOOL># 公共静态属性
-
static auto constexpr value = "PINNEDPOOL"#
-
static auto constexpr value = "PINNEDPOOL"#
-
template<>
struct MemoryTypeString<MemoryType::kUVM># 公共静态属性
-
static constexpr value = "UVM"#
-
static constexpr value = "UVM"#
-
template<typename T, bool = false>
struct TRTDataType# - #include <iBuffer.h>
用于将 C++ 数据类型转换为 TensorRT 数据类型。
-
template<>
struct TRTDataType<bool>#
-
template<>
struct TRTDataType<float>#
-
template<>
struct TRTDataType<half>#
-
template<>
struct TRTDataType<kernels::FinishedState># 公共静态属性
-
static constexpr auto value = TRTDataType<kernels::FinishedState::UnderlyingType>::value#
-
static constexpr auto value = TRTDataType<kernels::FinishedState::UnderlyingType>::value#
-
template<>
struct TRTDataType<kernels::KVCacheIndex># 公共静态属性
-
static constexpr auto value = TRTDataType<kernels::KVCacheIndex::UnderlyingType>::value#
-
static constexpr auto value = TRTDataType<kernels::KVCacheIndex::UnderlyingType>::value#
-
template<>
struct TRTDataType<runtime::RequestType># 公共静态属性
-
static constexpr auto value = TRTDataType<std::underlying_type_t<runtime::RequestType>>::value#
-
static constexpr auto value = TRTDataType<std::underlying_type_t<runtime::RequestType>>::value#
-
template<>
struct TRTDataType<std::int32_t>#
-
template<>
struct TRTDataType<std::int64_t>#
-
template<>
struct TRTDataType<std::int8_t>#
-
template<>
struct TRTDataType<std::uint32_t># 公共静态属性
-
static constexpr auto value = BufferDataType{nvinfer1::DataType::kINT32, true}#
-
static constexpr auto value = BufferDataType{nvinfer1::DataType::kINT32, true}#
-
template<>
struct TRTDataType<std::uint64_t># 公共静态属性
-
static constexpr auto value = BufferDataType{nvinfer1::DataType::kINT64, true}#
-
static constexpr auto value = BufferDataType{nvinfer1::DataType::kINT64, true}#
-
template<>
struct TRTDataType<std::uint8_t>#
-
template<typename T>
struct TRTDataType<T*># 公共静态属性
-
static auto constexpr value = BufferDataType{kUnderlyingType.getDataType(), kUnderlyingType.isUnsigned(), true}#
私有静态属性
-
static auto constexpr kUnderlyingType = BufferDataType{TRTDataType<std::remove_const_t<T>, false>::value}#
-
static auto constexpr value = BufferDataType{kUnderlyingType.getDataType(), kUnderlyingType.isUnsigned(), true}#
-
template<>
struct TRTDataType<void*># 公共静态属性
-
static constexpr auto value = BufferDataType::kTrtPointerType#
-
static constexpr auto value = BufferDataType::kTrtPointerType#
-
template<typename T>
-
namespace runtime
ipcUtils.h#
-
namespace tensorrt_llm
-
namespace runtime
函数
- void lamportInitializeAll(
- void *buffer_0,
- void *buffer_1,
- void *buffer_2,
- size_t size,
-
bool canAccessPeer(WorldConfig const &worldConfig)#
-
class AllReduceBuffers#
-
公共函数
- AllReduceBuffers(
- SizeType32 maxBatchSize,
- SizeType32 maxBeamWidth,
- SizeType32 maxSequenceLength,
- SizeType32 hiddenSize,
- BufferManager const &manager,
- WorldConfig const &worldConfig,
- bool const fakeBuffers = false,
-
class IpcMemory#
-
公共函数
- IpcMemory(
- std::size_t bufferSize,
- BufferManager const &manager,
- WorldConfig const &worldConfig,
- bool openIpc = true,
-
~IpcMemory()#
-
inline std::vector<void*> const &getCommPtrs() const#
公共静态属性
-
static size_t constexpr FLAGS_SIZE = (tensorrt_llm::kernels::MAX_ALL_REDUCE_BLOCKS + 1) * sizeof(uint32_t)#
私有函数
- void allocateIpcMemory(
- std::size_t bufferSize,
- BufferManager const &manager,
- WorldConfig const &worldConfig,
-
void destroyIpcMemory()#
-
namespace runtime
lookaheadBuffers.h#
-
namespace tensorrt_llm
-
namespace runtime
-
class LookaheadDecodingBuffers#
-
公共函数
- LookaheadDecodingBuffers(
- SizeType32 maxNumSequences,
- SizeType32 maxTokensPerStep,
- BufferManager const &bufferManager,
-
class LookaheadRuntimeBuffers#
-
公共函数
- LookaheadRuntimeBuffers(
- SizeType32 maxBatchSize,
- SizeType32 maxBeamWidth,
- BufferManager const &manager,
- ModelConfig const &modelConfig,
- WorldConfig const &worldConfig,
- executor::DecodingConfig const &decodingConfig,
- TllmRuntime const &runtime,
- void setFromInputs(
- SizeType32 numCtxSequences,
- SizeType32 numGenSequences,
- ITensor const &requestTypes,
- ITensor const &seqSlots,
- LookaheadDecodingBuffers const &decoderLookaheadBuffers,
- TllmRuntime const &runtime,
- ModelConfig const &modelConfig,
- WorldConfig const &worldConfig,
- void reshape(
- SizeType32 numCtxSequences,
- SizeType32 numGenSequences,
- SizeType32 tokensPerStep,
- void insertInputTensors(
- TensorMap &inputBuffers,
- TensorMap &outputBuffers,
- WorldConfig const &worldConfig,
- void enableLookaheadDecoding(
- SizeType32 maxBatchSize,
- SizeType32 tokensPerStep,
-
void disableLookaheadDecoding()#
公共成员
-
class LookaheadDecodingBuffers#
-
namespace runtime
iTensor.h#
-
namespace nvinfer1#
-
namespace tensorrt_llm
-
namespace runtime
函数
- ITensor::SharedConstPtr const &tensorPtr,
检索指向 tensorPtr 所指向的张量底层数据的 T const 类型指针,如果 tensorPtr 为空则返回 nullptr。
必须声明此重载以避免涉及隐式转换为 IBuffer 时出现的歧义。
- 模板参数:
**T** – 底层数据的类型。
- 参数:
tensorPtr – 一个可能是 null 的共享指针。
- 返回:
指向 T const 的指针,可能为 nullptr。
-
)#
检索指向 tensorPtr 所指向的缓冲区底层数据的 T 类型指针,如果 tensorPtr 为空则返回 nullptr。
必须声明此重载以避免涉及隐式转换为 IBuffer 时出现的歧义。
- 模板参数:
**T** – 底层数据的类型。
- 参数:
tensorPtr – 一个可能是 null 的共享指针。
- 返回:
指向 T 的指针,可能为 nullptr。
-
)#
检索指向 optionalBufferPtr 中包含的张量指针所指向的张量底层数据的 T 类型指针,如果 optional 没有值则返回 nullptr。
必须声明此重载以避免涉及隐式转换为 IBuffer 时出现的歧义。
- 模板参数:
**T** – 底层数据的类型。
- 参数:
optionalBufferPtr – 可能为空的 optional 对象。
- 返回:
指向 T 的指针,可能为 nullptr。
- std::optional<ITensor::SharedConstPtr> const &optionalTensorPtr,
检索指向 optionalBufferPtr 中包含的张量指针所指向的张量底层数据的 T const 类型指针,如果 optional 没有值则返回 nullptr。
必须声明此重载以避免涉及隐式转换为 IBuffer 时出现的歧义。
- 模板参数:
**T** – 底层数据的类型。
- 参数:
optionalBufferPtr – 可能为空的 optional 对象。
- 返回:
指向常量 T 的指针,可能为 nullptr。
-
class ITensor : public virtual tensorrt_llm::runtime::IBuffer#
-
公共函数
-
~ITensor() override = default#
-
template<SizeType32 n>
inline DimType64 getDimension() const# 返回张量的第 n 个维度。如果 n 为负,则返回第 (nbDims - n) 个维度。TODO:迁移到 C++20 时替换为 constexpr 参数。
-
inline virtual void resize(std::size_t newSize) override#
调整缓冲区大小。如果新大小小于或等于当前容量,则此操作无效。
-
inline void squeeze(SizeType32 dim)#
从此张量中移除给定的 *unit* 维度。
-
inline void unsqueeze(SizeType32 dim)#
在指定位置添加一个 *unit* 维度。
- inline bool shapeEquals(
- std::initializer_list<SizeType32> const &other,
-
template<typename T>
inline bool shapeEquals( - T const *dims,
- SizeType32 count,
公共静态函数
-
static Shape squeeze(Shape const &shape, SizeType32 dim)#
从
shape
中移除给定的 *unit* 维度。- 参数:
shape – 要压缩(squeeze)的形状。
dim – 应移除(“squeezed”)的维度。
- 返回:
一个新的没有单位维度的形状。
-
static Shape unsqueeze(Shape const &shape, SizeType32 dim)#
在指定位置为
shape
添加一个 单位 维度。- 参数:
shape – 要取消压缩(unsqueeze)的形状。
dim – 应该添加单位维度的维度。
- 返回:
添加了单位维度的新形状。
- SharedPtr tensor,
- std::size_t offset,
- std::size_t size,
在底层
tensor
上创建一个切片视图。该视图将具有与tensor
相同的数据类型。- 参数:
tensor – 要查看的张量。
offset – 视图相对于张量维度 0 的偏移量。
size – 视图相对于张量维度 0 的大小。
- 返回:
buffer
的一个视图。
-
template<typename TConstPtr, std::enable_if_t<std::is_const_v<PointerElementType<TConstPtr>>, int> = 0>
static inline UniqueConstPtr slice( - TConstPtr &&tensor,
- std::size_t offset,
- std::size_t size,
-
template<typename TConstPtr, std::enable_if_t<std::is_const_v<PointerElementType<TConstPtr>>, int> = 0>
static inline UniqueConstPtr slice( - TConstPtr &&tensor,
- std::size_t offset,
-
)#
- 参数:
offsetDims – 多维度的偏移量。
tensor – 要查看的张量。
offsetDims – 视图的偏移维度。
size – 视图相对于 offsetDims 中最后一个维度的大小。
offsetDims – 指定所有维度。
- 抛出:
Whenever – 偏移量溢出或最后一个维度的偏移量+大小溢出时。
- 返回:
形状为 [size, 其余维度] 或 [size] 的视图,当
-
template<typename TConstPtr, std::enable_if_t<std::is_const_v<PointerElementType<TConstPtr>>, int> = 0>
static inline UniqueConstPtr slice(
)#
-
template<typename TConstPtr, std::enable_if_t<std::is_const_v<PointerElementType<TConstPtr>>, int> = 0>
static inline UniqueConstPtr slice(
)#
-
template<typename TConstPtr, std::enable_if_t<std::is_const_v<PointerElementType<TConstPtr>>, int> = 0>
static inline UniqueConstPtr slice(
)#
-
template<typename TConstPtr, std::enable_if_t<std::is_const_v<PointerElementType<TConstPtr>>, int> = 0>
static inline UniqueConstPtr slice(
)#
- 参数:
offsetDims – 指定所有维度。
- 返回:
仅该点的块,形状为 [其余维度] 或 [1],当
-
template<typename TConstPtr, std::enable_if_t<std::is_const_v<PointerElementType<TConstPtr>>, int> = 0>
static inline UniqueConstPtr at(
)#
-
template<typename TConstPtr, std::enable_if_t<std::is_const_v<PointerElementType<TConstPtr>>, int> = 0>
static inline ITensor::UniqueConstPtr at(
)#
返回给定形状的底层
buffer
(或张量)的视图。- 参数:
tensor – 要查看的张量。
shape – 视图的形状。
- 返回:
tensor
的一个视图。
-
template<typename TConstPtr, std::enable_if_t<std::is_const_v<PointerElementType<TConstPtr>>, int> = 0>
static inline UniqueConstPtr view(
)#
返回底层
tensor
的视图,该视图可以独立地重新整形。- 参数:
tensor – 要查看的张量。
- 返回:
tensor
的一个视图。
- SharedPtr tensor,
- std::int64_t sliceN = -1,
返回底层
tensor
的展平视图,该视图可以独立地重新整形。- 参数:
tensor – 要展平的张量。
sliceN – 展平后切取前 N 个元素。-1 表示取整个展平的张量。
- 返回:
tensor
的展平视图。
- static UniquePtr wrap( )#
将给定的
data
封装到ITensor
中。ITensor
不拥有底层data
,并且不能重新整形超出capacity
。- 参数:
data – 要封装的数据。
type –
data
的数据类型。shape – 张量的形状。
capacity – 缓冲区的容量。
- 返回:
一个
ITensor
。
-
template<typename T>
static inline bool shapeEquals( - Shape const &lhs,
- T const *dims,
- SizeType32 count,
一个方便函数,用于比较形状。
保护函数
-
ITensor() = default#
友元
- friend class ITensorBindings
-
~ITensor() override = default#
-
namespace runtime
loraCache.h#
-
namespace tensorrt_llm
-
namespace runtime
函数
-
std::string to_string(LoraCache::TaskLayerModuleConfig const &v)#
- std::ostream &operator<<(
- std::ostream &os,
- LoraCache::TaskLayerModuleConfig const &v,
-
class LoraCache#
- #include <loraCache.h>
使用 LRU 逐出策略缓存 LoRA 权重。
放入缓存的任务被标记为进行中,在标记为已完成之前无法被逐出。
一个缓存页存储一个最佳大小的 LoRA。一个页的大小为 [numSlots x pageWidth]。最佳大小的 LoRA 是指配置了 optimalAdapterSize 的 LoRA。
概念上,一个槽对应于一个 r=1、1 层、1 模块的输入/输出权重集。页宽度设置为最小模块中的权重数量。
每页的槽数量等于 ceilDiv(最佳大小 LoRA 中的权重数量, 最小模块中的权重数量)
缓存页在一个或多个块上分配
公共类型
-
using TaskIdType = std::uint64_t#
-
using TaskLayerModuleConfigListPtr = std::shared_ptr<std::vector<TaskLayerModuleConfig>>#
公共函数
- LoraCache(
- LoraCachePageManagerConfig const &pageManagerConfig,
- ModelConfig const &modelConfig,
- WorldConfig const &worldConfig,
- BufferManager const &bufferManager,
param[in] pageManagerConfig: 一个 LoraCachePageManagerConfig param[in] modelConfig: 一个 ModelConfig param[in] worldConfig: 一个 WorldConfig param[in] bufferManager: 一个 BufferManager 仅用于分配页块
- void put(
- TaskIdType taskId,
- TensorPtr weights,
- TensorPtr config,
- bool load = true,
将任务放入缓存,为其申请页,并可选地加载任务权重。
- 参数:
taskId – [in] 任务 ID
weights – [in] LoRA 权重张量
config – [in] LoRA 配置张量
load – [in] 如果为 true,则在返回前加载权重,否则不加载
- void loadWeights(
- TaskIdType taskId,
- TensorPtr weights,
- TensorPtr config,
加载任务权重。此方法必须在 put 后调用。它被设计为在 put 返回 load = false 后异步调用
- 参数:
taslId – [in] 任务 ID
weights – [in] LoRA 权重张量
config – [in] LoRA 配置张量
-
inline bool isLoaded(TaskIdType taskId) const#
- 参数:
taskId – [in] 任务 ID
- 返回:
— 如果任务已加载(权重已就位)则为 true,否则为 false
-
bool isDone(TaskIdType taskId) const#
- 参数:
taskId – [in] 任务 ID
- 返回:
— 如果任务已标记为完成且可以被逐出则为 true
-
inline bool has(TaskIdType taskId) const#
- 参数:
taskId – [in] 任务 ID
- 返回:
— 如果任务在缓存中(不一定已加载)则为 true,否则为 false
-
std::vector<TaskLayerModuleConfig> const &get(TaskIdType taskId)#
- 参数:
taskId – [in] 任务 ID
- 返回:
— Value 对象列表,包含指向任务权重的指针
-
void bump(TaskIdType taskId)#
标记任务为最近使用
- 参数:
taskId – [in] 任务 ID
-
void markTaskDone(TaskIdType taskId)#
将任务标记为完成,表示它可以被逐出
- 参数:
taskId – [in] 任务 ID
-
void markAllDone()#
将缓存中的所有任务标记为完成
-
SizeType32 determineNumPages(TaskIdType taskId) const#
- 参数:
taskId – [in] 任务 ID
- 返回:
— 存储给定任务所需的页数
-
SizeType32 determineNumPages(TensorPtr config) const#
- 参数:
config – [in] LoRA 配置张量
- 返回:
— 存储由 config 张量配置的任务所需的页数
-
bool fits(TensorPtr config) const#
- 参数:
config – [in] 一个 LoRA 配置张量
- 返回:
— 如果任务适合缓存,则为 true,否则为 false
- void copyTask(
- TaskIdType taskId,
- LoraCache &deviceCache,
- bool markDone = false,
将任务复制到另一个缓存。缓存必须具有相同的页大小。
- 参数:
taskId – [in] 要复制的任务 ID
otherCache – [in] 要将任务移动到的 LoraCache
markDone – [in] 在复制时将已复制的任务标记为完成
-
SizeType32 getNumPages() const#
- 返回:
— 分配给缓存的总页数(无论是否使用)
-
ITensor::SharedConstPtr getPagePtr(size_t pageId) const#
- 参数:
pageId – [in] 页 ID
- 返回:
— 指向页的 const 指针
公共静态函数
- static std::vector<LoraCache::TaskLayerModuleConfig> copyToPages(
- TensorPtr weights,
- TensorPtr config,
- ModelConfig const &modelConfig,
- WorldConfig const &worldConfig,
- std::unordered_map<SizeType32, LoraModule> moduleIdToModel,
- BufferManager const &manager,
- std::vector<TensorPtr> const &pages,
- std::vector<std::size_t> const &pageIds,
将任务权重复制到缓存页。
- 参数:
weights – [in] 任务权重
config – [in] 任务配置张量
modelConfig – [in] 一个 ModelConfig
worldConfig – [in] 一个 WorldConfig
modelIdToModel – [in] 从 LoRA 模块 ID 到 LoraModule 的映射
manager – [in] 一个 BufferManager 用于执行复制操作的管理器
pages – [out] 要将权重复制到的页张量列表
pageIds – [in] 页的 ID 列表
- 返回:
— 缓存 Value 对象列表
- static void splitTransposeCpu(
- ITensor &output,
- ITensor const &input,
- SizeType32 tpSize,
- SizeType32 tpRank,
将输入的第二个维度分割成 tpSize 部分,并将 tpRank 部分写入到 output
- 参数:
output – [out] 输出张量
input – [in] 输入张量
tpSize – [in] 分割数量
tpRank – [in] 要写入到 output 的分割部分
私有类型
私有函数
-
void bumpTaskInProgress(TaskIdType taskId)#
-
ValueStatus getStatus(TaskIdType taskId) const#
-
std::vector<std::size_t> claimPagesWithEvict(SizeType32 numPages)#
声明 numPages 页面,如果需要则驱逐任务
- 参数:
numPages – [in] 要声明的页面数量
- 抛出:
std::runtime_error – 如果无法声明所有页面
- 返回:
– 页面 ID 列表
- std::map<size_t, std::pair<size_t, SizeType32>> copyTaskMapPages(
- TaskValue &targetTaskValue,
- TaskValue const &sourceTaskValue,
- std::vector<size_t> const &targetPageIds,
- LoraCache const &targetCache,
内部辅助方法,用于 copyTask 内部。本身不是线程安全的。
私有成员
-
LoraCachePageManagerConfig mPageManagerConfig#
-
ModelConfig mModelConfig#
-
WorldConfig mWorldConfig#
-
mutable std::mutex mPagesMutex#
-
std::unique_ptr<LoraCachePageManager> mCachePageManager#
-
mutable std::mutex mCacheMutex#
-
std::unordered_map<TaskIdType, TaskValuePtr> mCacheMap#
-
std::list<TaskIdType> mInProgressTasks#
-
std::list<TaskIdType> mDoneTasks#
-
std::vector<std::unique_ptr<BufferManager>> mDeviceBufferManagers#
-
std::unique_ptr<BufferManager> mBufferManager#
-
std::unordered_map<SizeType32, LoraModule> mModuleIdToModule#
私有静态函数
-
template<typename T>
static void splitTransposeCpuInner( - ITensor &output,
- ITensor const &input,
- SizeType32 tpSize,
- SizeType32 tpRank,
-
struct TaskLayerModuleConfig#
- #include <loraCache.h>
包含单个层/模块的信息。这些配置的列表与每个任务相关联,可用于填充运行时张量。
公共函数
-
std::string toString() const#
-
bool operator==(LoraCache::TaskLayerModuleConfig const &o) const#
公共成员
-
std::size_t pageId#
-
SizeType32 slotIdx#
-
SizeType32 inSize#
-
SizeType32 outSize#
-
SizeType32 moduleId#
-
SizeType32 layerId#
-
SizeType32 adapterSize#
-
SizeType32 numSlots#
-
std::int64_t weightsInPointer#
-
std::int64_t weightsOutPointer#
-
std::optional<std::int64_t> scalingVecPointer#
友元
- friend class TaskLayerModuleConfigBindings
-
std::string toString() const#
-
struct TaskValue#
保存单个任务的配置和状态。
公共函数
-
TaskValue() = delete#
-
~TaskValue() = default#
- inline TaskValue(
- std::vector<std::size_t> const &pageIds,
- TaskLayerModuleConfigListPtr const &configs,
- std::list<TaskIdType>::iterator it,
- bool inProgress,
- bool loaded,
- bool done,
- bool loadInProgress = false,
公共成员
-
std::vector<std::size_t> pageIds#
-
TaskLayerModuleConfigListPtr configs#
-
std::list<TaskIdType>::iterator it#
-
bool inProgress#
-
bool loaded#
-
bool done#
将任务标记为已完成。这用于在加载期间将任务标记为已完成。如果在加载结束时(put、loadweights 或 copyTask 结束时)done=true,则该任务将被标记为已完成。
-
bool loadInProgress#
表示权重正在通过 put 或 loadWeights 加载。这用于阻止同一任务的并发 loadWeights 调用。
-
TaskValue() = delete#
-
using TaskIdType = std::uint64_t#
-
class LoraCacheFullException : public tensorrt_llm::runtime::LoraExpectedException#
-
class LoraCachePageManager#
- #include <loraCache.h>
持有 LoRA 缓存页的内存,并管理整页的分配和释放。内存预先分配在主机或设备上。
注意,此类非线程安全。
公共函数
- LoraCachePageManager(
- 使用给定的配置和 BufferManager 创建一个 LoraCachePageManager。,
- BufferManager const &bufferManager,
- 参数:
config – [in] 一个 LoraCachePageManagerConfig
bufferManager – [in] 用于分配页块的 BufferManager
- std::optional<std::vector<std::size_t>> claimPages(
- SizeType32 numPages,
请求页
- 参数:
numPages – [in] 要声明的页面数量
- 返回:
一个元组,第一个值是布尔值,指示是否请求到页。如果第一个值为 true,则第二个值将包含页 ID 列表。
-
SizeType32 numAvailablePages() const#
获取管理器中可用(空闲)页的数量
- 返回:
管理器中的空闲页数量
-
void releasePages(std::vector<std::size_t> const &pages)#
释放给定的页
- 参数:
pages – [in] 要释放(空闲)的页列表
-
ITensor::SharedConstPtr blockPtr(SizeType32 blockIdx) const#
返回给定页块的指针
- 参数:
blockIdx; – [in]
- 返回:
— 指向页块的指针
-
ITensor::SharedConstPtr pagePtr(std::size_t pageIdx) const#
返回给定页的指针
- 参数:
pageIdx – [in]
- 返回:
— 指向页的 const 指针
私有函数
-
void initialize(BufferManager const &bufferManager)#
-
class LoraExpectedException : public std::runtime_error#
-
std::string to_string(LoraCache::TaskLayerModuleConfig const &v)#
-
namespace runtime
loraModule.h#
-
namespace tensorrt_llm
-
namespace runtime
函数
- inline std::ostream &operator<<(
- std::ostream &output,
- module – [in],
-
LoraModule const &module
公共类型
-
enum class ModuleType : SizeType32#
值
-
enumerator kINVALID#
-
enumerator kATTN_QKV#
-
enumerator kATTN_Q#
-
enumerator kATTN_K#
-
enumerator kATTN_V#
-
enumerator kATTN_DENSE#
-
enumerator kMLP_H_TO_4H#
-
enumerator kMLP_4H_TO_H#
-
enumerator kMLP_GATE#
-
enumerator kCROSS_ATTN_QKV#
-
enumerator kCROSS_ATTN_Q#
-
enumerator kCROSS_ATTN_K#
-
enumerator kCROSS_ATTN_V#
-
enumerator kCROSS_ATTN_DENSE#
-
enumerator kMOE_H_TO_4H#
-
enumerator kMOE_4H_TO_H#
-
enumerator kMOE_GATE#
-
enumerator kMOE_ROUTER#
-
enumerator kMLP_ROUTER#
-
enumerator kMLP_GATE_UP#
-
enumerator kINVALID#
公共函数
- inline explicit constexpr LoraModule(
- t – [in] 模块类型,
- inDim – [in] 输入维度,
- SizeType32 outDim,
- bool inDimFirst,
- bool outDimFirst,
- SizeType32 inTpSplitDim,
- SizeType32 outTpSplitDim,
-
inline explicit constexpr LoraModule() noexcept#
-
explicit constexpr LoraModule(LoraModule const &o) = default#
-
constexpr LoraModule &operator=(LoraModule const &o) = default#
- inline SizeType32 constexpr flattenedInOutSize(
- SizeType32 adapterSize,
- bool isDora,
- inline SizeType32 constexpr inSize(
- SizeType32 adapterSize,
- inline SizeType32 constexpr outSize(
- SizeType32 adapterSize,
- inline SizeType32 constexpr localInSize(
- SizeType32 adapterSize,
- SizeType32 tpSize,
- inline SizeType32 constexpr localOutSize(
- SizeType32 adapterSize,
- SizeType32 tpSize,
- inline SizeType32 constexpr localScalesSize(
- SizeType32 tpSize,
- bool isDora,
- inline SizeType32 constexpr localInDim(
- SizeType32 tpSize,
- inline SizeType32 constexpr localOutDim(
- SizeType32 tpSize,
- inline SizeType32 constexpr localInAdapterSize(
- SizeType32 adapterSize,
- SizeType32 tpSize,
- inline SizeType32 constexpr localOutAdapterSize(
- SizeType32 adapterSize,
- SizeType32 tpSize,
- inline SizeType32 constexpr localInOutSize(
- SizeType32 adapterSize,
- SizeType32 tpSize,
- inline SizeType32 constexpr localTotalSize(
- SizeType32 adapterSize,
- SizeType32 tpSize,
- bool isDora,
-
inline SizeType32 constexpr value() const noexcept#
-
inline std::string_view constexpr name() const noexcept#
-
inline SizeType32 constexpr inDim() const noexcept#
-
inline SizeType32 constexpr outDim() const noexcept#
-
inline bool constexpr inDimFirst() const noexcept#
-
inline bool constexpr outDimFirst() const noexcept#
-
inline SizeType32 constexpr inTpSplitDim() const noexcept#
-
inline SizeType32 constexpr outTpSplitDim() const noexcept#
公共静态函数
- static std::vector<LoraModule> createLoraModules(
- std::vector<std::string> const &loraModuleNames,
- SizeType32 hiddenSize,
- SizeType32 mlpHiddenSize,
- SizeType32 numAttentionHeads,
- SizeType32 numKvAttentionHeads,
- SizeType32 attentionHeadSize,
- SizeType32 tpSize,
- SizeType32 numExperts,
- static inline ModuleType constexpr toModuleType(
- std::string_view const &name,
- static inline std::string_view constexpr toModuleName(
- ModuleType t,
-
static inline std::string_view constexpr toModuleName(SizeType32 id)#
私有成员
-
ModuleType mType#
-
SizeType32 mInDim#
-
SizeType32 mOutDim#
-
bool mInDimFirst#
-
bool mOutDimFirst#
-
SizeType32 mInTpSplitDim#
-
SizeType32 mOutTpSplitDim#
-
enum class ModuleType : SizeType32#
-
namespace runtime
modelConfig.h#
-
namespace tensorrt_llm
-
namespace runtime
-
class ModelConfig#
公共类型
公共函数
- inline explicit ModelConfig(
- SizeType32 词汇量大小,
- SizeType32 层数,
- SizeType32 注意力层数,
- SizeType32 循环层数,
- SizeType32 注意力头数,
- SizeType32 hiddenSize,
- nvinfer1::DataType dtype,
-
inline SizeType32 constexpr 获取词汇量大小() const noexcept#
- inline SizeType32 constexpr 获取填充后的词汇量大小(
- SizeType32 世界大小,
- inline SizeType32 计算本地层数(
- LayerType 层类型,
- SizeType32 流水线并行度 = 1,
- SizeType32 流水线并行度级别 = 0,
- inline SizeType32 计算较低级别层数(
- LayerType 层类型,
- SizeType32 流水线并行度 = 1,
- SizeType32 流水线并行度级别 = 0,
-
inline SizeType32 获取层数(SizeType32 流水线并行度 = 1) const#
- inline SizeType32 获取注意力层数(
- SizeType32 流水线并行度 = 1,
- SizeType32 流水线并行度级别 = 0,
- inline SizeType32 获取循环层数(
- SizeType32 流水线并行度 = 1,
- SizeType32 流水线并行度级别 = 0,
-
inline SizeType32 constexpr 获取注意力头数() const noexcept#
-
inline SizeType32 获取KV头数(SizeType32 层索引) const#
-
inline void 设置KV头数(SizeType32 KV头数)#
-
inline void 设置交叉KV头数(SizeType32 KV头数)#
-
inline SizeType32 constexpr 获取隐藏层大小() const noexcept#
-
inline SizeType32 constexpr 获取编码器隐藏层大小() const noexcept#
- inline void constexpr 设置编码器隐藏层大小(
- SizeType32 编码器隐藏层大小,
-
inline SizeType32 constexpr 获取每个头的大小() const noexcept#
-
inline void constexpr 设置每个头的大小(SizeType32 每个头的大小) noexcept#
-
inline bool constexpr 使用Gpt注意力插件() const noexcept#
-
inline bool constexpr 使用GemmAllReduce插件() const noexcept#
- inline void constexpr 使用Gpt注意力插件(
- bool 使用Gpt注意力插件,
- inline void constexpr 使用GemmAllReduce插件(
- bool 使用GemmAllReduce插件,
-
inline bool constexpr 使用MambaConv1d插件() const noexcept#
- inline void constexpr 使用MambaConv1d插件(
- bool 使用MambaConv1d插件,
-
inline bool constexpr 使用打包输入() const noexcept#
-
inline void constexpr 使用打包输入(bool 输入是否打包) noexcept#
-
inline bool constexpr 使用分页状态() const noexcept#
-
inline void constexpr 使用分页状态(bool 分页状态) noexcept#
-
inline SizeType32 constexpr getTokensPerBlock() const noexcept#
- inline void constexpr setTokensPerBlock(
- SizeType32 TokensPerBlock,
-
inline common::QuantMode constexpr getQuantMode() const noexcept#
- inline void constexpr setQuantMode(
- common::QuantMode QuantMode,
-
inline bool constexpr supportsInflightBatching() const noexcept#
-
inline SizeType32 constexpr getMaxBatchSize() const noexcept#
- inline void constexpr setMaxBatchSize(
- SizeType32 maxBatchSize,
-
inline SizeType32 constexpr getMaxBeamWidth() const noexcept#
- inline void constexpr setMaxBeamWidth(
- SizeType32 maxBeamWidth,
-
inline SizeType32 constexpr getMaxInputLen() const noexcept#
-
inline void constexpr setMaxInputLen(SizeType32 maxInputLen) noexcept#
-
inline SizeType32 constexpr getMaxSequenceLen() const noexcept#
- inline void constexpr setMaxSequenceLen(
- SizeType32 maxSequenceLen,
- inline std::optional<SizeType32> constexpr getMaxNumTokens(
- inline void constexpr setMaxNumTokens(
- std::optional<SizeType32> maxNumTokens,
-
inline SizeType32 constexpr getMaxEncoderLen() const noexcept#
- inline void constexpr setMaxEncoderLen(
- SizeType32 maxEncoderLen,
-
inline bool constexpr usePromptTuning() const noexcept#
-
inline bool constexpr useMrope() const noexcept#
-
inline void constexpr setUseMrope(bool useMrope) noexcept#
-
inline SizeType32 constexpr getMaxPositionEmbeddings() const noexcept#
- inline void constexpr setMaxPositionEmbeddings(
- SizeType32 maxPositionEmbeddings,
-
inline SizeType32 constexpr getRotaryEmbeddingDim() const noexcept#
- inline void constexpr setRotaryEmbeddingDim(
- SizeType32 rotaryEmbeddingDim,
- inline SizeType32 constexpr getMaxPromptEmbeddingTableSize(
- inline void constexpr setMaxPromptEmbeddingTableSize(
- SizeType32 maxPromptEmbeddingTableSize,
-
inline bool constexpr computeContextLogits() const noexcept#
- inline void constexpr computeContextLogits(
- bool computeContextLogits,
-
inline bool constexpr computeGenerationLogits() const noexcept#
- inline void constexpr computeGenerationLogits(
- bool computeGenerationLogits,
-
inline ModelVariant getModelVariant() const#
-
inline void setModelVariant(ModelVariant modelVariant)#
-
inline SizeType32 getMaxDecodingDraftTokens() const#
-
inline SizeType32 constexpr getMaxDecodingTokens() const noexcept#
-
inline void constexpr setContextFMHA(bool contextFMHA) noexcept#
-
inline bool constexpr getContextFMHA() const noexcept#
- inline void constexpr setPagedContextFMHA(
- bool pagedContextFMHA,
-
inline bool constexpr getPagedContextFMHA() const noexcept#
- inline void constexpr setPpReduceScatter(
- bool ppReduceScatter,
-
inline bool constexpr getPpReduceScatter() const noexcept#
-
inline bool constexpr useLoraPlugin() const noexcept#
-
inline void constexpr useLoraPlugin(bool useLoraPlugin) noexcept#
- inline std::vector<LoraModule> const &获取LoraModules(
- inline void 设置LoraModules(
- std::vector<LoraModule> const &loraModules,
-
inline SizeType32 constexpr 获取MLP隐藏层大小() const noexcept#
- inline void constexpr 设置MLP隐藏层大小(
- SizeType32 mlpHiddenSize,
-
inline bool constexpr 是否启用KV缓存() const noexcept#
-
inline bool constexpr 是否分页KV缓存() const noexcept#
-
inline bool constexpr 是否连续KV缓存() const noexcept#
-
inline KVCacheType constexpr 获取KV缓存类型() const noexcept#
- inline void constexpr 设置KV缓存类型(
- KVCacheType kvCacheType,
-
inline bool constexpr 使用交叉注意力() const noexcept#
- inline void constexpr 设置是否使用交叉注意力(
- bool useCrossAttention,
-
inline bool constexpr 使用位置嵌入() const noexcept#
- inline void constexpr 设置是否使用位置嵌入(
- bool usePositionEmbedding,
-
inline bool constexpr 使用TokenType嵌入() const noexcept#
- inline void constexpr 设置是否使用TokenType嵌入(
- bool useTokenTypeEmbedding,
-
inline SizeType32 constexpr 获取最大Lora Rank() const noexcept#
-
inline void constexpr 设置最大Lora Rank(SizeType32 maxLoraRank) noexcept#
- inline void 设置推测解码模式(
- SpeculativeDecodingMode mode,
-
inline bool 是否具有推测解码模块() const noexcept#
- inline SpeculativeDecodingModule const &获取推测解码模块(
- inline std::shared_ptr<SpeculativeDecodingModule const> 获取推测解码模块指针(
- inline std::shared_ptr<SpeculativeDecodingModule> 获取推测解码模块指针(
- std::shared_ptr<SpeculativeDecodingModule> const &speculativeDecodingModule,
-
inline void 重置推测解码模块() noexcept#
- inline void 启用无缝先行解码(
- SizeType32 maxDraftTokens,
-
inline void 禁用无缝先行解码() noexcept#
-
inline bool constexpr 是否基于Transformer() const noexcept#
-
inline bool 是否具有RNN配置() const noexcept#
-
inline bool constexpr 是否基于RNN() const noexcept#
- inline SpeculativeDecodingMode constexpr 获取推测解码模式(
-
inline void setUseShapeInference(bool useShapeInference) noexcept#
-
inline bool useShapeInference() const noexcept#
-
inline ManageWeightsType getManageWeightsType() const noexcept#
- inline void setManageWeightsType(
- ManageWeightsType const manageWeightType,
-
inline std::string const &getModelName() const noexcept#
-
inline void setModelName(std::string const &modelName)#
- inline std::vector<SizeType32> const &getNumKvHeadsPerLayer(
- inline std::pair<std::vector<SizeType32>::const_iterator, std::vector<SizeType32>::const_iterator> getNumKvHeadsPerLayerLocalRange(
- SizeType32 流水线并行度 = 1,
- SizeType32 流水线并行度级别 = 0,
- bool isCrossAttention = false,
- inline void setNumKvHeadsPerLayer(
- std::vector<SizeType32> const &headsPerLayer,
- inline void setNumKvHeadsPerCrossLayer(
- std::vector<SizeType32> const &headsPerLayer,
- inline SizeType32 getSumLocalKvHeads(
- SizeType32 流水线并行度 = 1,
- SizeType32 流水线并行度级别 = 0,
- bool isCrossAttention = false,
-
inline bool constexpr skipCrossAttnBlocks() const noexcept#
- inline void constexpr setSkipCrossAttnBlocks(
- bool skipCrossAttnBlocks,
- inline std::optional<SizeType32> constexpr getNumLanguages(
-
inline bool constexpr useLanguageAdapter() const noexcept#
- inline void constexpr setNumLanguages(
- std::optional<SizeType32> numLanguages,
-
inline bool isMultiModal() const#
-
inline bool isWhisper() const#
公共静态函数
-
static inline KVCacheType KVCacheTypeFromString(std::string value)#
- static inline std::vector<SizeType32> getOptProfilesSplitPoints(
公共静态属性
-
static constexpr std::array kOPT_PROFILES_SPLIT_POINTS = {64, 128, 256, 512, 1024}#
-
static constexpr SizeType32 kDEFAULT_NUM_TOKENS_PER_BLOCK = 64#
私有成员
-
SizeType32 mVocabSize#
-
SizeType32 mNbLayers#
-
SizeType32 mNbAttentionLayers#
-
SizeType32 mNbRnnLayers#
-
SizeType32 mNbHeads#
-
SizeType32 mHiddenSize#
-
SizeType32 mSizePerHead#
-
bool mUseGptAttentionPlugin#
-
bool mUseGemmAllReducePlugin#
-
bool mUseMambaConv1dPlugin#
-
bool mInputPacked#
-
bool mPagedState#
-
SizeType32 mTokensPerBlock#
-
common::QuantMode mQuantMode#
-
SizeType32 mMaxBatchSize#
-
SizeType32 mMaxBeamWidth#
-
SizeType32 mMaxInputLen#
-
SizeType32 mMaxSequenceLen#
-
最大token数量
-
计算上下文logits
-
计算生成logits
-
模型变体
-
最大prompt嵌入表大小
-
使用Mrope
-
最大位置嵌入
-
旋转嵌入维度
-
上下文FMHA
-
分页上下文FMHA
-
PP Reduce Scatter
-
使用Lora插件
-
Lora模块
-
MLP隐藏层大小
-
最大Lora秩
-
RNN配置
-
KV缓存类型
-
最大编码器长度
-
编码器隐藏层大小
-
使用交叉注意力
-
使用位置嵌入
-
使用token类型嵌入
-
层类型
-
推测解码模块
-
推测解码模式
-
Logits数据类型
-
使用形状推断
-
管理权重类型
-
模型名称
-
每注意力层的KV头数量
-
每交叉注意力层的KV头数量
-
跳过交叉注意力块
-
语言数量
-
结构体 RnnConfig
公共成员
-
状态大小
-
卷积核
-
RNN隐藏层大小
-
RNN头大小
-
RNN卷积维度大小
-
状态大小
-
class ModelConfig#
-
namespace runtime
lookaheadModule.h#
request.h#
-
namespace tensorrt_llm
-
namespace runtime
-
命名空间 decoder_batch
-
类 Request
公共类型
-
Tensor常量指针
-
Tensor指针
-
Buffer指针
公共函数
- Request 构造函数
- ID,
- 输入长度,
- 最大新token数量,
- std::optional<SizeType32> endId = std::nullopt,
公共成员
-
TensorConstPtr ids#
强制参数。
-
SizeType32 inputLen#
-
std::optional<SizeType32> maxNewTokens#
-
std::optional<SizeType32> endId#
-
SizeType32 generatedTokensPerEngineStep#
-
std::optional<executor::LookaheadDecodingConfig> lookaheadRuntimeConfig#
-
std::optional<executor::EagleConfig> eagleConfig#
-
Tensor常量指针
-
类 Request
-
命名空间 decoder_batch
-
namespace runtime
loraCachePageManagerConfig.h#
-
namespace tensorrt_llm
-
namespace runtime
函数
- inline std::ostream &operator<<(
- std::ostream &os,
- LoraCachePageManagerConfig const &c,
-
inline std::string to_string(LoraCachePageManagerConfig const &c)#
-
class LoraCachePageManagerConfig#
- #include <loraCachePageManagerConfig.h>
LoraCachePageManager 的配置
有关页面、插槽和页块的描述,请参阅 LoraCache 文档。
公共函数
- inline explicit constexpr LoraCachePageManagerConfig(
- runtime::MemoryType memType,
- nvinfer1::DataType dType,
- SizeType32 totalNumPages,
- SizeType32 maxPagesPerBlock,
- SizeType32 slotsPerPage,
- SizeType32 pageWidth,
- SizeType32 numCopyStreams,
-
inline runtime::MemoryType constexpr getMemoryType() const noexcept#
- inline void constexpr setMemoryType(
- runtime::MemoryType const &memoryType,
-
inline SizeType32 constexpr getTotalNumPages() const noexcept#
- inline void constexpr setTotalNumPage(
- SizeType32 const &totalNumPages,
-
inline SizeType32 constexpr getMaxPagesPerBlock() const noexcept#
- inline void constexpr setMaxPagesPerBlock(
- SizeType32 const &maxPagesPerBlock,
-
inline SizeType32 constexpr getSlotsPerPage() const noexcept#
- inline void constexpr setSlotsPerPage(
- SizeType32 const &slotsPerPage,
-
inline SizeType32 constexpr getPageWidth() const noexcept#
- inline void constexpr setPageWidth(
- SizeType32 const &pageWidth,
-
inline bool constexpr getInitToZero() const noexcept#
-
inline void constexpr setInitToZero(bool initToZero) noexcept#
-
inline SizeType32 constexpr getNumCopyStreams() const noexcept#
- inline void constexpr setNumCopyStreams(
- SizeType32 numCopyStreams,
私有成员
-
runtime::MemoryType mMemoryType#
-
SizeType32 总页数#
-
SizeType32 每块最大页数#
-
SizeType32 每页槽位#
-
SizeType32 页宽度#
-
SizeType32 复制流数量 = 1#
-
bool 初始化为零#
-
namespace runtime
samplingConfig.h#
宏定义
-
SET_FROM_OPTIONAL(varName, VarName, VarType)#
-
namespace tensorrt_llm
-
namespace runtime
-
class 采样配置#
公共函数
-
inline explicit 采样配置(SizeType32 束宽度 = 1)#
- inline explicit 采样配置(
- executor::SamplingConfig const &samplingConfig,
- std::optional<executor::ExternalDraftTokensConfig> const &externalDraftTokensConfig = std::nullopt,
-
inline bool 验证()#
-
inline SizeType32 获取返回 Beam 数量() const#
- inline SizeType32 按迭代次数获取 Beam 宽度(
- int const decodingIter,
- int const indexSC = 0,
-
inline SizeType32 获取最大 Beam 宽度() const noexcept#
公共成员
-
SizeType32 束宽度#
-
std::optional<SizeType32> 返回序列数量#
-
OptVec<SizeType32> 最小生成长度#
-
OptVec<SizeType32> 禁止重复 N-gram 大小#
-
OptVec<SizeType32> Top K 采样#
-
OptVec<TokenIdType> Top P 重置 ID#
-
OptVec<SizeType32> 提前停止#
-
OptVec<std::vector<SizeType32>> 束宽度数组#
-
OptVec<std::vector<SizeType32>> Medusa 头部的 Top K#
-
std::optional<bool> 标准化对数概率#
私有函数
-
inline explicit 采样配置(SizeType32 束宽度 = 1)#
-
class 采样配置#
-
namespace runtime
medusaModule.h#
-
namespace tensorrt_llm
-
namespace runtime
-
class MedusaModule : public tensorrt_llm::runtime::SpeculativeDecodingModule#
公共类型
-
using MedusaChoices = std::vector<std::vector<SizeType32>>#
公共函数
- inline explicit MedusaModule(
- SizeType32 maxAcceptedTokens,
- SizeType32 maxDraftTokens,
-
inline explicit MedusaModule() noexcept#
-
inline MedusaChoices const &getMedusaChoices() const noexcept#
私有成员
-
MedusaChoices mDefaultMedusaChoices = {{0}, {0, 0}, {1}, {0, 1}, {2}, {0, 0, 0}, {1, 0}, {0, 2}, {3}, {0, 3}, {4}, {0, 4} , {2, 0} , {0, 5} , {0, 0, 1} , {5} , {0, 6} , {6} , {0, 7} , {0, 1, 0} , {1, 1} , {7} , {0, 8} , {0, 0, 2} , {3, 0} , {0, 9} , {8} , {9} , {1, 0, 0} , {0, 2, 0} , {1, 2} , {0, 0, 3} , {4, 0} , {2, 1} , {0, 0, 4} , {0, 0, 5} , {0, 0, 0, 0} , {0, 1, 1} , {0, 0, 6} , {0, 3, 0} , {5, 0} , {1, 3} , {0, 0, 7} , {0, 0, 8} , {0, 0, 9} , {6, 0} , {0, 4, 0} , {1, 4} , {7, 0} , {0, 1, 2} , {2, 0, 0} , {3, 1} , {2, 2} , {8, 0} , {0, 5, 0} , {1, 5} , {1, 0, 1} , {0, 2, 1} , {9, 0} , {0, 6, 0} , {0, 0, 0, 1} , {1, 6} , {0, 7, 0}}#
-
using MedusaChoices = std::vector<std::vector<SizeType32>>#
-
class MedusaModule : public tensorrt_llm::runtime::SpeculativeDecodingModule#
-
namespace runtime
memoryCounters.h#
-
namespace tensorrt_llm
-
namespace runtime
-
class MemoryCounters#
-
公共函数
-
MemoryCounters() = default#
-
inline SizeType32 getGpu() const#
-
inline SizeType32 getCpu() const#
-
inline SizeType32 getPinned() const#
-
inline SizeType32 getUVM() const#
-
inline SizeType32 getPinnedPool() const#
-
template<MemoryType T>
inline void allocate(SizeType32 size)#
-
void allocate(MemoryType memoryType, SizeType32 size)#
-
template<MemoryType T>
inline void deallocate(SizeType32 size)#
-
void deallocate(MemoryType memoryType, SizeType32 size)#
-
std::string toString() const#
公共静态函数
-
static MemoryCounters &getInstance()#
-
static std::string bytesToString(SizeType32 bytes, int precision = 2)#
私有成员
-
std::atomic<SizeType32> mGpu = {}#
-
std::atomic<SizeType32> mCpu = {}#
-
std::atomic<SizeType32> mPinned = {}#
-
std::atomic<SizeType32> mUVM = {}#
-
std::atomic<SizeType32> mPinnedPool = {}#
-
MemoryCounters() = default#
-
class MemoryCounters#
-
namespace runtime
worldConfig.h#
-
namespace tensorrt_llm
-
namespace runtime
-
class WorldConfig#
公共函数
- explicit WorldConfig(
- SizeType32 tensorParallelism = 1,
- SizeType32 流水线并行度 = 1,
- SizeType32 contextParallelism = 1,
- SizeType32 rank = 0,
- SizeType32 gpusPerNode = kDefaultGpusPerNode,
- std::optional<std::vector<SizeType32>> const &deviceIds = std::nullopt,
- bool enableAttentionDP = false,
-
inline SizeType32 constexpr getSize() const noexcept#
-
inline SizeType32 constexpr getTensorParallelism() const noexcept#
-
inline bool constexpr isTensorParallel() const noexcept#
-
inline SizeType32 constexpr getPipelineParallelism() const noexcept#
-
inline bool constexpr isPipelineParallel() const noexcept#
-
inline SizeType32 constexpr getContextParallelism() const noexcept#
-
inline bool constexpr isContextParallel() const noexcept#
-
inline SizeType32 constexpr getRank() const noexcept#
-
inline SizeType32 constexpr getGpusPerNode() const noexcept#
-
inline SizeType32 getGpusPerGroup() const noexcept#
-
inline SizeType32 getDevice() const noexcept#
-
inline SizeType32 getDeviceOf(SizeType32 rank) const noexcept#
-
inline SizeType32 constexpr getPipelineParallelRank() const noexcept#
-
inline SizeType32 constexpr getTensorParallelRank() const noexcept#
-
inline SizeType32 constexpr getContextParallelRank() const noexcept#
-
inline SizeType32 constexpr getLocalRank() const noexcept#
-
inline SizeType32 constexpr getNodeRank() const noexcept#
- inline SizeType32 constexpr getNodeRankOf(
- SizeType32 rank,
-
inline bool constexpr isFirstPipelineParallelRank() const noexcept#
-
inline bool constexpr isLastPipelineParallelRank() const noexcept#
我的 rank 是否是其 pipeline 中的最后一个 rank?
-
inline bool constexpr isFirstTensorParallelRank() const noexcept#
-
inline bool constexpr isFirstContextParallelRank() const noexcept#
-
inline SizeType32 constexpr getLastRank() const noexcept#
-
inline bool constexpr enableAttentionDP() const noexcept#
-
std::vector<SizeType32> getPipelineParallelGroup() const#
-
std::vector<SizeType32> getTensorParallelGroup() const#
-
std::vector<SizeType32> getContextParallelGroup() const#
-
bool validMpiConfig() const#
公共静态函数
- static WorldConfig mpi(
- SizeType32 gpusPerNode = kDefaultGpusPerNode,
- std::optional<SizeType32> tensorParallelism = std::nullopt,
- std::optional<SizeType32> pipelineParallelism = std::nullopt,
- std::optional<SizeType32> contextParallelism = std::nullopt,
- std::optional<std::vector<SizeType32>> const &deviceIds = std::nullopt,
- bool enableAttentionDP = false,
公共静态属性
-
static SizeType32 constexpr kDefaultGpusPerNode = 1#
私有成员
-
SizeType32 mTensorParallelism#
-
SizeType32 mPipelineParallelism#
-
SizeType32 mContextParallelism#
-
SizeType32 mRank#
-
SizeType32 mGpusPerNode#
-
bool mEnableAttentionDP#
-
std::vector<SizeType32> mDeviceIds#
-
class WorldConfig#
-
namespace runtime
promptTuningParams.h#
-
namespace tensorrt_llm
-
namespace runtime
-
template<typename TTensor>
class GenericPromptTuningParams# -
公共函数
-
class PromptTuningParams : public tensorrt_llm::runtime::GenericPromptTuningParams<ITensor::SharedPtr>#
公共类型
-
using SizeType32 = GenericPromptTuningParams::SizeType32#
公共函数
- inline explicit PromptTuningParams( )#
- void fillTasksTensor(
- TensorPtr tasksHost,
- const SizeType32 batchSize,
- const SizeType32 numContextRequests,
- std::vector<SizeType32> const &reqBeamWidths,
- std::vector<SizeType32> const &reqPromptLengths,
- BufferManager const &manager,
- bool packedInput,
-
using SizeType32 = GenericPromptTuningParams::SizeType32#
-
template<typename TTensor>
-
namespace runtime
rawEngine.h#
-
namespace tensorrt_llm
-
namespace runtime
-
class RawEngine#
-
公共函数
-
inline explicit RawEngine(std::filesystem::path enginePath) noexcept#
- inline explicit RawEngine(
- void const *engineAddr,
- std::size_t engineSize,
-
inline std::filesystem::path getPath() const#
-
inline std::optional<std::filesystem::path> getPathOpt() const#
-
inline void setPath(std::filesystem::path enginePath)#
- inline std::optional<std::map<std::string, tensorrt_llm::executor::Tensor>> const &getManagedWeightsMapOpt(
- inline void setManagedWeightsMap(
- std::map<std::string, tensorrt_llm::executor::Tensor> managedWeightsMap,
-
inline void const *getAddress() const#
-
inline std::size_t getSize() const#
-
inline explicit RawEngine(std::filesystem::path enginePath) noexcept#
-
class RawEngine#
-
namespace runtime
decoderState.h#
-
namespace tensorrt_llm
-
namespace runtime
-
namespace decoder
-
class BeamSearchBuffers#
公共函数
-
explicit BeamSearchBuffers(BufferManager const &bufferManager)#
-
void reshape(SizeType32 maxBeamWidth, SizeType32 maxSequenceLength)#
公共成员
-
DecodingOutput::BeamHypotheses mOutputBeamHypotheses#
-
DecodingOutput::TensorPtr mCumLogProbsTmp#
-
SizeType32 mNumSMs#
-
explicit BeamSearchBuffers(BufferManager const &bufferManager)#
-
class DecoderState#
公共类型
-
using LlmRequestPtr = std::shared_ptr<tensorrt_llm::batch_manager::LlmRequest>#
-
using RequestVector = std::vector<LlmRequestPtr>#
-
using DecodingInputPtr = std::unique_ptr<DecodingInput>#
-
using DecodingOutputPtr = std::unique_ptr<DecodingOutput>#
公共函数
- DecoderState(
- nvinfer1::DataType dtype,
- BufferManager const &bufferManager,
- void allocateSpeculativeDecodingBuffers(
- SpeculativeDecodingMode speculativeDecodingMode,
- nvinfer1::DataType dtype,
- BufferManager const &bufferManager,
为推测解码分配缓冲区。
- void setup(
- SizeType32 maxBatchSize,
- SizeType32 maxBeamWidth,
- SizeType32 maxAttentionWindow,
- SizeType32 sinkTokenLength,
- SizeType32 maxSequenceLength,
- ModelConfig const &modelConfig,
- WorldConfig const &worldConfig,
- BufferManager const &bufferManager,
- void setupSpeculativeDecoding(
- SpeculativeDecodingMode const &speculativeDecodingMode,
- SizeType32 maxTokensPerEngineStep,
- ModelConfig const &modelConfig,
- WorldConfig const &worldConfig,
- BufferManager const &bufferManager,
为推测解码设置缓冲区。
- void setupExplicitDraftTokens(
- ExplicitDraftTokensBuffers::Inputs explicitDraftTokensBuffers,
为 ExplicitDraftTokens 解码设置缓冲区。
- void setupLookahead(
- LookaheadDecodingBuffers lookaheadDecodingBuffers,
为 Lookahead 解码设置缓冲区。
-
void setupEagle(EagleBuffers::Inputs eagleBuffers) const#
为 Eagle 解码设置缓冲区。
-
void disableLookahead(RequestVector const &genRequests)#
禁用 Lookahead 解码。
-
TensorPtr getIds() const#
- 返回:
[batchSize, maxBeamWidth, maxInputLength + maxNewTokens],包含输入 token id 和生成的 token id,无填充,位于 GPU 上。对于 Beam Search,包含未收集的数据。
-
TensorPtr getIds(SizeType32 batchIdx) const#
- 参数:
batchIdx – 批次的索引
- 返回:
[maxBeamWidth, maxInputLength + maxNewTokens],包含请求
batchIdx
的输入 token id 和生成的 token id,无填充,位于 GPU 上。对于 Beam Search,包含未收集的数据。
-
TensorPtr getGatheredIds() const#
- 返回:
[batchSize, maxBeamWidth, maxInputLength + maxNewTokens],仅用于 Beam Search。包含已收集的 token id,无填充,位于 GPU 上。
-
TensorPtr getGatheredIds(SizeType32 batchIdx) const#
- 参数:
batchIdx – 批次的索引
- 返回:
[batchSize, maxBeamWidth, maxInputLength + maxNewTokens],仅用于 beam search。它包含 request
batchIdx
的无填充的 gathered token id,位于 gpu 上。
-
TensorPtr getParentIds() const#
- 返回:
[batchSize, maxBeamWidth, maxInputLength + maxNewTokens],包含 beam search 期间收集的无填充的 parent id,位于 gpu 上。
-
TensorPtr getCumLogProbs(SizeType32 batchIdx) const#
- 返回:
[maxBeamWidth],累积对数概率(每个 beam),位于 gpu 上。
-
TensorPtr getLogProbs() const#
- 返回:
[batchSize, maxBeamWidth, maxSequenceLength],对数概率(每个 beam),在 GPU 上
-
TensorPtr getLogProbs(SizeType32 batchIdx) const#
- 返回:
[maxBeamWidth, maxSequenceLength],对数概率(每个 beam),位于 gpu 上。
-
TensorPtr getAllNewTokens() const#
获取上一次前向传播中生成的 maxTokensPerStep 个 token。
- 返回:
[maxTokensPerStep, batchSize, maxBeamWidth],上一次前向传播中生成的 token,位于 gpu 上。
-
TensorPtr getNextDraftTokens() const#
- 返回:
[batchSize, maxDraftTokens],预测的用于下一步的 draft token,位于 gpu 上。
-
TensorPtr getAcceptedPackedPaths() const#
- 返回:
[batchSize, maxAcceptedDraftTokensPerStep],已接受的路径打包到连续张量中,位于 gpu 上。
-
TensorPtr getFinishedSteps() const#
- 返回:
[maxTokensPerStep, batchSize, beamWidth],类型为 FinishedState 的完成状态,位于 gpu 上。
-
SizeType32 getActualBatchSize() const#
-
void setActualBatchSize(SizeType32 actualBatchSize)#
-
SizeType32 getMaxBeamWidth() const#
-
SizeType32 getMaxSequenceLength() const#
-
SizeType32 getMaxDecodingDecoderTokens() const#
-
SizeType32 getMaxDecodingEngineTokens() const#
-
std::vector<SizeType32> const &getNumDecodingEngineTokens() const#
获取批次中所有请求的 token 数量。
- 返回:
批次中所有请求的 token 数量。
-
SizeType32 getNumDecodingEngineTokens(SizeType32 batchIdx) const#
获取批次中特定请求的 token 数量。
- 参数:
batchIdx – 请求在批次中的索引。
- 返回:
指定请求的 token 数量。
- void setNumDecodingEngineTokens(
- SizeType32 batchIdx,
- SizeType32 numTokens,
设置批次中特定请求的 token 数量。
- 参数:
batchIdx – 请求在批次中的索引。
numTokens – 指定请求的 token 数量。
-
SpeculativeDecodingMode getSpeculativeDecodingMode() const#
-
BeamSearchBuffers const &getBeamSearchBuffers() const#
流式模式下 beam search 的工作空间。
-
DecodingInput &getJointDecodingInput() const#
解码器的有状态输入。为 maxBatchSize 个槽位分配。
-
DecodingOutput &getJointDecodingOutput() const#
解码器的有状态输出。为 maxBatchSize 个槽位分配。
私有成员
-
SizeType32 mActualBatchSize = {}#
-
SizeType32 mMaxBatchSize = {}#
-
SizeType32 mMaxBeamWidth = {}#
-
SizeType32 mMaxSequenceLength = {}#
-
DecodingInputPtr mJointDecodingInput#
解码器的有状态输入。为 maxBatchSize 个槽位分配。
-
DecodingOutputPtr mJointDecodingOutput#
解码器的有状态输出。为 maxBatchSize 个槽位分配。
-
TensorPtr mFinishedSteps#
[maxTokensPerStep, batchSize, beamWidth] 类型为 FinishedState 的完成状态,对应 maxTokensPerStep 的每个生成 token,位于 gpu 上。
-
std::unique_ptr<BeamSearchBuffers> mBeamSearchBuffers#
流式模式下 beam search 的工作空间。
-
SizeType32 mMaxDecodingDecoderTokens = {1}#
-
SizeType32 mMaxDecodingEngineTokens = {1}#
-
std::vector<SizeType32> mNumDecodingEngineTokens#
[batchSize],每个请求的令牌数量。
-
SpeculativeDecodingMode mSpeculativeDecodingMode = {SpeculativeDecodingMode::None()}#
-
using LlmRequestPtr = std::shared_ptr<tensorrt_llm::batch_manager::LlmRequest>#
-
class BeamSearchBuffers#
-
namespace decoder
-
namespace runtime
runtimeDefaults.h#
-
namespace tensorrt_llm
-
namespace runtime
-
struct RuntimeDefaults#
公共函数
- inline RuntimeDefaults(
- std::optional<std::vector<SizeType32>> maxAttentionWindowVec,
- std::optional<SizeType32> sinkTokenLength,
-
RuntimeDefaults() = default#
公共成员
-
std::optional<std::vector<SizeType32>> maxAttentionWindowVec#
-
std::optional<SizeType32> sinkTokenLength#
-
struct RuntimeDefaults#
-
namespace runtime
eagleModule.h#
-
namespace tensorrt_llm
-
namespace runtime
-
class EagleModule : public tensorrt_llm::runtime::SpeculativeDecodingModule#
公共函数
- inline explicit EagleModule(
- 最大草稿路径长度,
- 最大解码草稿token数量,
- SizeType32 numTransformersLayer,
- SizeType32 maxNonLeafNodesPerLayer,
-
inline explicit EagleModule() noexcept#
- inline executor::EagleChoices const &getDefaultEagleChoices(
-
inline SizeType32 getNumTransformerLayers() const noexcept#
-
inline SizeType32 getMaxNonLeafNodesPerLayer() const noexcept#
私有成员
-
SizeType32 mNumTransformersLayer#
-
SizeType32 mMaxNonLeafNodesPerLayer#
-
executor::EagleChoices mDefaultEagleChoices = {{0}, {0, 0}, {1}, {0, 1}, {2}, {0, 0, 0}, {1, 0}, {0, 2}, {3}, {0, 3}, {4}, {0, 4}, {2, 0}, {0, 5}, {0, 0, 1}, {5}, {0, 6}, {6} , {0, 7}, {0, 1, 0}, {1, 1}, {7} , {0, 8}, {0, 0, 2}, {3, 0}, {0, 9}, {8} , {9} , {1, 0, 0}, {0, 2, 0}, {1, 2} , {0, 0, 3}, {4, 0}, {2, 1} , {0, 0, 4}, {0, 0, 5} , {0, 0, 0, 0} , {0, 1, 1} , {0, 0, 6} , {0, 3, 0} , {5, 0} , {1, 3} , {0, 0, 7} , {0, 0, 8} , {0, 0, 9} , {6, 0} , {0, 4, 0} , {1, 4} , {7, 0} , {0, 1, 2} , {2, 0, 0} , {3, 1} , {2, 2} , {8, 0} , {0, 5, 0} , {1, 5} , {1, 0, 1} , {0, 2, 1} , {9, 0} , {0, 6, 0} , {0, 0, 0, 1} , {1, 6} , {0, 7, 0}}#
-
class EagleModule : public tensorrt_llm::runtime::SpeculativeDecodingModule#
-
namespace runtime
speculativeDecodingMode.h#
-
namespace tensorrt_llm
-
namespace runtime
-
class SpeculativeDecodingMode#
公共类型
-
using UnderlyingType = std::uint8_t#
公共函数
-
inline bool constexpr isNone() const#
-
inline bool constexpr isDraftTokensExternal() const#
-
inline bool constexpr isMedusa() const#
-
inline bool constexpr isLookaheadDecoding() const#
-
inline bool constexpr isExplicitDraftTokens() const#
-
inline bool constexpr isEagle() const#
-
inline bool constexpr updatesPositionIds() const#
-
inline bool constexpr requiresAttentionMask() const#
-
inline bool constexpr predictsDraftTokens() const#
-
inline bool constexpr needsKVCacheRewind() const#
-
inline bool constexpr variableDraftLength() const#
-
inline bool constexpr hasDraftLogits() const#
-
inline bool constexpr needsDecoderPrologue() const#
-
inline bool operator==(SpeculativeDecodingMode const &other) const#
- inline explicit constexpr SpeculativeDecodingMode(
- UnderlyingType state,
公共静态函数
-
static inline auto constexpr None()#
-
static inline auto constexpr DraftTokensExternal()#
-
static inline auto constexpr Medusa()#
-
static inline auto constexpr LookaheadDecoding()#
-
static inline auto constexpr ExplicitDraftTokens()#
-
static inline auto constexpr Eagle()#
私有函数
-
inline bool constexpr anyBitSet(UnderlyingType bits) const#
-
inline bool constexpr allBitSet(UnderlyingType bits) const#
私有成员
-
UnderlyingType mState = {kNone}#
私有静态属性
-
static UnderlyingType constexpr kNone = {1U << 0U}#
-
static UnderlyingType constexpr kDraftTokensExternal = {1U << 1U}#
-
static UnderlyingType constexpr kMedusa = {1U << 2U}#
-
static UnderlyingType constexpr kLookaheadDecoding = {1U << 3U}#
-
static UnderlyingType constexpr kExplicitDraftTokens = {1U << 4U}#
-
static UnderlyingType constexpr kEagle = {1U << 5U}#
-
using UnderlyingType = std::uint8_t#
-
class SpeculativeDecodingMode#
-
namespace runtime
speculativeDecodingModule.h#
-
namespace tensorrt_llm
-
namespace runtime
-
class SpeculativeDecodingModule#
子类包括 tensorrt_llm::runtime::EagleModule, tensorrt_llm::runtime::LookaheadModule, tensorrt_llm::runtime::MedusaModule
公共函数
- inline explicit SpeculativeDecodingModule(
- 最大草稿路径长度,
- 最大解码草稿token数量,
- SizeType32 maxNumPaths,
-
inline explicit SpeculativeDecodingModule() noexcept#
-
virtual ~SpeculativeDecodingModule() = default#
-
SpeculativeDecodingModule(SpeculativeDecodingModule const &o) = default#
- SpeculativeDecodingModule &operator=(
- SpeculativeDecodingModule const &o,
-
inline SizeType32 getMaxDraftPathLen() const noexcept#
- 返回:
解码器一步可接受的最大草稿令牌数
-
inline SizeType32 getMaxPathLen() const noexcept#
比草稿路径长度多一,用于从主头进行预测
- 返回:
一个请求在解码器一步中可增长的最大令牌数
-
inline SizeType32 getMaxDecodingDraftTokens() const noexcept#
- 返回:
解码器一步处理的最大草稿令牌数
-
inline SizeType32 getMaxDecodingTokens() const noexcept#
比解码草稿令牌多一,用于从主头进行预测
- 返回:
解码器一步处理的最大令牌数
-
inline SizeType32 getNumPackedMasks() const noexcept#
-
inline SizeType32 getMaxNumPaths() const noexcept#
-
inline void setMaxDraftTokens(SizeType32 maxDraftTokens) noexcept#
-
inline void setMaxDraftPathLen(SizeType32 maxDraftPathLen) noexcept#
-
inline void setMaxNumPaths(SizeType32 maxNumPaths) noexcept#
私有函数
-
inline void computeNumPackedMasks() noexcept#
私有成员
-
SizeType32 mMaxDraftPathLen#
-
SizeType32 mMaxDecodingDraftTokens#
-
SizeType32 mMaxNumPaths#
-
SizeType32 mMaxNumPackedMasks#
-
class SpeculativeDecodingModule#
-
namespace runtime
ipcNvlsMemory.h#
-
namespace tensorrt_llm
-
namespace runtime
函数
-
void MPI_group_barrier(std::set<int> ranks)#
-
bool ipcNvlsSupported()#
-
IpcNvlsHandle *ipcNvlsAllocate(size_t size, std::set<int> ranks)#
-
void ipcNvlsFree(IpcNvlsHandle *handle)#
-
template<typename T>
class DeviceAllocationNvls#
-
struct IpcNvlsHandle#
公共成员
-
size_t size = 0#
-
uintptr_t uc_ptr = 0#
-
uintptr_t mc_ptr = 0#
-
std::vector<uintptr_t> ipc_uc_ptrs#
-
CUdeviceptr uc_va#
-
CUdeviceptr mc_va#
-
std::vector<CUdeviceptr> ipc_uc_vas#
-
CUmemGenericAllocationHandle uc_handle#
-
CUmemGenericAllocationHandle mc_handle#
-
std::vector<CUmemGenericAllocationHandle> ipc_uc_handles#
-
size_t size = 0#
-
void MPI_group_barrier(std::set<int> ranks)#
-
namespace runtime
tllmLogger.h#
statefulGptDecoderBatched.h#
-
namespace tensorrt_llm
-
namespace runtime
-
class StatefulGptDecoderBatched : public tensorrt_llm::runtime::IStatefulGptDecoder#
- #include <statefulGptDecoderBatched.h>
支持在途批处理和有状态接口的 GPT 解码器类。
公共函数
- StatefulGptDecoderBatched(
- CudaStreamPtr stream,
- nvinfer1::DataType dtype,
-
~StatefulGptDecoderBatched() override#
- virtual void setup(
- executor::DecodingMode const &mode,
- SizeType32 maxBatchSize,
- SizeType32 maxBeamWidth,
- SizeType32 maxAttentionWindow,
- SizeType32 sinkTokenLength,
- SizeType32 maxSequenceLength,
- nvinfer1::DataType dtype,
- ModelConfig const &modelConfig,
- WorldConfig const &worldConfig,
- virtual void newBatch(
- GenerationInput const &inputs,
- GenerationOutput const &outputs,
- SamplingConfig const &samplingConfig,
- ModelConfig const &modelConfig,
在调用
forward()
之前设置解码器,也调用 reshapeBuffers。
- virtual void forwardAsync( ) override#
在不阻塞主机线程的情况下,为所有请求运行一步。
-
virtual void forwardSync() override#
等待对
forwardAsync
的最后一次调用完成。
-
virtual TensorPtr getIds() const override#
- 返回:
[batchSize, beamWidth, maxSequenceLength],所有 token id,在 GPU 上
-
virtual TensorPtr getGatheredIds() const override#
- 返回:
[batchSize, beamWidth, maxSequenceLength] 在 gatherTree 后的 token id
- virtual void finalize(
- SamplingConfig const &samplingConfig,
收集所有请求的最终束搜索结果。
-
virtual TensorPtr getCumLogProbs() const override#
- 返回:
[batchSize, maxBeamWidth],累积对数概率(每个 beam),在 GPU 上
-
virtual TensorPtr getLogProbs() const override#
- 返回:
[batchSize, maxBeamWidth, maxSequenceLength],对数概率(每个 beam),在 GPU 上
-
virtual TensorPtr getNewTokens(SizeType32 iter = 0) const override#
获取上一次 forward 传递中一步生成的 token。
- 参数:
**iter** – 要获取 token 的迭代次数,范围在 [0; maxTokensPerStep) 内
- 返回:
[batchSize, beamWidth],在
iter
中生成的 token(每个 beam),在 GPU 上
-
class StatefulGptDecoderBatched : public tensorrt_llm::runtime::IStatefulGptDecoder#
-
namespace runtime