Support sanity checking weight consistency especially for RL (#13854)

This commit is contained in:
fzyzcjy
2025-11-27 20:25:12 +08:00
committed by GitHub
parent 2bc8ee8b74
commit 25758647b1
7 changed files with 156 additions and 0 deletions

View File

@@ -1311,6 +1311,17 @@ class ResumeMemoryOccupationReqOutput(BaseReq):
pass
@dataclass
class CheckWeightsReqInput(BaseReq):
action: str
@dataclass
class CheckWeightsReqOutput(BaseReq):
success: bool
message: str
@dataclass
class SlowDownReqInput(BaseReq):
forward_sleep_time: Optional[float]

View File

@@ -71,6 +71,7 @@ from sglang.srt.managers.io_struct import (
BaseReq,
BatchTokenizedEmbeddingReqInput,
BatchTokenizedGenerateReqInput,
CheckWeightsReqInput,
ClearHiCacheReqInput,
ClearHiCacheReqOutput,
CloseSessionReqInput,
@@ -568,6 +569,7 @@ class Scheduler(
(GetWeightsByNameReqInput, self.get_weights_by_name),
(ReleaseMemoryOccupationReqInput, self.release_memory_occupation),
(ResumeMemoryOccupationReqInput, self.resume_memory_occupation),
(CheckWeightsReqInput, self.check_weights),
(SlowDownReqInput, self.slow_down),
(ProfileReq, self.profile),
(FreezeGCReq, self.handle_freeze_gc),

View File

@@ -1,6 +1,7 @@
from __future__ import annotations
import logging
import traceback
from typing import TYPE_CHECKING, Tuple
import torch
@@ -12,6 +13,8 @@ from sglang.srt.constants import (
GPU_MEMORY_TYPE_WEIGHTS,
)
from sglang.srt.managers.io_struct import (
CheckWeightsReqInput,
CheckWeightsReqOutput,
DestroyWeightsUpdateGroupReqInput,
DestroyWeightsUpdateGroupReqOutput,
GetWeightsByNameReqInput,
@@ -166,6 +169,15 @@ class SchedulerUpdateWeightsMixin:
return ResumeMemoryOccupationReqOutput()
def check_weights(self: Scheduler, recv_req: CheckWeightsReqInput):
try:
self.tp_worker.model_runner.check_weights(action=recv_req.action)
return CheckWeightsReqOutput(success=True, message="Success.")
except Exception as e:
logger.warning(f"check_weights see error: {e}")
traceback.print_exc()
return CheckWeightsReqOutput(success=False, message=f"{e}")
def save_remote_model(self: Scheduler, params):
url = params["url"]

View File

@@ -22,6 +22,8 @@ import fastapi
import zmq
from sglang.srt.managers.io_struct import (
CheckWeightsReqInput,
CheckWeightsReqOutput,
ClearHiCacheReqInput,
ClearHiCacheReqOutput,
CloseSessionReqInput,
@@ -183,6 +185,9 @@ class TokenizerCommunicatorMixin:
self.resume_memory_occupation_communicator = _Communicator(
self.send_to_scheduler, server_args.dp_size
)
self.check_weights_communicator = _Communicator(
self.send_to_scheduler, server_args.dp_size
)
self.slow_down_communicator = _Communicator(
self.send_to_scheduler, server_args.dp_size
)
@@ -256,6 +261,10 @@ class TokenizerCommunicatorMixin:
ResumeMemoryOccupationReqOutput,
self.resume_memory_occupation_communicator.handle_recv,
),
(
CheckWeightsReqOutput,
self.check_weights_communicator.handle_recv,
),
(
SlowDownReqOutput,
self.slow_down_communicator.handle_recv,
@@ -670,6 +679,15 @@ class TokenizerCommunicatorMixin:
self.auto_create_handle_loop()
await self.resume_memory_occupation_communicator(obj)
async def check_weights(
self: TokenizerManager,
obj: CheckWeightsReqInput,
request: Optional[fastapi.Request] = None,
) -> CheckWeightsReqOutput:
self.auto_create_handle_loop()
results = await self.check_weights_communicator(obj)
return _Communicator.merge_results(results)
async def slow_down(
self: TokenizerManager,
obj: SlowDownReqInput,