Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
321 commits
Select commit Hold shift + click to select a range
6fa8f74
add assert none
shihaobai Feb 9, 2026
bf83078
set_unique_server_name
shihaobai Feb 10, 2026
3eab5a7
fix return_routed_experts
sufubao Feb 10, 2026
14cfc95
fix r3
sufubao Feb 10, 2026
e8ed8b5
add-neo++
Feb 12, 2026
77b73c2
feat: add Qwen3Next linear attention model support
sufubao Feb 19, 2026
a4ab210
refactor: simplify mamba buffer copy and integrate Triton kernels
sufubao Feb 20, 2026
1686d34
fix conv3d
sufubao Feb 21, 2026
dd9b611
[draft] qwen3.5 dense
sufubao Feb 26, 2026
6a3a17c
split dense and moe
sufubao Feb 26, 2026
e1cdfb4
feat: add mamba_cache_ratio for automatic memory allocation
sufubao Feb 26, 2026
f2e148e
refactor: simplify mamba_cache_ratio to direct percentage
sufubao Feb 26, 2026
b4fe201
add H100 config
sufubao Feb 26, 2026
e2ce9c0
refactor: align radix_cache_class with infer_state_class style
sufubao Feb 27, 2026
b1adbf3
fix: add missing attention_chunk param to flashattention_nopad.py
sufubao Feb 27, 2026
c744ebd
refactor: clarify naming in mamba_buffer_copy
sufubao Feb 27, 2026
9def697
clean
sufubao Feb 27, 2026
2b3deb8
fix
sufubao Feb 27, 2026
61f8945
clean
sufubao Feb 27, 2026
f7280a3
split
sufubao Feb 27, 2026
86d3bfb
Merge origin/qwen3.5_clean into rl_verl_qwen35
sufubao Feb 28, 2026
c05838e
fix: lazy-initialize SHM name constants to avoid import-time crash
sufubao Feb 28, 2026
243c6a0
fix: revert weight slicing and rmsnorm precision regressions
sufubao Feb 28, 2026
711e30c
fix
sufubao Feb 28, 2026
7734c21
feat: add Qwen3Next linear attention model support
sufubao Feb 19, 2026
c757b06
refactor: simplify mamba buffer copy and integrate Triton kernels
sufubao Feb 20, 2026
340d11c
fix conv3d
sufubao Feb 21, 2026
a6a2435
[draft] qwen3.5 dense
sufubao Feb 26, 2026
054035d
split dense and moe
sufubao Feb 26, 2026
01b112a
feat: add mamba_cache_ratio for automatic memory allocation
sufubao Feb 26, 2026
174757d
refactor: simplify mamba_cache_ratio to direct percentage
sufubao Feb 26, 2026
dd2516e
add H100 config
sufubao Feb 26, 2026
326ae22
refactor: align radix_cache_class with infer_state_class style
sufubao Feb 27, 2026
e996cd2
fix: add missing attention_chunk param to flashattention_nopad.py
sufubao Feb 27, 2026
5e5cdbe
refactor: clarify naming in mamba_buffer_copy
sufubao Feb 27, 2026
9cf783c
clean
sufubao Feb 27, 2026
e120edb
fix
sufubao Feb 27, 2026
f3330cf
clean
sufubao Feb 27, 2026
d030a67
split
sufubao Feb 27, 2026
e1f6129
style: apply black formatting to mamba_buffer_copy
sufubao Mar 1, 2026
74f82d1
perf: add autotune configs for mamba_buffer_copy/fork kernels on H200
sufubao Mar 1, 2026
c1ea769
refactor: rename buffer copy methods for clarity
sufubao Mar 2, 2026
b81baaa
clean the code
sufubao Mar 2, 2026
52b422a
vlm tokenizer support token list
shihaobai Mar 2, 2026
aa442a4
fix
shihaobai Mar 2, 2026
0fd0202
clean code
sufubao Mar 2, 2026
eed0a9c
qwen35 qkv improve
shihaobai Mar 6, 2026
b9a386e
code simplify
shihaobai Mar 9, 2026
86f17b6
clean code
shihaobai Mar 9, 2026
a1849e6
fix
shihaobai Mar 13, 2026
61f74ac
remove contiguous
shihaobai Mar 16, 2026
bf0f254
remove gemma rms norm config
shihaobai Mar 16, 2026
76782c2
clean code
sufubao Mar 17, 2026
fdd2052
add get_radix_class
sufubao Mar 17, 2026
733e851
fix acc of mamba cache
shihaobai Mar 17, 2026
b1f8233
fix acc of mamba cache
shihaobai Mar 17, 2026
90120b0
fix warmup
shihaobai Mar 17, 2026
4ef6091
merge main
shihaobai Mar 18, 2026
13edba2
simplify the qwen3next layer_infer
shihaobai Mar 18, 2026
ec499ce
openai api simplify
shihaobai Mar 18, 2026
3c8597d
simplify mem manager
shihaobai Mar 18, 2026
20edcc1
slime code
shihaobai Mar 19, 2026
eed9863
remove mtp of base_backend
shihaobai Mar 19, 2026
90df4f1
slime mode_backend
shihaobai Mar 19, 2026
3b832af
merge qwen3.5 and main
shihaobai Mar 19, 2026
91edf3b
fix invalid memory of release_memory
shihaobai Mar 19, 2026
711667a
flush_cache for hybrid cache
shihaobai Mar 19, 2026
b181c0a
fix rpyc
shihaobai Mar 19, 2026
c6a6dda
fix: node is None
sufubao Mar 20, 2026
ee3a7d5
fix resume invalid memory
shihaobai Mar 20, 2026
32d795d
fix reqs queue
shihaobai Mar 20, 2026
a0937a9
fix
shihaobai Mar 20, 2026
1de0e53
fix
shihaobai Mar 20, 2026
2dbd2f7
pop weight after load
shihaobai Mar 20, 2026
33bbfda
async update weight
shihaobai Mar 20, 2026
6017484
model.norm.weight: add 1 during runtime
shihaobai Mar 23, 2026
b98f6d7
fix r3
sufubao Mar 23, 2026
c0cebba
fix qwen35 nrom
sufubao Mar 23, 2026
5f4fa78
Revert "fix qwen35 nrom"
sufubao Mar 23, 2026
64506b3
fix
shihaobai Mar 23, 2026
9da13c1
Merge branch 'qwen3.5_clean' of https://github.com/ModelTC/lightllm i…
shihaobai Mar 23, 2026
73b10ca
remove unused log
shihaobai Mar 23, 2026
1d46601
Merge branch 'rl_verl_qwen35' of https://github.com/ModelTC/lightllm …
shihaobai Mar 23, 2026
b2ab0bf
Merge remote-tracking branch 'origin/main' into qwen3.5_clean
sufubao Mar 23, 2026
a93509f
fix mamba_len
shihaobai Mar 23, 2026
1115543
fix
sufubao Mar 23, 2026
d562b7b
fix
sufubao Mar 23, 2026
8f11f08
fix and remove unused code
shihaobai Mar 23, 2026
709075a
Merge branch 'qwen3.5_clean' of https://github.com/ModelTC/lightllm i…
shihaobai Mar 23, 2026
267412d
fix format
shihaobai Mar 23, 2026
f7bee08
gatermsnorm weight and mamba profile_size
shihaobai Mar 23, 2026
b85b6ca
simpliy code
shihaobai Mar 24, 2026
3965845
update tp param
shihaobai Mar 24, 2026
ef41d77
fix: restore tool_calls arguments JSON string to dict conversion
sufubao Mar 24, 2026
7d0458f
fix: restore tool_calls arguments JSON string to dict conversion
sufubao Mar 24, 2026
8f1212a
fix build_prompt too
sufubao Mar 25, 2026
77bfcba
fix
sufubao Mar 25, 2026
3585432
fix buffer idx
shihaobai Mar 26, 2026
334e3c4
fix
shihaobai Mar 26, 2026
2f34bac
merge the update of qwen3.5_clean
shihaobai Mar 26, 2026
0974ba9
fix
shihaobai Mar 27, 2026
fe91aa3
add instance_id with improved robustness and code quality
sufubao Mar 31, 2026
f4a0cb7
fix: occasional accuracy drop in rollout
shihaobai Apr 1, 2026
f4caa8f
reset req manager
shihaobai Apr 1, 2026
8794f43
fix typo
shihaobai Apr 2, 2026
1abf95a
add fp8 rl for qwen35
shihaobai Apr 10, 2026
901bd13
fix abort
shihaobai Apr 15, 2026
8de8baf
add logs for detoken
shihaobai Apr 16, 2026
2dc39fa
fix decode overflow
shihaobai Apr 17, 2026
8c20369
fix bytes decode
shihaobai Apr 18, 2026
6cd300c
merge main
shihaobai May 8, 2026
1f466c7
remove neo
shihaobai May 8, 2026
9e54f20
remove unused code
shihaobai May 8, 2026
46d2ee2
remove unused code
shihaobai May 8, 2026
f2c1a3e
remove unused code
shihaobai May 8, 2026
e7c1475
slime code
shihaobai May 8, 2026
1ecf015
slim code
shihaobai May 8, 2026
a93dcb6
slime code
shihaobai May 9, 2026
ccc8832
slime radix cache
shihaobai May 9, 2026
11ea37a
slime radixcache
shihaobai May 9, 2026
f446e5b
slim code
shihaobai May 9, 2026
998020a
remove unused code
shihaobai May 9, 2026
5a745e5
fix
shihaobai May 9, 2026
90ed556
lazy init cache dir
shihaobai May 9, 2026
eb42e5b
fix linear flush_cache
shihaobai May 9, 2026
ccf7d91
feat: new rl update weight support
yqyao May 11, 2026
3e1ac50
fix abort request
shihaobai May 11, 2026
24028a1
memory tag normalizew
shihaobai May 11, 2026
5f5d263
fix
shihaobai May 11, 2026
81bf00a
Merge remote-tracking branch 'origin/main' into rl_verl_rebase_main
shihaobai May 11, 2026
8461bd8
fix
shihaobai May 11, 2026
641ef6e
rpyc rl
shihaobai May 11, 2026
d26e822
fix
shihaobai May 12, 2026
a6b5cbc
fix
shihaobai May 12, 2026
b48eb36
fix visual server infer name
shihaobai May 12, 2026
cbec63c
list kv cache
shihaobai May 12, 2026
9d64e33
fix
shihaobai May 12, 2026
ffdd879
add test
shihaobai May 12, 2026
31d3584
R3 auto dtype
shihaobai May 18, 2026
5812070
fix
shihaobai May 25, 2026
72e0bc5
Merge remote-tracking branch 'origin/main' into rl_verl_rebase_main
shihaobai May 25, 2026
e00721f
mm_slicer: assert weight ndim in {2, 3} and fix shape[1] residue
shihaobai May 25, 2026
47e313f
revert detokenization/manager.py to main; add weight verify_load; twe…
shihaobai May 25, 2026
7e1b737
inline _handle_token_output back into handle_loop
shihaobai May 25, 2026
542254b
revert multi_level_kv_cache/manager.py to main
shihaobai May 25, 2026
2f99b73
remove MTP buffer copy-back in dp_backend impl
shihaobai May 25, 2026
b737d2a
multinode tp: sync abort via router broadcast, drop httpserver zmq fo…
shihaobai May 26, 2026
a79fdd7
fix abort && R3 overlap
shihaobai May 26, 2026
2399900
fix
shihaobai May 26, 2026
361b548
sync abort
shihaobai May 27, 2026
df7963b
remove verify load
shihaobai May 27, 2026
7c94bbd
fix multimodal encode
shihaobai May 27, 2026
031a225
fix
shihaobai May 27, 2026
591b9f7
add reject_all for pause_generation
shihaobai Jun 1, 2026
b0e2ec7
fix pause generation
shihaobai Jun 2, 2026
2ca3e47
fix pause generation
shihaobai Jun 2, 2026
a5c0074
fix pause
shihaobai Jun 2, 2026
e336d82
bugfix: fix auto ipc handle
yqyao Jun 10, 2026
d200bdd
fix
hiworldwzj Jun 17, 2026
69df89e
merge main
shihaobai Jun 17, 2026
064a6f2
fix
hiworldwzj Jun 17, 2026
1d950e0
fix
hiworldwzj Jun 17, 2026
eb994d0
fix
hiworldwzj Jun 17, 2026
9319da1
fix
hiworldwzj Jun 17, 2026
68a62eb
fix
hiworldwzj Jun 17, 2026
81d5c9b
fix
hiworldwzj Jun 17, 2026
301fe73
fix
hiworldwzj Jun 17, 2026
681663d
fix
hiworldwzj Jun 17, 2026
a3d13f6
fix
hiworldwzj Jun 17, 2026
b9c1448
Add MoE routing capture callback path
shihaobai Jun 17, 2026
549eba3
simplify rpyc
shihaobai Jun 18, 2026
8a75d3a
fix test & enable_cpu_weight_backup
shihaobai Jun 20, 2026
26c719a
simplify the modification of models
shihaobai Jun 20, 2026
2baf34f
rl utils
shihaobai Jun 20, 2026
8b31221
simplify req_queue
shihaobai Jun 20, 2026
bdf22b8
update abort_all
shihaobai Jun 20, 2026
5f28e4a
simplify basemodel and net utils
shihaobai Jun 21, 2026
1e6a149
simplify r3
shihaobai Jun 21, 2026
8bfc08f
update test
shihaobai Jun 22, 2026
b748265
add start_parent_check_thread on visualserver modelinfer
shihaobai Jun 22, 2026
535fc6f
fix abort
shihaobai Jun 24, 2026
449365c
fix abort
shihaobai Jun 24, 2026
a7db0e2
support logprobs api
sufubao Jul 7, 2026
fccbc5e
Fix stale pending admission cleanup on cancelled requests
shihaobai Jul 9, 2026
050ded2
Merge branch 'rl_verl_rebase_main' of https://github.com/ModelTC/ligh…
shihaobai Jul 9, 2026
88c05f0
fix(routing): guard MTP draft capture and align routed_experts length…
sufubao Jul 9, 2026
d693a42
fix r3 and prompt logprob
shihaobai Jul 10, 2026
a37bc9a
merge
shihaobai Jul 10, 2026
b1598bc
refactor: centralize startup port allocation and release management
shihaobai Jul 11, 2026
8e6cc9c
update the test_r3 api
shihaobai Jul 12, 2026
24f33f3
merge main
shihaobai Jul 12, 2026
72630f6
fix
hiworldwzj Jul 13, 2026
30f8824
add token metadate to simplify req.py
shihaobai Jul 13, 2026
023fdff
add split weight for rl update weight
shihaobai Jul 13, 2026
163c8ce
Move routing capture callback creation into manager
shihaobai Jul 13, 2026
b6d6ad2
Update metadata tests and memory saver comments
shihaobai Jul 13, 2026
58df9d7
fix port manager
hiworldwzj Jul 14, 2026
b1d2d82
fix
hiworldwzj Jul 14, 2026
8d88105
fix
hiworldwzj Jul 14, 2026
c08581b
Treat abort as normal finish in http wait loop
shihaobai Jul 14, 2026
55be3bc
Merge branch 'rl_verl_rebase_main' of https://github.com/ModelTC/ligh…
shihaobai Jul 14, 2026
9cc0009
fix
hiworldwzj Jul 15, 2026
1a99e89
fix tab
hiworldwzj Jul 15, 2026
19bc6c1
fix routed_moe_manager
hiworldwzj Jul 15, 2026
c8dab33
fix abort stuck
shihaobai Jul 15, 2026
f55ba5d
Merge branch 'rl_verl_rebase_main' of https://github.com/ModelTC/ligh…
shihaobai Jul 15, 2026
d8dd577
fix logprobs_manager.py
hiworldwzj Jul 16, 2026
4407fb6
move moe router manager init
hiworldwzj Jul 16, 2026
a3d0eee
fix
hiworldwzj Jul 16, 2026
cebe8ee
feat: make image resizing opt-in
shihaobai Jul 16, 2026
455eac2
fix ReqFinalTokenMetadata
hiworldwzj Jul 16, 2026
99f2775
fix line
hiworldwzj Jul 17, 2026
0cdddbb
remove dead code
hiworldwzj Jul 17, 2026
ac74ec1
fix start args
hiworldwzj Jul 17, 2026
5655f44
remove moe routed manager in httpserver
hiworldwzj Jul 17, 2026
e930f68
merge
hiworldwzj Jul 17, 2026
97abf15
fix
hiworldwzj Jul 17, 2026
fc6bc28
fix verify
hiworldwzj Jul 17, 2026
6af742f
add verify_resource_limits
hiworldwzj Jul 17, 2026
c490aa6
move abort_request
hiworldwzj Jul 17, 2026
4f524ea
fix rl_controler
hiworldwzj Jul 17, 2026
f7f1094
add comment
hiworldwzj Jul 17, 2026
29a1f5f
fix return prompt_logics
hiworldwzj Jul 19, 2026
bbc69ba
fix
hiworldwzj Jul 19, 2026
2e2ddd1
fix cpu cache
hiworldwzj Jul 20, 2026
9dc2831
fix _filter
hiworldwzj Jul 20, 2026
5572155
fix infer_req
hiworldwzj Jul 20, 2026
289f42d
add FinalTokenMetadataExt
hiworldwzj Jul 20, 2026
e6cd5d4
fix PromptSelectedLogprobsExt
hiworldwzj Jul 20, 2026
0ae9bdb
fix rl controler
hiworldwzj Jul 20, 2026
8ca41a9
fix rl router code
hiworldwzj Jul 20, 2026
bb14e01
fix aborted
hiworldwzj Jul 20, 2026
f990a5f
fix multinode_tp router
hiworldwzj Jul 20, 2026
67c41d8
fix
hiworldwzj Jul 20, 2026
05f418c
fix
hiworldwzj Jul 20, 2026
c0d1f5e
remove lightllm instance id
hiworldwzj Jul 21, 2026
c0c2799
fix enable_rl
hiworldwzj Jul 21, 2026
ebb9a6d
fix next_token_ranks_cpu
hiworldwzj Jul 21, 2026
39e2f9d
remove start arg unused
hiworldwzj Jul 21, 2026
1020e65
fix get_const_gpu_tensor
hiworldwzj Jul 21, 2026
804b62a
resize image fix
hiworldwzj Jul 21, 2026
656a503
fix
hiworldwzj Jul 21, 2026
c2f6e1b
add disable_image_resize
hiworldwzj Jul 21, 2026
f49debc
add comment
hiworldwzj Jul 21, 2026
951ce69
fix wait_until_final_token_metadata_ready
hiworldwzj Jul 21, 2026
c9127e7
fix aborted
hiworldwzj Jul 21, 2026
4342ad1
fix all
hiworldwzj Jul 21, 2026
26a3907
fix
hiworldwzj Jul 21, 2026
b090c32
fix
hiworldwzj Jul 21, 2026
b0ca8a4
fix multi tp stop str
hiworldwzj Jul 21, 2026
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 6 additions & 14 deletions docs/CN/source/tutorial/api_server_args.rst
Original file line number Diff line number Diff line change
Expand Up @@ -294,6 +294,10 @@ PD 分离模式参数

