Files
FastDeploy/docs/zh/parameters.md
kevin 8aab4e367f [Feature] mm support prefix cache (#4134)
* support mm prefix caching

* update code

* fix mm_hashes

* support encoder cache

* add encoder cache

* update code

* update encoder cache

* fix features bug

* fix worker bug

* support processor cache, need to optimize yet

* refactor multimodal data cache

* update code

* update code

* update v1 scheduler

* update code

* update code

* update codestyle

* support turn off processor cache and encoder cache

* update pre-commit

* fix code

* solve review

* update code

* update code

* update test case

* set processor cache in GiB

* update test case

* support mm prefix caching for qwen model

* fix code style check

* update pre-commit

* fix unit test

* fix unit test

* add ci test case

* fix rescheduled bug

* change text_after_process to prompt_tokens

* fix unit test

* fix chat template

* change model path

* [EP] fix adapter bugs (#4572)

* Update expert_service.py

* Update common_engine.py

* Update expert_service.py

* fix v1 hang bug (#4573)

* fix import image_ops error on some platforms (#4559)

* [CLI]Update parameters in bench latecy cli tool and fix collect-env cli tool (#4558)

* add collect-env

* del files

* [Graph Optimization] Add dy_runnable and introduce cudagraph_switch_threshold for cudagraph mode switching (#4578)

* add new branch for sot

* reorder

* fix batch bug

* [XPU]Moe uses a new operator (#4585)

* [XPU]Moe uses a new operator

* [XPU]Moe uses a new operator

* update response

* [Feature] Support Paddle-OCR (#4396)

* init

* update code

* fix code style & disable thinking

* adapt for common_engine.update_mm_requests_chunk_size

* use 3d rope

* use flash_attn_unpadded

* opt siglip

* update to be compatible with the latest codebase

* fix typo

* optim OCR performance

* fix bug

* fix bug

* fix bug

* fix bug

* normlize name

* modify xpu rope

* revert logger

* fix bug

* fix bug

* fix bug

* support default_v1

* optim performance

* fix bug

---------

Co-authored-by: root <root@szzj-acg-tge1-fdda9.szzj.baidu.com>
Co-authored-by: zhangyue66 <zhangyue66@baidu.com>

* [DataProcessor] add reasoning_tokens into usage info (#4520)

* add reasoning_tokens into usage info initial commit

* add unit tests

* modify unit test

* modify and add unit tests

* fix unit test

* move steam usage to processor

* modify processor

* modify test_logprobs

* modify test_logprobs.py

* modify stream reasoning tokens accumulation

* fix unit test

* perf: Optimize task queue communication from engine to worker (#4531)

* perf: Optimize task queue communication from engine to worker

* perf: get_tasks to numpy

* perf: get_tasks remove to_numpy

* fix: request & replace ENV

* remove test_e2w_perf.py

* fix code style

---------

Co-authored-by: Jiang-Jia-Jun <163579578+Jiang-Jia-Jun@users.noreply.github.com>

* Clean up ports after processing results (#4587)

* [CI] Add /re-run command in PR comments to restart failed CI workflows (#4593)

* [Others] api server exits when worker process is dead (#3271)

* [fix] fix terminal hangs when worker process is dead

* [chore] change sleep time of monitor

* [chore] remove redundant comments

* update docs

---------

Co-authored-by: ApplEOFDiscord <wwy640130@163.com>
Co-authored-by: ApplEOFDiscord <31272106+ApplEOFDiscord@users.noreply.github.com>
Co-authored-by: ltd0924 <32387785+ltd0924@users.noreply.github.com>
Co-authored-by: yinwei <yinwei_hust@163.com>
Co-authored-by: JYChen <zoooo0820@qq.com>
Co-authored-by: qwes5s5 <45442318+qwes5s5@users.noreply.github.com>
Co-authored-by: Ryan <zihaohuang@aliyun.com>
Co-authored-by: yyssys <atyangshuang@foxmail.com>
Co-authored-by: ming1753 <61511741+ming1753@users.noreply.github.com>
Co-authored-by: root <root@szzj-acg-tge1-fdda9.szzj.baidu.com>
Co-authored-by: zhangyue66 <zhangyue66@baidu.com>
Co-authored-by: kxz2002 <115912648+kxz2002@users.noreply.github.com>
Co-authored-by: SunLei <sunlei5788@gmail.com>
Co-authored-by: Jiang-Jia-Jun <163579578+Jiang-Jia-Jun@users.noreply.github.com>
Co-authored-by: Zhang Yulong <35552275+ZhangYulongg@users.noreply.github.com>
Co-authored-by: YuBaoku <49938469+EmmonsCurse@users.noreply.github.com>
Co-authored-by: 李泳桦 <39643373+liyonghua0910@users.noreply.github.com>
2025-10-27 17:39:51 +08:00

10 KiB
Raw Blame History

English

FastDeploy参数说明

在使用FastDeploy部署模型包括离线推理、服务化部署涉及如下参数配置其实需要注意在使用离线推理时各参数配置即为如下参数名而在使用命令行启动服务时相应参数中的分隔符需要从_修改为-,如max_model_len在命令行中则为--max-model-len

参数名 类型 说明
port int 仅服务化部署需配置服务HTTP请求端口号默认8000
metrics_port int 仅服务化部署需配置服务监控Metrics端口号默认8001
max_waiting_time int 仅服务化部署需配置,服务请求建立连接最大等待时间,默认-1 表示无等待时间限制
max_concurrency int 仅服务化部署需配置服务实际建立连接数目默认512
engine_worker_queue_port int FastDeploy内部引擎进程通信端口, 默认8002
cache_queue_port int FastDeploy内部KVCache进程通信端口, 默认8003
max_model_len int 推理默认最大支持上下文长度默认2048
tensor_parallel_size int 模型默认张量并行数默认1
data_parallel_size int 模型默认数据并行数默认1
block_size int KVCache管理粒度(Token数)推荐默认值64
max_num_seqs int Decode阶段最大的并发数默认为8
mm_processor_kwargs dict[str] 多模态处理器参数配置,如:{"image_min_pixels": 3136, "video_fps": 2}
tokenizer str tokenizer 名或路径,默认为模型路径
use_warmup int 是否在启动时进行warmup会自动生成极限长度数据进行warmup默认自动计算KV Cache时会使用
limit_mm_per_prompt dict[str] 限制每个prompt中多模态数据的数量{"image": 10, "video": 3}默认都为1
enable_mm bool [已废弃] 是否支持多模态数据仅针对多模模型默认False
quantization str 模型量化策略当在加载BF16 CKPT时指定wint4或wint8时支持无损在线4bit/8bit量化
gpu_memory_utilization float GPU显存利用率默认0.9
num_gpu_blocks_override int 预分配KVCache块数此参数可由FastDeploy自动根据显存情况计算无需用户配置默认为None
max_num_batched_tokens int Prefill阶段最大Batch的Token数量默认为None(与max_model_len一致)
kv_cache_ratio float KVCache块按kv_cache_ratio比例分给Prefill阶段和Decode阶段, 默认0.75
enable_prefix_caching bool 是否开启Prefix Caching默认False
swap_space float 开启Prefix Caching时用于swap KVCache的CPU内存大小单位GB默认None
enable_chunked_prefill bool 开启Chunked Prefill默认False
max_num_partial_prefills int 开启Chunked Prefill时Prefill阶段的最大并发数默认1
max_long_partial_prefills int 开启Chunked Prefill时Prefill阶段并发中包启的最多长请求数默认1
long_prefill_token_threshold int 开启Chunked Prefill时请求Token数超过此值的请求被视为长请求默认为max_model_len*0.04
static_decode_blocks int 推理过程中每条请求强制从Prefill的KVCache分配对应块数给Decode使用默认2
reasoning_parser str 指定要使用的推理解析器,以便从模型输出中提取推理内容
use_cudagraph bool [已废弃] 2.3版本开始 CUDAGraph 默认开启,详细说明参考 graph_optimization.md
graph_optimization_config dict[str] 可以配置计算图优化相关的参数,默认值为'{"use_cudagraph":true, "graph_opt_level":0}',详细说明参考 graph_optimization.md
disable_custom_all_reduce bool 关闭Custom all-reduce默认False
splitwise_role str 是否开启splitwise推理默认值mixed 支持参数为["mixed", "decode", "prefill"]
innode_prefill_ports str prefill 实例内部引擎启动端口 仅单机PD分离需要默认值None
guided_decoding_backend str 指定要使用的guided decoding后端支持 autoxgrammaroff, 默认为 off
guided_decoding_disable_any_whitespace bool guided decoding期间是否禁止生成空格默认False
speculative_config dict[str] 投机解码配置仅支持标准格式json字符串默认为None
dynamic_load_weight int 是否动态加载权重默认0
enable_expert_parallel bool 是否启用专家并行
enable_logprob bool 是否启用输出token返回logprob。如果未使用 logrpob则在启动时可以省略此参数。
logprobs_mode str 指定logprobs中返回的内容。支持的模式raw_logprobsprocessed_logprobs'、raw_logits,processed_logits'。processed表示logits应用温度、惩罚、禁止词处理后计算的logprobs。
served_model_name str API 中使用的模型名称,如果未指定,模型名称将与--model参数相同
revision str 自动下载模型时用于指定模型的Git版本分支名或tag
chat_template str 指定模型拼接使用的模板支持字符串与文件路径默认为None如未指定则使用模型默认模板
tool_call_parser str 指定要使用的function call解析器以便从模型输出中抽取 function call内容
tool_parser_plugin str 指定要注册的tool parser文件路径以便注册不在代码库中的parserparser中代码格式需遵循代码库中格式
load_choices str 默认使用"default" loader进行权重加载加载torch权重/权重加速需开启 "default_v1"
max_encoder_cache int 编码器缓存的最大token数使用0表示禁用
max_processor_cache int 处理器缓存的最大字节数以GiB为单位使用0表示禁用

1. KVCache分配与num_gpu_blocks_overrideblock_size的关系?

FastDeploy在推理过程中显存被模型权重预分配KVCache块模型计算中间激活值占用。其中预分配KVCache块由num_gpu_blocks_override决定,其单位为block_size(默认64即一个块可以存储64个Token的KVCache。

在实际推理中,用户很难知道num_gpu_blocks_override到底该配置到多少合适因此FastDeploy采用如下方式来自动推导并配置这个值流程如下:

  • 加载模型,在完成模型加载后,记录当前显存占用情况total_memory_after_load和FastDeploy框架占用的显存值fd_memory_after_load; 注意前者为GPU实际被占用显存可能有其它进程也占用后者是FD框架本身占用显存

  • 根据用户配置的max_num_batched_tokens(默认为max_model_len)Fake相应长度的输入数据进行Prefill计算记录当前FastDeploy框架显存最大分配值fd_memory_after_prefill,因此可以认为模型计算中间激活值fd_memory_after_prefill - fd_memory_after_load;

    • 截止当前认为GPU卡可以剩分配KVCache的显存(以A800 80G为例)为80GB * gpu_memory_utilization - total_memory_after_load - (fd_memory_after_prefill - fd_memory_after_load)
    • 根据模型KVCache的精度如8bit/16bit)计算一个block占用的KVCache大小从而计算出总共可分配的block数量赋值给num_gpu_blocks_override

在服务启动日志中我们可以在log/fastdeploy.log中找到Reset block num, the total_block_num:17220, prefill_kvcache_block_num:12915,其中total_block_num即为自动计算出来的KVCache block数量将其乘以block_size即可知道整个服务可以缓存多少Token的KV值。

2. kv_cache_ratioblock_sizemax_num_seqs的关系?

  • FastDeploy里面将KVCache按照kv_cache_ratio分为Prefill阶段使用和Decode阶段使用在配置这个参数时可以按照kv_cache_ratio = 平均输入Token数/(平均输入+平均输出Token数)进行配置常规情况输入是输出的3倍因此可以配置成0.75
  • max_num_seqs是Decode阶段的最大并发数一般而言可以配置成最大值128但用户也可以根据KVCache情况作调用例如输出的KVCache Token量为decode_token_cache = total_block_num * (1 - kv_cache_ratio) * block_size,为了防止极端情况下的显存不足问题,可以配置max_num_seqs = decode_token_cache / 平均输出Token数不高于128即可。

3. enable_chunked_prefill参数配置说明

当启用 enable_chunked_prefill服务通过动态分块处理长输入序列显著提升GPU资源利用率。在此模式下原有 max_num_batched_tokens 参数不再约束预填充阶段的批处理token数量限制单次prefill的token数量因此引入 max_num_partial_prefills 参数,专门用于限制同时处理的分块批次数。

为优化短请求的调度优先级,新增 max_long_partial_prefillslong_prefill_token_threshold 参数组合。前者限制单个预填充批次中的长请求数量后者定义长请求的token阈值。系统会优先保障短请求的批处理空间从而在混合负载场景下降低短请求延迟同时保持整体吞吐稳定。