Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
76 commits
Select commit Hold shift + click to select a range
65eebd8
pickle to msgpack migration
rainj-me Jun 3, 2026
b4b22d1
lint
rainj-me Jun 4, 2026
f045343
Merge branch 'main' into dev/msgpack-migration
rainj-me Jun 4, 2026
7142327
support python 3.10
rainj-me Jun 4, 2026
3527ab9
fix the ci
rainj-me Jun 4, 2026
5f76d23
Merge branch 'main' into dev/msgpack-migration
rainj-me Jun 4, 2026
78ccb65
revert the meta test model
rainj-me Jun 4, 2026
df8e4c3
fix the model repo
rainj-me Jun 4, 2026
bb64f8b
fix logprob type error
rainj-me Jun 4, 2026
2f8e997
fix ci for test_data_parallel_controller.py
rainj-me Jun 4, 2026
54d2ae4
fix unit test for the tokenizer manager
rainj-me Jun 4, 2026
563c9bf
fix ci test
rainj-me Jun 5, 2026
2af0e99
Merge branch 'main' into dev/msgpack-migration
rainj-me Jun 5, 2026
304718f
Merge branch 'main' into dev/msgpack-migration
rainj-me Jun 5, 2026
c250fd0
fix ci test
rainj-me Jun 6, 2026
7725506
fix ci test
rainj-me Jun 6, 2026
e861846
Merge branch 'main' into dev/msgpack-migration
rainj-me Jun 6, 2026
c748f36
fix ci tests
rainj-me Jun 7, 2026
907b274
Merge branch 'main' into dev/msgpack-migration
rainj-me Jun 7, 2026
9023dc6
fix ci test
rainj-me Jun 7, 2026
a7832ac
Merge branch 'main' into dev/msgpack-migration
rainj-me Jun 7, 2026
fad4cb0
fix ci tests
rainj-me Jun 7, 2026
1379286
http2 fix
rainj-me Jun 7, 2026
2b33112
fix ci test
rainj-me Jun 7, 2026
6709987
fix the ci test
rainj-me Jun 7, 2026
690a442
fix ci test
rainj-me Jun 8, 2026
d5992f5
Merge branch 'main' into dev/msgpack-migration
rainj-me Jun 8, 2026
88b7d0f
fix ci test
rainj-me Jun 8, 2026
2232276
Merge branch 'main' into dev/msgpack-migration
rainj-me Jun 8, 2026
f961a4e
lint
rainj-me Jun 8, 2026
24c80b2
Merge branch 'main' into dev/msgpack-migration
rainj-me Jun 8, 2026
2427aad
fix ci tests
rainj-me Jun 8, 2026
350fadf
Merge branch 'main' into dev/msgpack-migration
rainj-me Jun 8, 2026
28329d2
fix ci test
rainj-me Jun 8, 2026
b60c3e7
Merge branch 'main' into dev/msgpack-migration
rainj-me Jun 8, 2026
1521232
fix ci test
rainj-me Jun 9, 2026
e517452
Merge branch 'main' into dev/msgpack-migration
rainj-me Jun 9, 2026
ebe1414
fix ci test
rainj-me Jun 9, 2026
b795b7a
Merge branch 'main' into dev/msgpack-migration
rainj-me Jun 9, 2026
ca7c51c
Merge branch 'main' into dev/msgpack-migration
rainj-me Jun 10, 2026
a0015fd
Merge branch 'main' into dev/msgpack-migration
rainj-me Jun 10, 2026
00d3554
address comments
rainj-me Jun 12, 2026
02a5808
Merge branch 'main' into dev/msgpack-migration
rainj-me Jun 12, 2026
5d78f74
fix ci test
rainj-me Jun 12, 2026
e32ec71
fix samplingparam re-post-init after normalize
rainj-me Jun 12, 2026
87b52ac
support metrics obj searialized with msgpack
rainj-me Jun 13, 2026
bc4089e
Merge branch 'main' into dev/msgpack-migration
rainj-me Jun 13, 2026
73d5008
lint
rainj-me Jun 13, 2026
bab26bc
fix ci test
rainj-me Jun 13, 2026
e0328e6
fix ci test
rainj-me Jun 13, 2026
c944785
Merge branch 'main' into dev/msgpack-migration
rainj-me Jun 13, 2026
25db6a7
fix ci test
rainj-me Jun 14, 2026
64bf06e
Merge branch 'main' into dev/msgpack-migration
rainj-me Jun 14, 2026
48e8f82
refactor BaseReqIpc and BaseBatchReqIpc, fix ci tests
rainj-me Jun 15, 2026
526f740
fix ci test
rainj-me Jun 15, 2026
8cfe46f
Merge branch 'main' into dev/msgpack-migration
rainj-me Jun 15, 2026
55a446a
remove comment
rainj-me Jun 15, 2026
e8ac7a0
support array-like to reduce msg size after serialization
rainj-me Jun 15, 2026
95ecfcb
Merge branch 'main' into dev/msgpack-migration
rainj-me Jun 15, 2026
381c099
fix ci test
rainj-me Jun 15, 2026
b6e00e6
Merge branch 'main' into dev/msgpack-migration
rainj-me Jun 16, 2026
9760869
refactor http2 server
rainj-me Jun 16, 2026
8a2e776
Merge branch 'main' into dev/msgpack-migration
rainj-me Jun 16, 2026
0322d27
set the granian backlog and backpressure exactly like uvicorn
rainj-me Jun 16, 2026
ccc1f05
rename api_specs.py to http_api_specs.py
rainj-me Jun 16, 2026
fa4926e
Merge branch 'main' into dev/msgpack-migration
rainj-me Jun 16, 2026
e593318
use msgpack to serialize mm_inputs and fix ci
rainj-me Jun 17, 2026
983b395
Merge branch 'main' into dev/msgpack-migration
rainj-me Jun 17, 2026
7fd3eca
fix ci issue
rainj-me Jun 17, 2026
752ee24
Merge branch 'main' into dev/msgpack-migration
rainj-me Jun 17, 2026
2ba59f9
revert the MultimodalDataItem to dataclass since lots of feature stil…
rainj-me Jun 17, 2026
b7571e3
Merge branch 'main' into dev/msgpack-migration
rainj-me Jun 17, 2026
8467177
fix ci test
rainj-me Jun 17, 2026
fbe5d88
Merge branch 'main' into dev/msgpack-migration
rainj-me Jun 17, 2026
3a713d6
Merge branch 'main' into dev/msgpack-migration
rainj-me Jun 17, 2026
a0d51f0
Merge branch 'main' into dev/msgpack-migration
rainj-me Jun 17, 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
16 changes: 9 additions & 7 deletions python/sglang/srt/debug_utils/dumper.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@