当输入图片超过该阈值时,LightLLM 会先自动将其缩放到该像素预算内,再继续后续流程。

.. option:: --disable_image_resize

禁用对超过 ``--max_image_pixels`` 的图片的自动缩放。默认开启自动缩放。

.. option:: --visual_infer_batch_size

每次推理批次中处理的图像数量,默认为 ``1``
Expand All @@ -310,10 +314,6 @@ PD 分离模式参数

ViT 的数据并行实例数量,默认为 ``1``

.. option:: --visual_nccl_ports

为 ViT 构建分布式环境的 NCCL 端口列表,例如 29500 29501 29502,默认为 [29500]

.. option:: --vit_att_backend

设置 ViT 使用的注意力后端。可选值为:
Expand Down Expand Up @@ -496,9 +496,9 @@ PD 分离模式参数
* ``triton``: 使用 torch 和 triton kernel(默认)
* ``sglang_kernel``: 使用 sglang_kernel 实现

.. option:: --return_all_prompt_logprobs
.. option:: --enable_prompt_logprobs

返回所有提示 token 的 logprobs
启用 prompt top-k logprobs 捕获

.. option:: --use_reward_model

Expand Down Expand Up @@ -549,14 +549,6 @@ DeepSeek 冗余专家参数
监控和日志参数
--------------

