API 参考#
- class tensorrt_llm.llmapi.LLM(
- model: str | Path,
- tokenizer: str | Path | PreTrainedTokenizerBase | TokenizerBase | None = None,
- tokenizer_mode: Literal['auto', 'slow'] = 'auto',
- skip_tokenizer_init: bool = False,
- trust_remote_code: bool = False,
- tensor_parallel_size: int = 1,
- dtype: str = 'auto',
- revision: str | None = None,
- tokenizer_revision: str | None = None,
- **kwargs: Any,
基类:
object
LLM 类是运行 LLM 模型的主要类。
- 参数:
model (Union[str, pathlib.Path]) – 模型检查点或 Hugging Face Hub 中的模型名称的路径。
tokenizer (Union[str, pathlib.Path, transformers.tokenization_utils_base.PreTrainedTokenizerBase, tensorrt_llm.llmapi.tokenizer.TokenizerBase, NoneType]) – tokenizer 检查点或 Hugging Face Hub 中的 tokenizer 名称的路径。默认为 None。
tokenizer_mode (Literal['auto', 'slow']) – 初始化 tokenizer 的模式。默认为 auto。
skip_tokenizer_init (bool) – 是否跳过 tokenizer 初始化。默认为 False。
trust_remote_code (bool) – 是否信任远程代码。默认为 False。
tensor_parallel_size (int) – 张量并行大小。默认为 1。
dtype (str) – 用于模型的数据类型。默认为 auto。
revision (Optional[str]) – 用于模型的修订版本。默认为 None。
tokenizer_revision (Optional[str]) – 用于 tokenizer 的修订版本。默认为 None。
pipeline_parallel_size (int) – 流水线并行大小。默认为 1。
context_parallel_size (int) – 上下文并行大小。默认为 1。
gpus_per_node (Optional[int]) – 每个节点的 GPU 数量。默认为 None。
moe_tensor_parallel_size (Optional[int]) – MoE 模型专家权重的张量并行大小。默认为 None。
moe_expert_parallel_size (Optional[int]) – MoE 模型专家权重的专家并行大小。默认为 None。
enable_attention_dp (bool) – 启用注意力数据并行。默认为 False。
cp_config (Optional[dict]) – 上下文并行配置。默认为 None。
auto_parallel (bool) – 启用自动并行模式。默认为 False。
auto_parallel_world_size (Optional[int]) – 自动并行模式的世界大小。默认为 None。
load_format (Literal['auto', 'dummy']) – 加载模型的格式。默认为 auto。
enable_tqdm (bool) – 启用 tqdm 以显示进度条。默认为 False。
enable_lora (bool) – 启用 LoRA。默认为 False。
max_lora_rank (Optional[int]) – 最大 LoRA 秩。默认为 None。
max_loras (int) – LoRA 的最大数量。默认为 4。
max_cpu_loras (int) – CPU 上 LoRA 的最大数量。默认为 4。
enable_prompt_adapter (bool) – 启用提示适配器。默认为 False。
max_prompt_adapter_token (int) – 提示适配器 token 的最大数量。默认为 0。
quant_config (Optional[tensorrt_llm.models.modeling_utils.QuantConfig]) – 量化配置。默认为 None。
calib_config (Optional[tensorrt_llm.llmapi.llm_args.CalibConfig]) – 校准配置。默认为 None。
build_config (可选[tensorrt_llm.builder.BuildConfig]) – 构建配置。默认为 None。
kv_cache_config (可选[tensorrt_llm.llmapi.llm_args.KvCacheConfig]) – KV 缓存配置。默认为 None。
enable_chunked_prefill (bool) – 启用分块预填充。默认为 False。
guided_decoding_backend (可选[str]) – 指导解码后端。默认为 None。
batched_logits_processor (可选[tensorrt_llm.sampling_params.BatchedLogitsProcessor]) – 批量 logits 处理器。默认为 None。
iter_stats_max_iterations (可选[int]) – iter stats 的最大迭代次数。默认为 None。
request_stats_max_iterations (可选[int]) – request stats 的最大迭代次数。默认为 None。
workspace (可选[str]) – 模型的 workspace。默认为 None。
embedding_parallel_mode (str) – Embedding 并行模式。默认为 SHARDING_ALONG_VOCAB。
fast_build (bool) – 启用快速构建。默认为 False。
enable_build_cache (Union[tensorrt_llm.llmapi.build_cache.BuildCacheConfig, bool]) – 启用构建缓存。默认为 False。
peft_cache_config (可选[tensorrt_llm.llmapi.llm_args.PeftCacheConfig]) – PEFT 缓存配置。默认为 None。
scheduler_config (可选[tensorrt_llm.llmapi.llm_args.SchedulerConfig]) – 调度器配置。默认为 None。
speculative_config (Union[tensorrt_llm.llmapi.llm_args.LookaheadDecodingConfig, tensorrt_llm.llmapi.llm_args.MedusaDecodingConfig, tensorrt_llm.llmapi.llm_args.EagleDecodingConfig, tensorrt_llm.llmapi.llm_args.MTPDecodingConfig, NoneType]) – 推测解码配置。默认为 None。
batching_type (可选[tensorrt_llm.llmapi.llm_args.BatchingType]) – 批处理类型。默认为 None。
normalize_log_probs (bool) – 归一化 log 概率。默认为 False。
gather_generation_logits (bool) – 收集生成 logits。默认为 False。
extended_runtime_perf_knob_config (可选[tensorrt_llm.llmapi.llm_args.ExtendedRuntimePerfKnobConfig]) – 扩展运行时 perf knob 配置。默认为 None。
max_batch_size (可选[int]) – 最大 batch size。默认为 None。
max_input_len (int) – 最大输入长度。默认为 1024。
max_seq_len (可选[int]) – 最大序列长度。默认为 None。
max_beam_width (int) – 最大 beam width。默认为 1。
max_num_tokens (可选[int]) – 最大 token 数量。默认为 None。
backend (可选[str]) – 要使用的后端。默认为 None。
kwargs (Any) – 传递给 LlmArgs 的高级参数。
- tokenizer#
由 LLM 实例加载的 tokenizer,如果有的话。
- 类型:
tensorrt_llm.llmapi.tokenizer.TokenizerBase, 可选
- workspace#
存储中间文件的目录。
- 类型:
pathlib.Path
- __init__(
- model: str | Path,
- tokenizer: str | Path | PreTrainedTokenizerBase | TokenizerBase | None = None,
- tokenizer_mode: Literal['auto', 'slow'] = 'auto',
- skip_tokenizer_init: bool = False,
- trust_remote_code: bool = False,
- tensor_parallel_size: int = 1,
- dtype: str = 'auto',
- revision: str | None = None,
- tokenizer_revision: str | None = None,
- **kwargs: Any,
- generate(
- inputs: str | List[int] | TextPrompt | TokensPrompt | Sequence[str | List[int] | TextPrompt | TokensPrompt],
- sampling_params: SamplingParams | List[SamplingParams] | None = None,
- use_tqdm: bool = True,
- lora_request: LoRARequest | Sequence[LoRARequest] | None = None,
- prompt_adapter_request: PromptAdapterRequest | Sequence[PromptAdapterRequest] | None = None,
- queries: str | List[int] | TextPrompt | TokensPrompt | Sequence[str | List[int] | TextPrompt | TokensPrompt] | None = None,
- kv_cache_retention_config: KvCacheRetentionConfig | None = None,
- disaggregated_params: DisaggregatedParams | None = None,
为同步模式下给定的提示生成输出。同步生成接受单个提示或批量提示。
- 参数:
inputs (tensorrt_llm.inputs.data.PromptInputs, Sequence[tensorrt_llm.inputs.data.PromptInputs]) – 提示文本或 token ID。可以是单个提示或批量提示。
sampling_params (tensorrt_llm.sampling_params.SamplingParams, List[tensorrt_llm.sampling_params.SamplingParams], optional) – 生成的采样参数。默认为 None。如果未提供,将使用默认参数。
use_tqdm (bool) – 是否使用 tqdm 显示进度条。默认为 True。
lora_request (tensorrt_llm.executor.request.LoRARequest, Sequence[tensorrt_llm.executor.request.LoRARequest], optional) – 用于生成的 LoRA 请求(如果有)。默认为 None。
prompt_adapter_request (tensorrt_llm.executor.request.PromptAdapterRequest, Sequence[tensorrt_llm.executor.request.PromptAdapterRequest], optional) – 用于生成的 Prompt Adapter 请求(如果有)。默认为 None。
queries (tensorrt_llm.inputs.data.PromptInputs, Sequence[tensorrt_llm.inputs.data.PromptInputs], optional) – 查询文本或 token IDs。默认为 None。它可以是单个提示或批量提示。它用于星型注意力机制以运行长上下文任务。
kv_cache_retention_config (tensorrt_llm.bindings.executor.KvCacheRetentionConfig, optional) – 请求在 KV 缓存中的保留配置。默认为 None。
disaggregated_params (tensorrt_llm.disaggregated_params.DisaggregatedParams, optional) – 分解的参数。默认为 None。
- 返回值:
LLM 完成请求的输出数据。
- 返回类型:
Union[tensorrt_llm.llmapi.RequestOutput, List[tensorrt_llm.llmapi.RequestOutput]]
- generate_async(
- inputs: str | List[int] | TextPrompt | TokensPrompt,
- sampling_params: SamplingParams | None = None,
- lora_request: LoRARequest | None = None,
- prompt_adapter_request: PromptAdapterRequest | None = None,
- streaming: bool = False,
- queries: str | List[int] | TextPrompt | TokensPrompt | None = None,
- kv_cache_retention_config: KvCacheRetentionConfig | None = None,
- disaggregated_params: DisaggregatedParams | None = None,
- _postproc_params: PostprocParams | None = None,
以异步模式为给定的提示生成输出。 异步生成只接受单个提示。
- 参数:
inputs (tensorrt_llm.inputs.data.PromptInputs) – 提示文本或 token IDs;它必须是单个提示。
sampling_params (tensorrt_llm.sampling_params.SamplingParams, optional) – 生成的采样参数。默认为 None。 如果未提供,将使用默认参数。
lora_request (tensorrt_llm.executor.request.LoRARequest, optional) – 用于生成的 LoRA 请求(如果有)。默认为 None。
prompt_adapter_request (tensorrt_llm.executor.request.PromptAdapterRequest, optional) – 用于生成的 Prompt Adapter 请求(如果有)。默认为 None。
streaming (bool) – 是否使用流模式进行生成。默认为 False。
queries (tensorrt_llm.inputs.data.PromptInputs, optional) – 查询文本或 token IDs。默认为 None。它可以是单个提示或批量提示。 它用于星型注意力机制以运行长上下文任务。
kv_cache_retention_config (tensorrt_llm.bindings.executor.KvCacheRetentionConfig, optional) – 请求在 KV 缓存中的保留配置。默认为 None。
disaggregated_params (tensorrt_llm.disaggregated_params.DisaggregatedParams, optional) – 分解的参数。默认为 None。
- 返回值:
LLM 完成请求的输出数据。
- 返回类型:
- get_kv_cache_events(
- timeout: float | None = 2,
从运行时获取迭代 KV 事件。
- KV 事件用于跟踪 KV 缓存中的更改和操作。 事件类型包括
KVCacheCreatedData:指示缓存块的创建。
KVCacheStoredData:表示存储的块序列。
KVCacheRemovedData:包含从缓存中删除的块的哈希值。
KVCacheUpdatedData:捕获对现有缓存块的更新。
- 要启用 KV 事件
在 KvCacheConfig 中将 event_buffer_max_size 设置为正整数。
在 KvCacheConfig 中将 enable_block_reuse 设置为 True。
- 参数:
timeout (float, optional) – 从队列检索事件时的最大等待时间(以秒为单位)。 默认为 2。
- 返回值:
运行时事件的 dict 列表。
- 返回类型:
List[dict]
- get_kv_cache_events_async(
- timeout: float | None = 2,
从运行时获取迭代 KV 事件。
- KV 事件用于跟踪 KV 缓存中的更改和操作。 事件类型包括
KVCacheCreatedData:指示缓存块的创建。
KVCacheStoredData:表示存储的块序列。
KVCacheRemovedData:包含从缓存中删除的块的哈希值。
KVCacheUpdatedData:捕获对现有缓存块的更新。
- 要启用 KV 事件
在 KvCacheConfig 中将 event_buffer_max_size 设置为正整数。
在 KvCacheConfig 中将 enable_block_reuse 设置为 True。
- 参数:
timeout (float, optional) – 从队列检索事件时的最大等待时间(以秒为单位)。. 默认为 2。
- 返回值:
一个包含运行时事件的异步可迭代对象。
- 返回类型:
tensorrt_llm.executor.result.IterationResult
- get_stats(timeout: float | None = 2) List[dict] [source]#
从运行时获取迭代统计信息。 要收集统计信息,请在使用 LLM().generate() 提交提示后调用此函数。
- 参数:
timeout (float, optional) – 从队列检索统计信息时的最大等待时间(以秒为单位)。 默认为 2。
- 返回值:
- 运行时统计信息的 dict 列表。
例如,[‘{“cpuMemUsage”: …, “iter”: 0, …}’, ‘{“cpuMemUsage”: …, “iter”: 1, …}’]
- 返回类型:
List[dict]
- get_stats_async(
- timeout: float | None = 2,
从运行时获取迭代统计信息。 要收集统计信息,您可以在提交提示后,在异步协程或 /metrics 端点(如果您正在使用 trtllm-serve)中调用此函数。
- 参数:
timeout (float, optional) – 从队列检索统计信息时的最大等待时间(以秒为单位)。 默认为 2。
- 返回值:
一个包含运行时统计信息的异步可迭代对象。
- 返回类型:
tensorrt_llm.executor.result.IterationResult
- property tokenizer: TokenizerBase | None#
- property workspace: Path#
- class tensorrt_llm.llmapi.CompletionOutput(
- index: int,
- text: str = '',
- token_ids: List[int] | None = None,
- cumulative_logprob: float | None = None,
- logprobs: List[float] | None = None,
- finish_reason: Literal['stop', 'length', 'timeout', 'cancelled'] | None = None,
- stop_reason: int | str | None = None,
- generation_logits: Tensor | None = None,
- disaggregated_params: DisaggregatedParams | None = None,
- _postprocess_result: Any = None,
基类:
object
请求的单个补全输出的数据。
- 参数:
index (int) – 请求中输出的索引。
text (str) – 生成的输出文本。默认为“”。
token_ids (List[int], 可选) – 生成的输出文本的token id。默认为None。
cumulative_logprob (float, 可选) – 生成的输出文本的累积对数概率。默认为None。
logprobs (List[float], 可选) – 如果请求了logprobs,则每个位置上最高概率单词的对数概率。默认为None。
finish_reason (Literal['stop', 'length', 'timeout', 'cancelled'], 可选) – 序列结束的原因。默认为None。
stop_reason (int, str, 可选) – 导致补全停止的停止字符串或token id,如果补全因其他原因结束,则为None。默认为None。
generation_logits (torch.Tensor, 可选) – 生成的输出token id上的logits。默认为None。
disaggregated_params (tensorrt_llm.disaggregated_params.DisaggregatedParams, 可选) – 分离服务所需的参数。包括请求类型、第一个生成的token、上下文请求id以及任何需要从上下文和生成实例传输的附加状态。默认为None。
- length#
生成的token数量。
- 类型:
int
- token_ids_diff#
新生成的token id。
- 类型:
List[int]
- logprobs_diff#
新生成的token的Logprobs。
- 类型:
List[float]
- text_diff#
新生成的token。
- 类型:
str
- __init__(
- index: int,
- text: str = '',
- token_ids: List[int] | None = None,
- cumulative_logprob: float | None = None,
- logprobs: List[float] | None = None,
- finish_reason: Literal['stop', 'length', 'timeout', 'cancelled'] | None = None,
- stop_reason: int | str | None = None,
- generation_logits: Tensor | None = None,
- disaggregated_params: DisaggregatedParams | None = None,
- _postprocess_result: Any = None,
- cumulative_logprob: float | None#
- disaggregated_params: DisaggregatedParams | None#
- finish_reason: Literal['stop', 'length', 'timeout', 'cancelled'] | None#
- generation_logits: Tensor | None#
- index: int#
- property length: int#
- logprobs: List[float] | None#
- property logprobs_diff: List[float]#
- stop_reason: int | str | None#
- text: str#
- property text_diff: str#
- token_ids: List[int] | None#
- property token_ids_diff: List[int]#
- class tensorrt_llm.llmapi.RequestOutput[source]#
基类:
DetokenizedGenerationResultBase
,GenerationResult
LLM补全请求的输出数据。
- request_id#
请求的唯一ID。
- 类型:
int
- prompt#
请求的提示字符串。
- 类型:
str, 可选
- prompt_token_ids#
提示的token id。
- 类型:
List[int]
- outputs#
请求的输出序列。
- 类型:
List[CompletionOutput]
- context_logits#
提示token id的logits。
- 类型:
torch.Tensor, 可选
- finished#
整个请求是否完成。
- 类型:
bool
- property prompt: str | None#
- class tensorrt_llm.llmapi.GuidedDecodingParams(
- *,
- json: str | BaseModel | dict | None = None,
- regex: str | None = None,
- grammar: str | None = None,
- json_object: bool = False,
基类:
object
用于文本生成的引导解码参数。只有一个字段可以生效。
- 参数:
json (str, pydantic.main.BaseModel, dict, optional) – 生成的文本适用于具有额外用户指定限制的json格式,即schema。默认为None。
regex (str, optional) – 生成的文本适用于用户指定的正则表达式。默认为None。
grammar (str, optional) – 生成的文本适用于用户指定的扩展巴科斯范式(EBNF)语法。默认为None。
json_object (bool) – 如果为True,则生成的文本适用于json格式。默认为False。
- __init__(
- *,
- json: str | BaseModel | dict | None = None,
- regex: str | None = None,
- grammar: str | None = None,
- json_object: bool = False,
- grammar: str | None#
- json: str | BaseModel | dict | None#
- json_object: bool#
- regex: str | None#
- class tensorrt_llm.llmapi.SamplingParams(
- *,
- end_id: int | None = None,
- pad_id: int | None = None,
- max_tokens: int = 32,
- max_new_tokens: int | None = None,
- bad: str | List[str] | None = None,
- bad_token_ids: List[int] | None = None,
- stop: str | List[str] | None = None,
- stop_token_ids: List[int] | None = None,
- include_stop_str_in_output: bool = False,
- embedding_bias: Tensor | None = None,
- logits_processor: LogitsProcessor | None = None,
- apply_batched_logits_processor: bool = False,
- n: int = 1,
- 最佳结果数: 整数 | 无 = 无,
- 使用集束搜索: 布尔值 = 假,
- 集束宽度: 整数 = 1,
- 返回序列数: 整数 | 无 = 无,
- Top K: 整数 | 无 = 无,
- Top P: 浮点数 | 无 = 无,
- Top P 最小值: 浮点数 | 无 = 无,
- Top P 重置 IDs: 整数 | 无 = 无,
- Top P 衰减: 浮点数 | 无 = 无,
- 种子: 整数 | 无 = 无,
- 随机种子: 整数 | 无 = 无,
- 温度: 浮点数 | 无 = 无,
- 最小 Token 数: 整数 | 无 = 无,
- 最小长度: 整数 | 无 = 无,
- 集束搜索多样性率: 浮点数 | 无 = 无,
- 重复惩罚: 浮点数 | 无 = 无,
- 存在惩罚: 浮点数 | 无 = 无,
- 频率惩罚: 浮点数 | 无 = 无,
- 长度惩罚: 浮点数 | 无 = 无,
- 提前停止: 整数 | 无 = 无,
- 禁止重复 N-gram 大小: 整数 | 无 = 无,
- 最小 P: 浮点数 | 无 = 无,
- 集束宽度数组: 整数列表 | 无 = 无,
- 返回对数概率: 布尔值 = 假,
- 返回上下文 Logits: 布尔值 = 假,
- 返回生成 Logits: 布尔值 = 假,
- 从输出中排除输入: 布尔值 = 真,
- 返回编码器输出: 布尔值 = 假,
- 返回性能指标: 布尔值 = 假,
- 附加模型输出: AdditionalModelOutput 列表 | 无 = 无,
- lookahead_config: LookaheadDecodingConfig | None = None,
- guided_decoding: GuidedDecodingParams | None = None,
- ignore_eos: bool = False,
- detokenize: bool = True,
- add_special_tokens: bool = True,
- truncate_prompt_tokens: int | None = None,
- skip_special_tokens: bool = True,
- spaces_between_special_tokens: bool = True,
基类:
object
文本生成的采样参数。
- 参数:
end_id (int, optional) – 结束 token ID。默认为 None。
pad_id (int, optional) – 填充 token ID。默认为 None。
max_tokens (int) – 要生成的最大 token 数。默认为 32。
max_new_tokens (int, optional) – 要生成的最大 token 数。此参数正在被弃用;请使用 max_tokens 代替。默认为 None。
bad (str, List[str], optional) – 当生成一个字符串或字符串列表时,重定向生成,以便从返回的输出中排除坏字符串。默认为 None。
bad_token_ids (List[int], optional) – 当生成一个 token ID 列表时,重定向生成,以便从返回的输出中排除坏 ID。默认为 None。
stop (str, List[str], optional) – 当生成一个字符串或字符串列表时,停止生成。除非 include_stop_str_in_output 为 True,否则返回的输出将不包含停止字符串。默认为 None。
stop_token_ids (List[int], optional) – 当生成一个 token ID 列表时,停止生成。默认为 None。
include_stop_str_in_output (bool) – 是否在输出文本中包含停止字符串。默认为 False。
embedding_bias (torch.Tensor, optional) – 嵌入偏差张量。预期类型为 kFP32,形状为 [vocab_size]。默认为 None。
logits_processor (tensorrt_llm.sampling_params.LogitsProcessor, optional) – logits 后处理器回调。默认为 None。建议使用 LogitsProcessor 类来创建回调。
apply_batched_logits_processor (bool) – 是否应用批处理的 logits 后处理器回调。默认为 False。建议使用 BatchedLogitsProcessor 类来创建回调。必须在初始化 LLM 时提供回调。
n (int) – 要生成的序列数。默认为 1。
best_of (int, optional) – 用于最佳输出考虑的序列数。默认为 None。
use_beam_search (bool) – 是否使用 beam search。默认为 False。
beam_width (int) – beam 宽度。设置为 1 会禁用 beam search。此参数将在未来的 LLM API 版本中被弃用。请改用 n/best_of/use_beam_search。默认为 1。
num_return_sequences (int, optional) – 要返回的序列数。如果设置为 None,则默认为 beam_width 的值。此参数将在未来的 LLM API 版本中被弃用。请改用 n/best_of/use_beam_search。默认为 None。
top_k (int, optional) – 控制从中采样的 logits 数量。None 表示使用 C++ 运行时默认值 0,即所有 logits。默认为 None。
top_p (float, optional) – 控制从中采样的 top-P 概率。None 表示使用 C++ 运行时默认值 0.f。默认为 None。
top_p_min (float, optional) – 控制 top-P 算法中的衰减。topPMin 是下限。None 表示使用 C++ 运行时默认值 1.e-6。默认为 None。
top_p_reset_ids (int, optional) – 控制 top-P 算法中的衰减。指示重置衰减的位置。None 表示使用 C++ 运行时默认值 1。默认为 None。
top_p_decay (float, optional) – 控制 top-P 算法中的衰减。衰减值。None 表示使用 C++ 运行时默认值 1.f。默认为 None。
seed (int, optional) – 控制采样中随机数生成器使用的随机种子。None 表示使用 C++ 运行时默认值 0。默认为 None。
random_seed (int, optional) – 此参数正在被弃用;请改用 seed。默认为 None。
temperature (float, optional) – 控制采样新 token 时 logits 的调制。它可以具有 > 0.f 的值。None 表示使用 C++ 运行时默认值 1.0f。默认为 None。
min_tokens (int, optional) – 要生成的 token 数量的下限。值 < 1 无效。None 表示使用 C++ 运行时默认值 1。默认为 None。
min_length (int, optional) – 此参数正在被弃用;请改用 min_tokens。默认为 None。
beam_search_diversity_rate (float, optional) – 用于根据 token 在序列中出现的频率来惩罚 token。它可以具有任何 > 0.f 的值。值 < 1.f 鼓励重复,值 > 1.f 阻止重复。None 表示使用 C++ 运行时默认值 1.f。默认为 None。
repetition_penalty (float, optional) – 用于根据 token 在序列中出现的频率来惩罚 token。它可以具有任何 > 0.f 的值。值 < 1.f 鼓励重复,值 > 1.f 阻止重复。None 表示使用 C++ 运行时默认值 1.f。默认为 None。
presence_penalty (float, optional) – 用于惩罚序列中已经存在的 token(与出现次数无关)。它可以具有任何值。值 < 0.f 鼓励重复,值 > 0.f 阻止重复。None 表示使用 C++ 运行时默认值 0.f。默认为 None。
frequency_penalty (float, optional) – 用于惩罚序列中已经存在的 token(取决于出现次数)。它可以具有任何值。值 < 0.f 鼓励重复,值 > 0.f 阻止重复。None 表示使用 C++ 运行时默认值 0.f。默认为 None。
length_penalty (float, optional) – 控制如何在 beam search 中惩罚更长的序列。None 表示使用 C++ 运行时默认值 0.f。默认为 None。
early_stopping (int, optional) – 控制是否在生成 beamWidth 个句子(以 end_token 结尾)后完成生成过程。None 表示使用 C++ 运行时默认值 1。默认为 None。
no_repeat_ngram_size (int, optional) – 控制可以接受的重复 ngram 大小。None 表示使用 C++ 运行时默认值 1 << 30。默认为 None。
min_p (float, optional) – 缩放最可能的 token 以确定最小 token 概率。None 表示使用 C++ 运行时默认值 0.0。默认为 None。
beam_width_array (List[int], optional) – 在可变 Beam 宽度搜索中使用的 beam 宽度数组。默认为 None。
return_log_probs (bool) – 控制 Result 是否应包含对数概率。默认为 False。
return_context_logits (bool) – 控制 Result 是否应包含上下文 logits。默认为 False。
return_generation_logits (bool) – 控制 Result 是否应包含生成 logits。默认为 False。
exclude_input_from_output (bool) – 控制 Result 中的输出 token 是否应包含输入 token。默认为 True。
return_encoder_output (bool) – 控制 Result 是否应包含编码器输出隐藏状态(对于仅编码器和编码器-解码器模型)。默认为 False。
return_perf_metrics (bool) – 控制 Result 是否应包含此请求的性能指标。默认为 False。
additional_model_outputs (List[tensorrt_llm.sampling_params.AdditionalModelOutput], optional) – 要从模型收集的其他输出。默认为 None。
lookahead_config (tensorrt_llm.bindings.executor.LookaheadDecodingConfig , optional) – 前瞻解码配置。默认为 None。
guided_decoding (tensorrt_llm.sampling_params.GuidedDecodingParams, optional) – Guided decoding params. 默认为 None。
ignore_eos (bool) – 是否忽略 EOS token 并在生成 EOS token 后继续生成 token。默认为 False。
detokenize (bool) – 是否对输出进行反 token 化。默认为 True。
add_special_tokens (bool) – 是否将特殊 token 添加到提示中。默认为 True。
truncate_prompt_tokens (int, optional) – 如果设置为整数 k,将仅使用提示中的最后 k 个 token(即,左侧截断)。默认为 None。
skip_special_tokens (bool) – 是否跳过输出中的特殊 token。默认为 True。
spaces_between_special_tokens (bool) – 是否在输出中的特殊 token 之间添加空格。默认为 True。
- __init__(
- *,
- end_id: int | None = None,
- pad_id: int | None = None,
- max_tokens: int = 32,
- max_new_tokens: int | None = None,
- bad: str | List[str] | None = None,
- bad_token_ids: List[int] | None = None,
- stop: str | List[str] | None = None,
- stop_token_ids: List[int] | None = None,
- include_stop_str_in_output: bool = False,
- embedding_bias: Tensor | None = None,
- logits_processor: LogitsProcessor | None = None,
- apply_batched_logits_processor: bool = False,
- n: int = 1,
- 最佳结果数: 整数 | 无 = 无,
- 使用集束搜索: 布尔值 = 假,
- 集束宽度: 整数 = 1,
- 返回序列数: 整数 | 无 = 无,
- Top K: 整数 | 无 = 无,
- Top P: 浮点数 | 无 = 无,
- Top P 最小值: 浮点数 | 无 = 无,
- Top P 重置 IDs: 整数 | 无 = 无,
- Top P 衰减: 浮点数 | 无 = 无,
- 种子: 整数 | 无 = 无,
- 随机种子: 整数 | 无 = 无,
- 温度: 浮点数 | 无 = 无,
- 最小 Token 数: 整数 | 无 = 无,
- 最小长度: 整数 | 无 = 无,
- 集束搜索多样性率: 浮点数 | 无 = 无,
- 重复惩罚: 浮点数 | 无 = 无,
- 存在惩罚: 浮点数 | 无 = 无,
- 频率惩罚: 浮点数 | 无 = 无,
- 长度惩罚: 浮点数 | 无 = 无,
- 提前停止: 整数 | 无 = 无,
- 禁止重复 N-gram 大小: 整数 | 无 = 无,
- 最小 P: 浮点数 | 无 = 无,
- 集束宽度数组: 整数列表 | 无 = 无,
- 返回对数概率: 布尔值 = 假,
- 返回上下文 Logits: 布尔值 = 假,
- 返回生成 Logits: 布尔值 = 假,
- 从输出中排除输入: 布尔值 = 真,
- 返回编码器输出: 布尔值 = 假,
- 返回性能指标: 布尔值 = 假,
- 附加模型输出: AdditionalModelOutput 列表 | 无 = 无,
- lookahead_config: LookaheadDecodingConfig | None = None,
- guided_decoding: GuidedDecodingParams | None = None,
- ignore_eos: bool = False,
- detokenize: bool = True,
- add_special_tokens: bool = True,
- truncate_prompt_tokens: int | None = None,
- skip_special_tokens: bool = True,
- spaces_between_special_tokens: bool = True,
- add_special_tokens: bool#
- additional_model_outputs: List[AdditionalModelOutput] | None#
- apply_batched_logits_processor: bool#
- bad: str | List[str] | None#
- bad_token_ids: List[int] | None#
- beam_search_diversity_rate: float | None#
- beam_width: int#
- beam_width_array: List[int] | None#
- best_of: int | None#
- detokenize: bool#
- early_stopping: int | None#
- embedding_bias: Tensor | None#
- end_id: int | None#
- exclude_input_from_output: bool#
- frequency_penalty: float | None#
- guided_decoding: GuidedDecodingParams | None#
- ignore_eos: bool#
- include_stop_str_in_output: bool#
- length_penalty: float | None#
- logits_processor: LogitsProcessor | None#
- lookahead_config: LookaheadDecodingConfig | None#
- max_new_tokens: int | None#
- max_tokens: int#
- min_length: int | None#
- min_p: float | None#
- min_tokens: int | None#
- n: int#
- no_repeat_ngram_size: int | None#
- num_return_sequences: int | None#
- pad_id: int | None#
- presence_penalty: float | None#
- random_seed: int | None#
- repetition_penalty: float | None#
- return_context_logits: bool#
- return_encoder_output: bool#
- return_generation_logits: bool#
- return_log_probs: bool#
- return_perf_metrics: bool#
- seed: int | None#
- skip_special_tokens: bool#
- spaces_between_special_tokens: bool#
- stop: str | List[str] | None#
- stop_token_ids: List[int] | None#
- temperature: float | None#
- top_k: int | None#
- top_p: float | None#
- top_p_decay: float | None#
- top_p_min: float | None#
- top_p_reset_ids: int | None#
- truncate_prompt_tokens: int | None#
- use_beam_search: bool#
- class tensorrt_llm.llmapi.DisaggregatedParams(
- *,
- request_type: str | None = None,
- first_gen_tokens: List[int] | None = None,
- ctx_request_id: int | None = None,
- opaque_state: bytes | None = None,
- draft_tokens: List[int] | None = None,
基类:
object
分散的服务参数
- 参数:
request_type (str) – 请求的类型 (“context_only” 或 “generation_only”)
first_gen_tokens (List[int]) – 生成请求的第一个 tokens
ctx_request_id (int) – 上下文请求 ID
opaque_state (bytes) – 上下文和生成实例之间需要交换的任何附加状态
- __init__(
- *,
- request_type: str | None = None,
- first_gen_tokens: List[int] | None = None,
- ctx_request_id: int | None = None,
- opaque_state: bytes | None = None,
- draft_tokens: List[int] | None = None,
- ctx_request_id: int | None#
- draft_tokens: List[int] | None#
- first_gen_tokens: List[int] | None#
- opaque_state: bytes | None#
- request_type: str | None#
- class tensorrt_llm.llmapi.KvCacheConfig(
- *,
- enable_block_reuse: bool = True,
- max_tokens: int | None = None,
- max_attention_window: List[int] | None = None,
- sink_token_length: int | None = None,
- free_gpu_memory_fraction: float | None = None,
- host_cache_size: int | None = None,
- onboard_blocks: bool = True,
- cross_kv_cache_fraction: float | None = None,
- secondary_offload_min_priority: int | None = None,
- event_buffer_max_size: int = 0,
- enable_partial_reuse: bool = True,
- copy_on_partial_reuse: bool = True,
Bases:
BaseModel
,PybindMirror
KV 缓存的配置。
- field copy_on_partial_reuse: bool = True#
指示是否可以在复制后重用使用中的部分匹配的块。
- field cross_kv_cache_fraction: float | None = None#
应该为交叉注意力保留的 KV 缓存内存比例。如果设置为 p,则自注意力将使用 KV 缓存内存的 1-p,交叉注意力将使用 KV 缓存内存的 p。默认为 50%。仅在使用编码器-解码器模型时才应设置。
- field enable_block_reuse: bool = True#
控制 KV 缓存块是否可以用于不同的请求。
- field enable_partial_reuse: bool = True#
指示是否可以重用仅部分匹配的块。
- field event_buffer_max_size: int = 0#
事件缓冲区的最大大小。如果设置为 0,则不会使用事件缓冲区。
- field free_gpu_memory_fraction: float | None = None#
应为 KV 缓存分配的 GPU 内存比例。默认为 90%。如果同时指定 max_tokens 和 free_gpu_memory_fraction,则将使用对应于最小值的内存。
- field host_cache_size: int | None = None#
主机缓存的大小(以字节为单位)。如果同时指定 max_tokens 和 host_cache_size,则将使用对应于最小值的内存。
- field max_attention_window: List[int] | None = None#
每个序列的注意力窗口大小。只有最后的 token 会存储在 KV 缓存中。如果 max_attention_window 中的元素数量少于层数,则 max_attention_window 将重复多次以达到层数。
- field max_tokens: int | None = None#
应存储在 KV 缓存中的最大 token 数。如果同时指定 max_tokens 和 free_gpu_memory_fraction,则将使用对应于最小值的内存。
- model_config: ClassVar[ConfigDict] = {}#
模型的配置,应该是一个符合 [ConfigDict][pydantic.config.ConfigDict] 的字典。
- field onboard_blocks: bool = True#
控制是否启用块的 onboard 功能。
- field secondary_offload_min_priority: int | None = None#
只有优先级 > mSecondaryOfflineMinPriority 的块才能被卸载到辅助内存。
- field sink_token_length: int | None = None#
Sink token 的数量(始终保留在注意力窗口中的 token)。
- class tensorrt_llm.llmapi.KvCacheRetentionConfig#
Bases:
pybind11_object
- class TokenRangeRetentionConfig#
Bases:
pybind11_object
- __init__(
- self: tensorrt_llm.bindings.executor.KvCacheRetentionConfig.TokenRangeRetentionConfig,
- token_start: int,
- token_end: int | None,
- priority: int,
- duration_ms: datetime.timedelta | None = None,
- property duration_ms#
- property priority#
- property token_end#
- property token_start#
- __init__(
- self: tensorrt_llm.bindings.executor.KvCacheRetentionConfig,
- token_range_retention_configs: list[tensorrt_llm.bindings.executor.KvCacheRetentionConfig.TokenRangeRetentionConfig],
- decode_retention_priority: int = 35,
- decode_duration_ms: datetime.timedelta | None = None,
- property decode_duration_ms#
- property decode_retention_priority#
- property token_range_retention_configs#
- class tensorrt_llm.llmapi.LookaheadDecodingConfig(
- *,
- max_draft_len: int | None = None,
- speculative_model: str | Path | None = None,
- max_window_size: int = 4,
- max_ngram_size: int = 3,
- max_verification_set_size: int = 4,
Bases:
DecodingBaseConfig
,PybindMirror
前瞻性推测解码的配置。
- __init__(**data)[source]#
通过解析和验证来自关键字参数的输入数据来创建一个新模型。
如果无法验证输入数据以形成有效模型,则引发 [ValidationError][pydantic_core.ValidationError] 。
self 显式地仅为位置参数,以允许 self 作为字段名称。
- decoding_type: ClassVar[str] = 'Lookahead'#
- field max_ngram_size: int = 3#
每个 NGram 的 Token 数量。
- field max_verification_set_size: int = 4#
每步验证分支中的 NGram 数量。
- field max_window_size: int = 4#
每步前瞻分支中的 NGram 数量。
- model_config: ClassVar[ConfigDict] = {}#
模型的配置,应该是一个符合 [ConfigDict][pydantic.config.ConfigDict] 的字典。
- class tensorrt_llm.llmapi.MedusaDecodingConfig(
- *,
- max_draft_len: int | None = None,
- speculative_model: str | Path | None = None,
- medusa_choices: List[List[int]] | None = None,
- num_medusa_heads: int | None = None,
Bases:
DecodingBaseConfig
- 解码类型: 类变量[字符串] = 'Medusa'#
- 字段 medusa_choices: 列表[列表[整数]] | None = None#
- 模型配置: 类变量[配置字典] = {}#
模型的配置,应该是一个符合 [ConfigDict][pydantic.config.ConfigDict] 的字典。
- 字段 medusa 头数: 整数 | None = None#
- 类 tensorrt_llm.llmapi.EagleDecodingConfig(
- *,
- max_draft_len: int | None = None,
- speculative_model: str | Path | None = None,
- eagle_choices: 列表[列表[整数]] | None = None,
- 贪婪采样: 布尔 | None = True,
- 后验概率阈值: 浮点数 | None = None,
- 使用动态树: 布尔 | None = False,
- 动态树最大 TopK: 整数 | None = None,
- eagle 层数: 整数 | None = None,
- 每层的最大非叶节点数: 整数 | None = None,
- PyTorch Eagle 权重路径: 字符串 | None = None,
Bases:
DecodingBaseConfig
- 解码类型: 类变量[字符串] = 'Eagle'#
- 字段 动态树最大 TopK: 整数 | None = None#
- 字段 eagle_choices: 列表[列表[整数]] | None = None#
- 字段 贪婪采样: 布尔 | None = True#
- 字段 每层的最大非叶节点数: 整数 | None = None#
- 模型配置: 类变量[配置字典] = {}#
模型的配置,应该是一个符合 [ConfigDict][pydantic.config.ConfigDict] 的字典。
- field num_eagle_layers: int | None = None#
- 字段 posterior_threshold: float | None = None#
- 字段 pytorch_eagle_weights_path: str | None = None#
- 字段 use_dynamic_tree: bool | None = False#
- 类 tensorrt_llm.llmapi.MTPDecodingConfig(
- *,
- max_draft_len: int | None = None,
- speculative_model: str | Path | None = None,
- num_nextn_predict_layers: int | None = 1,
Bases:
DecodingBaseConfig
- decoding_type: ClassVar[str] = 'MTP'#
- model_config: ClassVar[ConfigDict] = {}#
模型的配置,应该是一个符合 [ConfigDict][pydantic.config.ConfigDict] 的字典。
- 字段 num_nextn_predict_layers: int | None = 1#
- 类 tensorrt_llm.llmapi.SchedulerConfig(
- *,
- capacity_scheduler_policy: CapacitySchedulerPolicy = CapacitySchedulerPolicy.GUARANTEED_NO_EVICT,
- context_chunking_policy: ContextChunkingPolicy | None = None,
- dynamic_batch_config: DynamicBatchConfig | None = None,
Bases:
BaseModel
,PybindMirror
- 字段 capacity_scheduler_policy: CapacitySchedulerPolicy = CapacitySchedulerPolicy.GUARANTEED_NO_EVICT#
使用的容量调度器策略
- 字段 context_chunking_policy: ContextChunkingPolicy | None = None#
使用的上下文分块策略
- 字段 dynamic_batch_config: DynamicBatchConfig | None = None#
使用的动态批处理配置
- model_config: ClassVar[ConfigDict] = {}#
模型的配置,应该是一个符合 [ConfigDict][pydantic.config.ConfigDict] 的字典。
- 类 tensorrt_llm.llmapi.CapacitySchedulerPolicy(
- 值,
- names=<未给定>,
- *值,
- 模块=None,
- 限定名=None,
- 类型=None,
- 开始=1,
- 边界=None,
基类:
StrEnum
- GUARANTEED_NO_EVICT = 'GUARANTEED_NO_EVICT'#
- MAX_UTILIZATION = 'MAX_UTILIZATION'#
- STATIC_BATCH = 'STATIC_BATCH'#
- class tensorrt_llm.llmapi.BuildConfig(
- max_input_len: int = 1024 最大输入长度: 整数 = 1024,
- max_seq_len: int = None 最大序列长度: 整数 = None,
- opt_batch_size: int = 8 优化批次大小: 整数 = 8,
- max_batch_size: int = 2048 最大批次大小: 整数 = 2048,
- max_beam_width: int = 1 最大束搜索宽度: 整数 = 1,
- max_num_tokens: int = 8192 最大token数量: 整数 = 8192,
- opt_num_tokens: Optional[int] = None 优化token数量: 可选[整数] = None,
- max_prompt_embedding_table_size: int = 0 最大提示嵌入表大小: 整数 = 0,
- kv_cache_type: tensorrt_llm.bindings.KVCacheType = None KV缓存类型: tensorrt_llm.bindings.KVCacheType = None,
- gather_context_logits: int = False 收集上下文logits: 整数 = False,
- gather_generation_logits: int = False 收集生成logits: 整数 = False,
- strongly_typed: bool = True 强类型: 布尔 = True,
- force_num_profiles: Optional[int] = None 强制profile数量: 可选[整数] = None,
- profiling_verbosity: str = 'layer_names_only' 性能分析详细程度: 字符串 = 'layer_names_only' (仅层名称),
- enable_debug_output: bool = False 启用调试输出: 布尔 = False,
- max_draft_len: int = 0 最大草稿长度: 整数 = 0,
- speculative_decoding_mode: tensorrt_llm.models.modeling_utils.SpeculativeDecodingMode = <SpeculativeDecodingMode.NONE: 1> 推测解码模式: tensorrt_llm.models.modeling_utils.SpeculativeDecodingMode = <SpeculativeDecodingMode.NONE: 1> (无),
- use_refit: bool = False 使用refit: 布尔 = False,
- input_timing_cache: str = None 输入时序缓存: 字符串 = None,
- output_timing_cache: str = 'model.cache' 输出时序缓存: 字符串 = 'model.cache',
- lora_config: tensorrt_llm.lora_manager.LoraConfig = <factory> Lora配置: tensorrt_llm.lora_manager.LoraConfig = <工厂>,
- auto_parallel_config: tensorrt_llm.auto_parallel.config.AutoParallelConfig = <factory> 自动并行配置: tensorrt_llm.auto_parallel.config.AutoParallelConfig = <工厂>,
- weight_sparsity: bool = False 权重稀疏性: 布尔 = False,
- weight_streaming: bool = False 权重流式传输: 布尔 = False,
- plugin_config: tensorrt_llm.plugin.plugin.PluginConfig = <factory> 插件配置: tensorrt_llm.plugin.plugin.PluginConfig = <工厂>,
- use_strip_plan: bool = False 使用strip plan: 布尔 = False,
- max_encoder_input_len: int = 1024 最大编码器输入长度: 整数 = 1024,
- dry_run: bool = False 空运行: 布尔 = False,
- visualize_network: str = None 可视化网络: 字符串 = None,
- monitor_memory: bool = False 监控内存: 布尔 = False,
- use_mrope: bool = False 使用 mrope: 布尔 = False,
基类:
object
- __init__(
- max_input_len: int = 1024 最大输入长度: 整数 = 1024,
- max_seq_len: int = None 最大序列长度: 整数 = None,
- opt_batch_size: int = 8 优化批次大小: 整数 = 8,
- max_batch_size: int = 2048 最大批次大小: 整数 = 2048,
- max_beam_width: int = 1 最大束搜索宽度: 整数 = 1,
- max_num_tokens: int = 8192 最大token数量: 整数 = 8192,
- opt_num_tokens: int | None = None 优化token数量: 整数 | None = None,
- max_prompt_embedding_table_size: int = 0 最大提示嵌入表大小: 整数 = 0,
- kv_cache_type: ~tensorrt_llm.bindings.KVCacheType = None KV缓存类型: ~tensorrt_llm.bindings.KVCacheType = None,
- gather_context_logits: int = False 收集上下文logits: 整数 = False,
- gather_generation_logits: int = False 收集生成logits: 整数 = False,
- strongly_typed: bool = True 强类型: 布尔 = True,
- force_num_profiles: int | None = None 强制profile数量: 整数 | None = None,
- profiling_verbosity: str = 'layer_names_only' 性能分析详细程度: 字符串 = 'layer_names_only' (仅层名称),
- enable_debug_output: bool = False 启用调试输出: 布尔 = False,
- max_draft_len: int = 0 最大草稿长度: 整数 = 0,
- speculative_decoding_mode: ~tensorrt_llm.models.modeling_utils.SpeculativeDecodingMode = <SpeculativeDecodingMode.NONE: 1> 推测解码模式: ~tensorrt_llm.models.modeling_utils.SpeculativeDecodingMode = <SpeculativeDecodingMode.NONE: 1>,
- use_refit: bool = False 使用refit: 布尔 = False,
- input_timing_cache: str = None 输入时序缓存: 字符串 = None,
- output_timing_cache: str = 'model.cache' 输出时序缓存: 字符串 = 'model.cache',
- lora_config: ~tensorrt_llm.lora_manager.LoraConfig = <factory> Lora配置: ~tensorrt_llm.lora_manager.LoraConfig = <工厂>,
- auto_parallel_config: ~tensorrt_llm.auto_parallel.config.AutoParallelConfig = <factory> 自动并行配置: ~tensorrt_llm.auto_parallel.config.AutoParallelConfig = <工厂>,
- weight_sparsity: bool = False 权重稀疏性: 布尔 = False,
- weight_streaming: bool = False 权重流式传输: 布尔 = False,
- plugin_config: ~tensorrt_llm.plugin.plugin.PluginConfig = <factory> 插件配置: ~tensorrt_llm.plugin.plugin.PluginConfig = <工厂>,
- use_strip_plan: bool = False 使用strip plan: 布尔 = False,
- max_encoder_input_len: int = 1024 最大编码器输入长度: 整数 = 1024,
- dry_run: bool = False 空运行: 布尔 = False,
- visualize_network: str = None 可视化网络: 字符串 = None,
- monitor_memory: bool = False 监控内存: 布尔 = False,
- use_mrope: bool = False 使用 mrope: 布尔 = False,
- auto_parallel_config: AutoParallelConfig# 自动并行配置: AutoParallelConfig
- dry_run: bool = False# 空运行: 布尔 = False
- enable_debug_output: bool = False#
- force_num_profiles: int | None = None#
- gather_context_logits: int = False#
- gather_generation_logits: int = False#
- input_timing_cache: str = None#
- kv_cache_type: KVCacheType = None#
- lora_config: LoraConfig#
- max_batch_size: int = 2048#
- max_beam_width: int = 1#
- max_draft_len: int = 0#
- max_encoder_input_len: int = 1024#
- max_input_len: int = 1024#
- max_num_tokens: int = 8192#
- max_prompt_embedding_table_size: int = 0#
- max_seq_len: int = None#
- monitor_memory: bool = False#
- opt_batch_size: int = 8#
- opt_num_tokens: int | None = None#
- output_timing_cache: str = 'model.cache'#
- plugin_config: PluginConfig#
- profiling_verbosity: str = 'layer_names_only'#
- speculative_decoding_mode: SpeculativeDecodingMode = 1#
- strongly_typed: bool = True#
- use_mrope: bool = False#
- use_refit: bool = False#
- use_strip_plan: bool = False#
- visualize_network: str = None#
- weight_sparsity: bool = False#
- weight_streaming: bool = False#
- class tensorrt_llm.llmapi.QuantConfig(
- quant_algo: QuantAlgo | None = None,
- kv_cache_quant_algo: QuantAlgo | None = None,
- group_size: int = 128,
- smoothquant_val: float = 0.5,
- clamp_val: List[float] | None = None,
- use_meta_recipe: bool = False,
- has_zero_point: bool = False,
- pre_quant_scale: bool = False,
- exclude_modules: List[str] | None = None,
基类:
object
可序列化的量化配置类,是 PretrainedConfig 的一部分。
- 参数:
quant_algo (tensorrt_llm.quantization.mode.QuantAlgo, 可选) – 量化算法。 默认为 None。
kv_cache_quant_algo (tensorrt_llm.quantization.mode.QuantAlgo, 可选) – KV 缓存量化算法。 默认为 None。
group_size (int) – 用于分组量化的组大小。 默认为 128。
smoothquant_val (float) – 在 smooth quant 中使用的平滑参数 alpha。 默认为 0.5。
clamp_val (List[float], 可选) – 用于 FP8 行式量化的 clamp 值。 默认为 None。
use_meta_recipe (bool) – 是否使用 Meta 的 FP8 行式量化方案。 默认为 False。
has_zero_point (bool) – 是否使用零点进行量化。 默认为 False。
pre_quant_scale (bool) – 是否使用预量化比例进行量化。 默认为 False。
exclude_modules (List[str], 可选) – 在量化中跳过的模块名称模式。 默认为 None。
- __init__(
- quant_algo: QuantAlgo | None = None,
- kv_cache_quant_algo: QuantAlgo | None = None,
- group_size: int = 128,
- smoothquant_val: float = 0.5,
- clamp_val: List[float] | None = None,
- use_meta_recipe: bool = False,
- has_zero_point: bool = False,
- pre_quant_scale: bool = False,
- exclude_modules: List[str] | None = None,
- clamp_val: List[float] | None = None#
- exclude_modules: List[str] | None = None#
- classmethod from_dict(
- config: dict,
从字典创建一个 QuantConfig 实例。
- 参数:
config (dict) – 用于创建 QuantConfig 的字典。
- 返回值:
从字典创建的 QuantConfig。
- 返回类型:
- group_size: int = 128#
- has_zero_point: bool = False#
- is_module_excluded_from_quantization(name: str) bool [source]#
检查模块是否从量化中排除。
- 参数:
name (str) – 模块的名称。
- 返回值:
如果模块从量化中排除,则为 True,否则为 False。
- 返回类型:
bool
- pre_quant_scale: bool = False#
- property quant_mode: QuantModeWrapper#
- smoothquant_val: float = 0.5#
- use_meta_recipe: bool = False#
- class tensorrt_llm.llmapi.QuantAlgo(
- 值,
- names=<未给定>,
- *值,
- 模块=None,
- 限定名=None,
- 类型=None,
- 开始=1,
- 边界=None,
基类:
StrEnum
- FP8 = 'FP8'#
- FP8_BLOCK_SCALES = 'FP8_BLOCK_SCALES'#
- FP8_PER_CHANNEL_PER_TOKEN = 'FP8_PER_CHANNEL_PER_TOKEN'#
- INT8 = 'INT8'#
- MIXED_PRECISION = 'MIXED_PRECISION'#
- NO_QUANT = 'NO_QUANT'#
- NVFP4 = 'NVFP4'#
- W4A16 = 'W4A16'#
- W4A16_AWQ = 'W4A16_AWQ'#
- W4A16_GPTQ = 'W4A16_GPTQ'#
- W4A8_AWQ = 'W4A8_AWQ'#
- W4A8_QSERVE_PER_CHANNEL = 'W4A8_QSERVE_PER_CHANNEL'#
- W4A8_QSERVE_PER_GROUP = 'W4A8_QSERVE_PER_GROUP'#
- W8A16 = 'W8A16'#
- W8A16_GPTQ = 'W8A16_GPTQ'#
- W8A8_SQ_PER_CHANNEL = 'W8A8_SQ_PER_CHANNEL'#
- W8A8_SQ_PER_CHANNEL_PER_TENSOR_PLUGIN = 'W8A8_SQ_PER_CHANNEL_PER_TENSOR_PLUGIN'#
- W8A8_SQ_PER_CHANNEL_PER_TOKEN_PLUGIN = 'W8A8_SQ_PER_CHANNEL_PER_TOKEN_PLUGIN'#
- W8A8_SQ_PER_TENSOR_PER_TOKEN_PLUGIN = 'W8A8_SQ_PER_TENSOR_PER_TOKEN_PLUGIN'#
- W8A8_SQ_PER_TENSOR_PLUGIN = 'W8A8_SQ_PER_TENSOR_PLUGIN'#
- class tensorrt_llm.llmapi.CalibConfig(
- *,
- device: Literal['cuda', 'cpu'] = 'cuda',
- calib_dataset: str = 'cnn_dailymail',
- calib_batches: int = 512,
- calib_batch_size: int = 1,
- calib_max_seq_length: int = 512,
- random_seed: int = 1234,
- tokenizer_max_seq_length: int = 2048,
基类:
BaseModel
校准配置。
- field calib_batch_size: int = 1#
校准运行的批次大小。
- field calib_batches: int = 512#
校准运行的批次数。
- field calib_dataset: str = 'cnn_dailymail'#
校准数据集的名称或本地路径。
- field calib_max_seq_length: int = 512#
校准运行的最大序列长度。
- field device: Literal['cuda', 'cpu'] = 'cuda'#
运行校准的设备。
- classmethod from_dict(
- config: dict,
从字典创建一个 CalibConfig 实例。
- 参数:
config (dict) – 用于创建 CalibConfig 的字典。
- 返回值:
从字典创建的 CalibConfig。
- 返回类型:
- model_config: ClassVar[ConfigDict] = {}#
模型的配置,应该是一个符合 [ConfigDict][pydantic.config.ConfigDict] 的字典。
- field random_seed: int = 1234#
用于校准的随机种子。
- field tokenizer_max_seq_length: int = 2048#
初始化 tokenizer 以进行校准的最大序列长度。
- class tensorrt_llm.llmapi.BuildCacheConfig(
- cache_root: Path | None = None,
- max_records: int = 10,
- max_cache_storage_gb: float = 256,
基类:
object
构建缓存的配置。
- cache_root#
构建缓存的根目录。
- 类型:
str
- max_records#
缓存中存储的最大记录数。
- 类型:
int
- max_cache_storage_gb#
用于缓存的最大存储量(以 GB 为单位)。
- 类型:
浮点数
注意
构建缓存假定模型的权重在执行过程中不会更改。如果权重已更改,则应手动删除缓存。
- __init__(
- cache_root: Path | None = None,
- max_records: int = 10,
- max_cache_storage_gb: float = 256,
- property cache_root: Path#
- property max_cache_storage_gb: float#
- property max_records: int#
- class tensorrt_llm.llmapi.MpiCommSession(comm=None, n_workers: int = 1)[source]#
基类:
MpiSession
- class tensorrt_llm.llmapi.ExtendedRuntimePerfKnobConfig(
- *,
- multi_block_mode: bool = True,
- enable_context_fmha_fp32_acc: bool = False,
- cuda_graph_mode: bool = False,
- cuda_graph_cache_size: int = 0,
Bases:
BaseModel
,PybindMirror
扩展运行时性能旋钮的配置。
- field cuda_graph_cache_size: int = 0#
运行时缓存的 CUDA 图的数量。缓存越大,性能越好,但消耗的 GPU 内存越多。
- field cuda_graph_mode: bool = False#
是否使用 CUDA 图模式。
- field enable_context_fmha_fp32_acc: bool = False#
是否启用上下文 FMHA FP32 累积。
- model_config: ClassVar[ConfigDict] = {}#
模型的配置,应该是一个符合 [ConfigDict][pydantic.config.ConfigDict] 的字典。
- field multi_block_mode: bool = True#
是否使用多块模式。
- class tensorrt_llm.llmapi.BatchingType(
- 值,
- names=<未给定>,
- *值,
- 模块=None,
- 限定名=None,
- 类型=None,
- 开始=1,
- 边界=None,
基类:
StrEnum
- INFLIGHT = 'INFLIGHT'#
- STATIC = 'STATIC'#
- class tensorrt_llm.llmapi.ContextChunkingPolicy(
- 值,
- names=<未给定>,
- *值,
- 模块=None,
- 限定名=None,
- 类型=None,
- 开始=1,
- 边界=None,
基类:
StrEnum
上下文分块策略。
- EQUAL_PROGRESS = 'EQUAL_PROGRESS'#
- FIRST_COME_FIRST_SERVED = 'FIRST_COME_FIRST_SERVED'#
- class tensorrt_llm.llmapi.DynamicBatchConfig(
- *,
- enable_batch_size_tuning: bool,
- enable_max_num_tokens_tuning: bool,
- dynamic_batch_moving_average_window: int,
Bases:
BaseModel
,PybindMirror
动态批处理配置。
控制在运行时如何动态调整批处理大小和令牌限制。
- field dynamic_batch_moving_average_window: int [Required]#
用于计算动态批处理大小和最大令牌数的输入和输出长度的移动平均窗口大小
- field enable_batch_size_tuning: bool [Required]#
控制是否应动态调整批处理大小
- field enable_max_num_tokens_tuning: bool [Required]#
控制是否应动态调整最大令牌数
- model_config: ClassVar[ConfigDict] = {}#
模型的配置,应该是一个符合 [ConfigDict][pydantic.config.ConfigDict] 的字典。