lang: support direct video inference (#9936)

Co-authored-by: Lianmin Zheng <lianminzheng@gmail.com>
This commit is contained in:
Mick
2025-10-23 18:12:39 -07:00
committed by GitHub
co-authored by Lianmin Zheng
parent 14a4d80e57
commit 823b442945
8 changed files with 52 additions and 69 deletions
+5 -11
View File
@@ -32,11 +32,7 @@ from sglang.lang.ir import (
SglVarScopeEnd,
SglVideo,
)
from sglang.utils import (
encode_image_base64,
encode_video_base64,
get_exception_traceback,
)
from sglang.utils import encode_image_base64, get_exception_traceback
def run_internal(state, program, func_args, func_kwargs, sync):
@@ -286,6 +282,7 @@ class StreamExecutor:
# For vision
self.images_ = []
self.cur_images = []
self.videos_ = []
# For fork/join
self.fork_start_text_pos = None
@@ -372,6 +369,7 @@ class StreamExecutor:
exes[i].cur_role_begin_pos = self.cur_role_begin_pos
exes[i].fork_start_text_pos = len(self.text_)
exes[i].images_ = list(self.images_)
exes[i].videos_ = list(self.videos_)
# TODO(ying): handle API speculative execution
@@ -508,13 +506,9 @@ class StreamExecutor:
def _execute_video(self, expr: SglVideo):
path = expr.path
num_frames = expr.num_frames
base64_data = encode_video_base64(path, num_frames)
self.images_.append((path, base64_data))
self.cur_images.append((path, base64_data))
self.text_ += self.chat_template.image_token
self.videos_.append(path)
self.text_ += self.chat_template.video_token
def _spec_gen(self, sampling_params):
stop = sampling_params.stop