.. option:: --disable_log_stats

禁用吞吐量统计日志记录

.. option:: --log_stats_interval

记录统计信息的间隔(秒),默认为 ``10``

.. option:: --health_monitor

检查服务健康状态并在出错时重启
Expand Down
20 changes: 6 additions & 14 deletions docs/EN/source/tutorial/api_server_args.rst
Original file line number Diff line number Diff line change
Expand Up @@ -293,6 +293,10 @@ Multimodal Parameters

If an input image exceeds this threshold, LightLLM automatically resizes it down to this pixel budget before continuing.

.. option:: --disable_image_resize

Disable automatic resize for images exceeding ``--max_image_pixels``. Resize is enabled by default.

.. option:: --visual_infer_batch_size

Number of images processed in each inference batch, default is ``1``
Expand All @@ -309,10 +313,6 @@ Multimodal Parameters

Number of data parallel instances for ViT, default is ``1``

.. option:: --visual_nccl_ports

List of NCCL ports for ViT, e.g., 29500 29501 29502, default is [29500]

.. option:: --vit_att_backend

Set the attention backend for ViT. Available options:
Expand Down Expand Up @@ -497,9 +497,9 @@ Sampling and Generation Parameters
* ``triton``: Use torch and triton kernel (default)
* ``sglang_kernel``: Use sglang_kernel implementation