import torch
import torch.distributed as dist
import zmq

from sglang.srt.managers.io_struct import sock_recv, sock_send

# -------------------------------------- config base ------------------------------------------

Expand Down Expand Up @@ -1419,8 +1422,6 @@ def _create_zmq_rpc_broadcast(
handler, timeout_seconds: int = 60
) -> Optional["_ZmqRpcBroadcast"]:
"""A general-purpose minimal RPC to support broadcasting executions to multi processes"""
import zmq

rank = _get_rank()
world_size = dist.get_world_size() if dist.is_initialized() else 1

Expand All @@ -1433,13 +1434,13 @@ def _create_zmq_rpc_broadcast(
def serve_loop():
while True:
try:
req = sock.recv_pyobj()
req = sock_recv(sock)
result = getattr(handler, req["method"])(*req["args"], **req["kwargs"])
resp = {"result": result, "error": None}
except Exception as e:
_log(f"[ZmqRpc] error inside handler: {e}")
resp = {"result": None, "error": str(e)}
sock.send_pyobj(resp)
sock_send(sock, resp)

thread = threading.Thread(target=serve_loop, daemon=True)
thread.start()
Expand Down Expand Up @@ -1476,14 +1477,15 @@ def __init__(self, socket, debug_name: str):

def __getattr__(self, method_name: str):
def call(*args, **kwargs):
self._socket.send_pyobj(
sock_send(
self._socket,
{
"method": method_name,
"args": args,
"kwargs": kwargs,
}
},
)
response = self._socket.recv_pyobj()
response = sock_recv(self._socket)
if response["error"]:
raise RuntimeError(
f"RPC error on {self._debug_name}: {response['error']}"
Expand Down
3 changes: 2 additions & 1 deletion python/sglang/srt/disaggregation/encode_grpc_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
handle_scheduler_receive_url_request,
launch_encoder,
)
from sglang.srt.managers.io_struct import async_sock_send
from sglang.srt.managers.schedule_batch import Modality
from sglang.srt.server_args import PortArgs, ServerArgs
from sglang.srt.utils import random_uuid
Expand Down Expand Up @@ -95,7 +96,7 @@ async def Encode(
"part_idx": request.part_idx,
}
for socket in self.send_sockets:
await socket.send_pyobj(request_dict)
await async_sock_send(socket, request_dict)

# gRPC encode is image-only; encoder.encode() requires modality
(
Expand Down
39 changes: 23 additions & 16 deletions python/sglang/srt/disaggregation/encode_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,15 @@
init_distributed_environment,
initialize_model_parallel,
)
from sglang.srt.entrypoints.http_api_specs import ProfileReqInputSpec
from sglang.srt.environ import envs
from sglang.srt.layers.dp_attention import initialize_dp_attention
from sglang.srt.managers.io_struct import ProfileReq, ProfileReqInput, ProfileReqType
from sglang.srt.managers.io_struct import (
ProfileReq,
ProfileReqType,
async_sock_recv,
sock_send,
)
from sglang.srt.managers.schedule_batch import Modality, MultimodalDataItem
from sglang.srt.mem_cache.multimodal_cache import EmbeddingResult, MultiModalStaticCache
from sglang.srt.model_loader import get_model
Expand Down Expand Up @@ -2390,13 +2396,14 @@ async def _dispatch_group(
requests = [p.request for p in group]
start = time.time()
for sock in self.send_sockets:
sock.send_pyobj(
sock_send(
sock,
{
"type": "batch_encode",
"modality": modality.name,
"requests": requests,
"enter_time": start,
}
},
)

logger.info(f"Dispatching batch of {len(group)} {modality.name} requests")
Expand Down Expand Up @@ -2442,7 +2449,7 @@ async def _dispatch_per_request(
req = p.request
try:
for sock in self.send_sockets:
sock.send_pyobj(req)
sock_send(sock, req)
result = await self.encoder.encode_request(req, modality)
if not p.future.done():
p.future.set_result(result)
Expand Down Expand Up @@ -2978,7 +2985,7 @@ async def _dp_worker_handle_profile(
req = (
ProfileReq(**obj)
if obj is not None
else ProfileReq(ProfileReqType.START_PROFILE)
else ProfileReq(req_type=ProfileReqType.START_PROFILE)
)
if enc.profiler is None:
enc.profiler = EncoderProfiler(dp_rank)
Expand Down Expand Up @@ -3197,9 +3204,9 @@ async def run_encoder(
):
encoder = MMEncoder(server_args, schedule_path, dist_init_method, rank)
while True:
request = await encoder.schedule_socket.recv_pyobj()
request = await async_sock_recv(encoder.schedule_socket)
if isinstance(request, ProfileReq):
if request.type == ProfileReqType.START_PROFILE:
if request.req_type == ProfileReqType.START_PROFILE:
if encoder.profiler is None:
encoder.profiler = EncoderProfiler(encoder.rank)
encoder.profiler.start(request)
Expand Down Expand Up @@ -3601,7 +3608,7 @@ def start_background_send(req_id):
)
else:
for socket in send_sockets:
socket.send_pyobj(request)
sock_send(socket, request)
nbytes, embedding_len, embedding_dim, error_msg, error_code = (
await encoder.encode_request(request, modality)
)
Expand Down Expand Up @@ -3822,7 +3829,7 @@ async def health_generate():

# Broadcast to other TP ranks so distributed ops stay in sync
for socket in send_sockets:
socket.send_pyobj(dummy_request)
sock_send(socket, dummy_request)

# Run encode on rank 0 with timeout
_, _, _, error_msg, _ = await asyncio.wait_for(
Expand Down Expand Up @@ -3854,12 +3861,12 @@ async def health_generate():


@app.api_route("/start_profile", methods=["GET", "POST"])
async def start_profile_async(obj: Optional[ProfileReqInput] = None):
async def start_profile_async(obj: Optional[ProfileReqInputSpec] = None):
if dp_dispatcher is not None:
profile_req = None
if obj is not None:
profile_req = {
"type": ProfileReqType.START_PROFILE,
"req_type": ProfileReqType.START_PROFILE,
"output_dir": obj.output_dir,
"start_step": obj.start_step,
"num_steps": obj.num_steps,
Expand All @@ -3883,10 +3890,10 @@ async def start_profile_async(obj: Optional[ProfileReqInput] = None):
return Response(content="encoder not ready\n", status_code=503)
req = None
if obj is None:
req = ProfileReq(ProfileReqType.START_PROFILE)
req = ProfileReq(req_type=ProfileReqType.START_PROFILE)
else:
req = ProfileReq(
type=ProfileReqType.START_PROFILE,
req_type=ProfileReqType.START_PROFILE,
output_dir=obj.output_dir,
start_step=obj.start_step,
num_steps=obj.num_steps,
Expand All @@ -3900,7 +3907,7 @@ async def start_profile_async(obj: Optional[ProfileReqInput] = None):
profile_stages=obj.profile_stages,
)
for socket in send_sockets:
socket.send_pyobj(req)
sock_send(socket, req)
if encoder.profiler is None:
encoder.profiler = EncoderProfiler(encoder.rank)
ok, msg = encoder.profiler.start(req)
Expand Down Expand Up @@ -3929,9 +3936,9 @@ async def stop_profile_async():
return Response(
content="profiling not initialized\n", status_code=HTTPStatus.BAD_REQUEST
)
req = ProfileReq(ProfileReqType.STOP_PROFILE)
req = ProfileReq(req_type=ProfileReqType.STOP_PROFILE)
for socket in send_sockets:
socket.send_pyobj(req)
sock_send(socket, req)
ok, msg = encoder.profiler.stop()
if ok:
return Response(content="Stop profiling.\n", status_code=200)
Expand Down
6 changes: 3 additions & 3 deletions python/sglang/srt/elastic_ep/expert_backup_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
)
from sglang.srt.environ import envs
from sglang.srt.eplb.expert_location import get_global_expert_location_metadata
from sglang.srt.managers.io_struct import UpdateExpertBackupReq
from sglang.srt.managers.io_struct import UpdateExpertBackupReq, sock_recv, sock_send
from sglang.srt.server_args import ServerArgs
from sglang.srt.utils.network import get_local_ip_auto

Expand Down Expand Up @@ -65,15 +65,15 @@ def __init__(self, server_args: ServerArgs, model_runner):
self.ready_sockets[i].connect(
f"tcp://{all_ips[i * get_world_size() // server_args.nnodes]}:{PORT_BASE + i * 2}"
)
self.ready_sockets[i].send_pyobj(UpdateExpertBackupReq())
sock_send(self.ready_sockets[i], UpdateExpertBackupReq())

self._receive_thread = threading.Thread(target=self._receive_loop, daemon=True)
self._receive_thread.start()

def _receive_loop(self):
cnt = 0
while cnt < self.engine_num:
response = self.recv_list[cnt].recv_pyobj()
response = sock_recv(self.recv_list[cnt])
self.dram_map_list[response.rank] = response.weight_pointer_map
self.session_id_list[response.rank] = response.session_id
self.buffer_size = max(self.buffer_size, response.buffer_size)
Expand Down
6 changes: 3 additions & 3 deletions python/sglang/srt/elastic_ep/expert_backup_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
from sglang.srt.configs.load_config import LoadConfig
from sglang.srt.configs.model_config import ModelConfig
from sglang.srt.environ import envs
from sglang.srt.managers.io_struct import BackupDramReq
from sglang.srt.managers.io_struct import BackupDramReq, sock_recv, sock_send
from sglang.srt.model_loader.loader import DefaultModelLoader, get_model_loader
from sglang.srt.model_loader.utils import set_default_torch_dtype
from sglang.srt.server_args import (
Expand Down Expand Up @@ -62,7 +62,7 @@ def __init__(self, server_args: ServerArgs, port_args: PortArgs):
num_ready_clients = 0

while num_ready_clients < server_args.tp_size:
self.recv_from_expert_backup_client.recv_pyobj()
sock_recv(self.recv_from_expert_backup_client)
num_ready_clients += 1

back_req = BackupDramReq(
Expand All @@ -72,7 +72,7 @@ def __init__(self, server_args: ServerArgs, port_args: PortArgs):
buffer_size=self.continuous_buffer.numel()
* self.continuous_buffer.element_size(),
)
self.send_to_expert_backup_client.send_pyobj(back_req)
sock_send(self.send_to_expert_backup_client, back_req)

# Keep the manager subprocess alive until signals
signal.pause()
Expand Down
8 changes: 5 additions & 3 deletions python/sglang/srt/entrypoints/engine.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,8 @@
UpdateWeightsFromDistributedReqInput,
UpdateWeightsFromIPCReqInput,
UpdateWeightsFromTensorReqInput,
sock_recv,
sock_send,
)
from sglang.srt.managers.multi_tokenizer_mixin import (
MultiTokenizerRouter,
Expand Down Expand Up @@ -861,8 +863,8 @@ def _launch_subprocesses(
for p in detoken_procs:
scheduler_init_result.all_child_pids.append(p.pid)

# Init tokenizer manager first, as the bootstrap server is initialized here
if server_args.tokenizer_worker_num == 1:
# Launch a single tokenizer manager without the router
tokenizer_manager, template_manager = init_tokenizer_manager_func(
Comment thread
rainj-me marked this conversation as resolved.
server_args, port_args
)
Expand Down Expand Up @@ -1223,8 +1225,8 @@ def freeze_gc(self):

def collective_rpc(self, method: str, **kwargs):
obj = RpcReqInput(method=method, parameters=kwargs)
self.send_to_rpc.send_pyobj(obj)
recv_req = self.send_to_rpc.recv_pyobj(zmq.BLOCKY)
sock_send(self.send_to_rpc, obj)
recv_req = sock_recv(self.send_to_rpc, flags=zmq.BLOCKY)
assert isinstance(recv_req, RpcReqOutput)
assert recv_req.success, recv_req.message

Expand Down
4 changes: 2 additions & 2 deletions python/sglang/srt/entrypoints/grpc_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ async def start_profile_handler(request):
record_shapes = (record_shapes is not False) and env_record_shapes

req = ProfileReq(
type=ProfileReqType.START_PROFILE,
req_type=ProfileReqType.START_PROFILE,
output_dir=body.get("output_dir"),
start_step=body.get("start_step"),
num_steps=body.get("num_steps"),
Expand Down Expand Up @@ -134,7 +134,7 @@ async def start_profile_handler(request):

async def stop_profile_handler(request):
try:
req = ProfileReq(type=ProfileReqType.STOP_PROFILE)
req = ProfileReq(req_type=ProfileReqType.STOP_PROFILE)
results = await request_manager.send_communicator_req(
req, "profile_communicator", timeout=600.0
)
Expand Down
Loading
Loading