.. option:: --return_all_prompt_logprobs
.. option:: --enable_prompt_logprobs

Return logprobs for all prompt tokens
Enable prompt top-k logprobs capture

.. option:: --use_reward_model

Expand Down Expand Up @@ -550,14 +550,6 @@ DeepSeek Redundant Expert Parameters
Monitoring and Logging Parameters
---------------------------------

.. option:: --disable_log_stats

Disable throughput statistics logging

.. option:: --log_stats_interval

Interval for recording statistics (seconds), default is ``10``

.. option:: --health_monitor

Check service health status and restart on error
Expand Down
49 changes: 31 additions & 18 deletions lightllm/common/basemodel/basemodel.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,10 @@
)
from lightllm.common.triton_utils.autotuner import Autotuner
from lightllm.utils.infer_utils import post_empty_cache
from lightllm.utils.torch_memory_saver_utils import (
TorchMemorySaverWrapper,
MemoryTag,
)
from .attention import get_prefill_att_backend_class, get_decode_att_backend_class
from .attention import BaseAttBackend

Expand Down Expand Up @@ -93,6 +97,7 @@ def __init__(self, kvargs):
self.tp_world_size_ = get_dp_world_size()
self.enable_tpsp_mix_mode = get_env_start_args().enable_tpsp_mix_mode

self.torch_memory_saver = TorchMemorySaverWrapper(self.args.enable_torch_memory_saver)
self.is_mtp_mode = self.args.mtp_mode in [
"vanilla_with_att",
"eagle_with_att",
Expand All @@ -106,18 +111,21 @@ def __init__(self, kvargs):
self._verify_params()
self._init_quant()

self._init_weights()
self._init_req_manager()
self._init_mem_manager()
enable_weight_cpu_backup = self.args.enable_weight_cpu_backup
with self.torch_memory_saver.region(tag=MemoryTag.WEIGHT, enable_cpu_backup=enable_weight_cpu_backup):
self._init_weights()
with self.torch_memory_saver.region(tag=MemoryTag.KV_CACHE):
self._init_req_manager()
self._init_mem_manager()

# 因为类似 qwen3.5 的linear 架构的模型,其 req_manager 会存储运行时使用的大量 linear state
# 这可能会占用大量的显存,所以,req_manger 中保存的 mem_manger 是mem manager 初始化后再赋值
self.req_manager.mem_manager = self.mem_manager

self._check_mem_size()
self._init_infer_layer()
self._init_some_value()
self._init_custom()
self._load_hf_weights()
self.load_weights(self.weight_dict)

self._init_att_backend()
self._init_att_backend1()
Expand Down Expand Up @@ -176,13 +184,14 @@ def _init_weights(self, start_layer_index=0):
]
return

def _load_hf_weights(self):
def load_weights(self, weight_dict: dict):
assert weight_dict is None or isinstance(weight_dict, dict), "weight_dict must be a dict or None"
load_hf_weights(
self.data_type,
data_type=self.data_type,
weight_dir=self.weight_dir_,
pre_post_layer=self.pre_post_weight,
transformer_layer_list=self.trans_layers_weight,
weight_dict=self.weight_dict,
weight_dict=weight_dict,
)
self.pre_post_weight.verify_load()
[weight.verify_load() for weight in self.trans_layers_weight]
Expand Down Expand Up @@ -520,13 +529,13 @@ def _create_unpad_decode_model_output(self, model_output: ModelOutput, origin_ba
def _create_unpad_prefill_model_output(
self, padded_model_output: ModelOutput, origin_handle_token_num: int, origin_batch_size: int
):
if self.return_all_prompt_logics:
new_model_output = copy.copy(padded_model_output)
new_model_output.logits = new_model_output.logits[0:origin_handle_token_num]
else:
new_model_output = copy.copy(padded_model_output)
# 移除多余的pad 的那个 req 对应的 logics
new_model_output.logits = new_model_output.logits[0:origin_batch_size]
new_model_output = copy.copy(padded_model_output)
# logits 始终只对应每个请求最后一个位置,移除 padding 的 req 对应的行。
new_model_output.logits = new_model_output.logits[0:origin_batch_size]
# prompt_logics 保存整个 prefill 阶段所有 token 位置的 logits,
# 按实际处理的 token 数量裁剪掉 padding 部分(仅 return_all_prompt_logics 模式下非空)。
if new_model_output.prompt_logics is not None:
new_model_output.prompt_logics = new_model_output.prompt_logics[0:origin_handle_token_num]

# 特殊模型,特殊模式的特殊变量的特殊 unpad
if new_model_output.mtp_main_output_hiddens is not None:
Expand Down Expand Up @@ -701,7 +710,7 @@ def prefill_func(input_tensors, infer_state):
last_input_embs = infer_state._all_to_all_unbalance_get(data=last_input_embs)

predict_logits = self.post_infer.token_forward(last_input_embs, infer_state, self.pre_post_weight)
model_output = ModelOutput(logits=predict_logits)
model_output = ModelOutput(logits=predict_logits, prompt_logics=infer_state.prompt_logics)

# 特殊模型特殊模式的额外输出
if self.is_mtp_mode:
Expand Down Expand Up @@ -974,8 +983,8 @@ def _overlap_tpsp_context_forward(self, infer_state: InferStateInfo, infer_state
)
g_cache_manager.cache_env_out()

model_output = ModelOutput(logits=predict_logits.contiguous())
model_output1 = ModelOutput(logits=predict_logits1.contiguous())
model_output = ModelOutput(logits=predict_logits.contiguous(), prompt_logics=infer_state.prompt_logics)
model_output1 = ModelOutput(logits=predict_logits1.contiguous(), prompt_logics=infer_state1.prompt_logics)

if self.is_mtp_mode:
input_embs = self.pre_infer._tpsp_allgather(input=input_embs, infer_state=infer_state)
Expand Down Expand Up @@ -1087,6 +1096,7 @@ def _check_max_len_infer(self):
)
logger.error(exception_str)
raise Exception(exception_str)
torch.cuda.empty_cache()
return

def autotune_layers(self):
Expand Down Expand Up @@ -1221,6 +1231,9 @@ def _init_padded_req(self):
del b_seq_len
del b_ready_cache_len
del model_output
del b_mtp_index
del b_prefill_start_loc
del b_q_seq_len
torch.cuda.empty_cache()
return

Expand Down
6 changes: 6 additions & 0 deletions lightllm/common/basemodel/batch_objs.py
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,12 @@ class ModelOutput:
# 输入
mtp_main_output_hiddens: Optional[torch.Tensor] = None

# prompt_logics 用于在开启 return_all_prompt_logics 模式(如 enable_prompt_logprobs)时,
# 保存整个 prefill 阶段每一个 token 位置对应的 logits(而非仅最后一个位置的 logits)。
# 此时 logits 依然只保存每个请求最后一个位置的 logits,prompt_logics 为可选项,仅在
# 需要返回 prompt logprobs 信息时才会非空。
prompt_logics: Optional[torch.Tensor] = None

def to_no_ref_tensor(self):
self.logits = tensor_to_no_ref_tensor(self.logits)
if self.mtp_main_output_hiddens is not None:
Expand Down
9 changes: 7 additions & 2 deletions lightllm/common/basemodel/cuda_graph.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@
from lightllm.utils.envs_utils import get_env_start_args
from lightllm.distributed import dist_group_manager
from lightllm.common.basemodel.batch_objs import ModelInput, ModelOutput
from lightllm.utils.torch_memory_saver_utils import (
TorchMemorySaverWrapper,
MemoryTag,
)
from .infer_struct import InferStateInfo


Expand Down Expand Up @@ -54,6 +58,7 @@ def __init__(self, max_batch_size=8, max_len_in_batch=8192, tp_world_size: int =
self.max_batch_size = max_batch_size
self.graph_max_len_in_batch = max_len_in_batch
self.enable_decode_microbatch_overlap = self.args.enable_decode_microbatch_overlap
self.torch_memory_saver = TorchMemorySaverWrapper(self.args.enable_torch_memory_saver)

self.cuda_graph_batch_sizes = self.gen_cuda_graph_batch_sizes(
max_batch_size=max_batch_size,
Expand Down Expand Up @@ -105,7 +110,7 @@ def _capture_decode(self, decode_func, infer_state: InferStateInfo):
if param_name not in pure_para_set:
delattr(infer_state, param_name)

with torch.cuda.graph(graph_obj, pool=self.mempool):
with self.torch_memory_saver.cuda_graph(graph_obj, pool=self.mempool):
model_output = decode_func(infer_state)
self.graph[batch_size] = (graph_obj, infer_state, model_output)
graph_obj.replay()
Expand Down Expand Up @@ -139,7 +144,7 @@ def _capture_decode_overlap(
if para_name not in pure_para_set1:
delattr(infer_state1, para_name)

with torch.cuda.graph(graph_obj, pool=self.mempool):
with self.torch_memory_saver.cuda_graph(graph_obj, pool=self.mempool):
model_output, model_output1 = decode_func(infer_state, infer_state1)
self.graph[batch_size] = (
graph_obj,
Expand Down
4 changes: 4 additions & 0 deletions lightllm/common/basemodel/infer_struct.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,10 @@ def __init__(self):

self.is_token_healing: bool = False
self.return_all_prompt_logics: bool = False
# 在开启 return_all_prompt_logics 模式时,保存整个 prefill 阶段每一个
# token 位置的 logits,供后续回传 prompt logprobs 信息使用。
# 仅在 prefill 阶段且需要返回 prompt logprobs 时才会被填充。
self.prompt_logics: Optional[torch.Tensor] = None
self.multimodal_params: dict = None
self.is_cuda_graph: bool = False # 标记是否是cuda graph的捕获推理
self.dist_group: CustomProcessGroup = None
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
SliceMixinTpl,
)
from lightllm.common.basemodel.layer_weights.meta_weights.fused_moe.impl import select_fuse_moe_impl
from lightllm.common.basemodel.moe_route_info_manager import get_moe_capture_callback
from lightllm.common.quantization.quantize_method import QuantizationMethod
from lightllm.utils.envs_utils import get_redundancy_expert_ids, get_redundancy_expert_num, get_env_start_args
from lightllm.utils.dist_utils import get_global_world_size, get_global_rank
Expand Down Expand Up @@ -134,9 +135,11 @@ def experts(
topk_group: int,
num_expert_group: int,
is_prefill: Optional[bool] = None,
infer_state=None,
shared_expert_gate: Optional[torch.Tensor] = None,
) -> torch.Tensor:
"""Backward compatible method that routes to platform-specific implementation."""
# Captures MoE topk expert ids for routed-experts metadata when enabled.
moe_capture_callback = get_moe_capture_callback(infer_state, self.layer_num_)
return self.fuse_moe_impl(
input_tensor=input_tensor,
router_logits=router_logits,
Expand All @@ -150,6 +153,7 @@ def experts(
topk_group=topk_group,
num_expert_group=num_expert_group,
is_prefill=is_prefill,
moe_capture_callback=moe_capture_callback,
per_expert_scale=self.per_expert_scale,
shared_expert_gate=shared_expert_gate,
)
Expand Down Expand Up @@ -319,6 +323,7 @@ def _create_weight(self):
device_id=self.device_id_,
num_experts=self.local_n_routed_experts,
)
self.w1, self.w3 = w13_param_list
self.w1_list: List[WeightPack] = self._get_expert_weight_list(w13_param_list[0])
self.w3_list: List[WeightPack] = self._get_expert_weight_list(w13_param_list[1])
self.w2_list: List[WeightPack] = self._get_expert_weight_list(self.w2)
Expand All @@ -341,7 +346,6 @@ def _get_expert_weight_list(self, weight_pack: WeightPack):
return weight_list

def _load_weight(self, expert_idx_to_local_idx: Dict[int, int], weights: Dict[str, torch.Tensor]):
# Load each expert with TP slicing
for expert_idx, local_expert_idx in expert_idx_to_local_idx.items():
with self.lock:
self._load_expert(expert_idx, local_expert_idx, weights)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
from typing import Optional, Tuple, List, Dict, Any

from lightllm.common.basemodel.layer_weights.meta_weights.fused_moe.fused_moe_weight import FusedMoeWeight
from lightllm.common.basemodel.moe_route_info_manager import get_moe_capture_callback
from lightllm.utils.dist_utils import get_current_rank_in_dp, get_current_device_id
from lightllm.common.quantization import Quantcfg
from lightllm.common.quantization.quantize_method import QuantizationMethod
Expand Down Expand Up @@ -144,12 +145,18 @@ def experts(
topk_group: int,
num_expert_group: int,
is_prefill: Optional[bool] = None,
infer_state=None,
shared_expert_gate: Optional[torch.Tensor] = None,
):
assert shared_expert_gate is None, "shared_expert_gate is not supported by GPT-OSS fused MoE"

topk_weights, topk_ids = self._router(router_logits, top_k)

# Captures MoE topk expert ids for routed-experts metadata when enabled.
moe_capture_callback = get_moe_capture_callback(infer_state, self.layer_num_)
if moe_capture_callback is not None:
moe_capture_callback(topk_ids)

w1, w1_scale = self.w1
w2, w2_scale = self.w2
use_fp8_w8a8 = self.quant_method is not None
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import torch
from abc import abstractmethod
from typing import Callable, Optional
from lightllm.common.quantization.quantize_method import (
WeightPack,
QuantizationMethod,
)
from typing import Optional
from lightllm.utils.dist_utils import (
get_global_rank,
get_global_world_size,
Expand Down Expand Up @@ -62,6 +62,8 @@ def __call__(
topk_group: int,
num_expert_group: int,
is_prefill: Optional[bool] = None,
# Callback to capture MoE topk expert ids (routed experts metadata).
moe_capture_callback: Optional[Callable[[torch.Tensor], None]] = None,
per_expert_scale: Optional[torch.Tensor] = None,
# Qwen3.5 uses this gate to control fused shared expert aggregation weights.
shared_expert_gate: Optional[torch.Tensor] = None,
Expand Down
Loading
Loading