repo
stringclasses
454 values
file_path
stringlengths
5
201
extension
stringclasses
1 value
content
stringlengths
8
509k
num_lines
int64
3
16.9k
size_bytes
int64
8
511k
sglang
python/sglang/multimodal_gen/runtime/disaggregation/orchestrator.py
.py
# SPDX-License-Identifier: Apache-2.0 """Central request router for disaggregated diffusion pipelines.""" import json import logging import pickle import threading import time from collections import deque from dataclasses import dataclass import zmq from sglang.multimodal_gen.runtime.disaggregation.dispatch_policy ...
1,077
38,559
sglang
python/sglang/multimodal_gen/runtime/disaggregation/disagg_args.py
.py
# SPDX-License-Identifier: Apache-2.0 """Compatibility shim for disaggregated diffusion argument helpers.""" from __future__ import annotations import argparse from sglang.multimodal_gen.runtime.disaggregation.roles import RoleType from sglang.multimodal_gen.runtime.server_args.disagg import DisaggServerArgsMixin #...
29
1,031
sglang
python/sglang/multimodal_gen/runtime/disaggregation/transport/allocator.py
.py
# SPDX-License-Identifier: Apache-2.0 """Buddy-system memory allocator for TransferTensorBuffer.""" from __future__ import annotations import logging import threading from dataclasses import dataclass from functools import lru_cache logger = logging.getLogger(__name__) @dataclass class Block: offset: int # by...
187
6,010
sglang
python/sglang/multimodal_gen/runtime/disaggregation/transport/manager.py
.py
# SPDX-License-Identifier: Apache-2.0 """Per-instance transfer manager for disaggregated diffusion roles.""" import logging import threading from dataclasses import dataclass, field import torch from sglang.multimodal_gen.runtime.disaggregation.transport.buffer import ( SlotHandle, TransferTensorBuffer, ) fr...
276
8,579
sglang
python/sglang/multimodal_gen/runtime/disaggregation/transport/__init__.py
.py
# SPDX-License-Identifier: Apache-2.0 """Transport layer for disaggregated diffusion pipelines."""
3
99
sglang
python/sglang/multimodal_gen/runtime/disaggregation/transport/protocol.py
.py
# SPDX-License-Identifier: Apache-2.0 """Transfer protocol messages for disaggregated diffusion. All messages are sent as ZMQ multipart with a b"__transfer__" discriminator in frame[0] and JSON payload in frame[1]. """ import json from dataclasses import asdict, dataclass, field from typing import Any TRANSFER_MAGIC...
140
3,767
sglang
python/sglang/multimodal_gen/runtime/disaggregation/transport/buffer.py
.py
# SPDX-License-Identifier: Apache-2.0 """TransferTensorBuffer: memory staging area for disaggregated tensor transfer.""" from __future__ import annotations import logging from dataclasses import dataclass, field import torch from sglang.multimodal_gen.runtime.disaggregation.transport.allocator import ( BuddyAll...
261
8,528
sglang
python/sglang/multimodal_gen/runtime/disaggregation/transport/engine.py
.py
# SPDX-License-Identifier: Apache-2.0 """Transfer engine abstraction for tensor transfer between role instances.""" import logging from abc import ABC, abstractmethod logger = logging.getLogger(__name__) _MOONCAKE_AVAILABLE = None def _check_mooncake() -> bool: global _MOONCAKE_AVAILABLE if _MOONCAKE_AVAIL...
127
3,523
sglang
python/sglang/multimodal_gen/runtime/disaggregation/transport/codec.py
.py
# SPDX-License-Identifier: Apache-2.0 """Zero-copy tensor codec for ZMQ multipart messages. Frame 0: JSON metadata (tensor descriptors + scalar fields) Frame 1-N: Raw tensor data buffers (one per tensor) """ import ctypes import json import logging from dataclasses import dataclass import torch import zmq logger = ...
199
6,255
sglang
python/sglang/multimodal_gen/runtime/layers/moe.py
.py
# Adapted from LingBot-Video (https://github.com/Robbyant/lingbot-video). # # SPDX-License-Identifier: Apache-2.0 from __future__ import annotations import torch import torch.nn.functional as F from torch import nn class LingBotVideoMLP(nn.Module): def __init__(self, hidden_size: int, intermediate_size: int) ->...
183
6,907
sglang
python/sglang/multimodal_gen/runtime/layers/utils.py
.py
# Copied and adapted from: https://github.com/hao-ai-lab/FastVideo # SPDX-License-Identifier: Apache-2.0 # Adapted from vllm: https://github.com/vllm-project/vllm/blob/v0.7.3/vllm/model_executor/layers/utils.py """Utility methods for model layers.""" import inspect from typing import Any, Callable, List, Optional im...
268
9,778
sglang
python/sglang/multimodal_gen/runtime/layers/fused_scale_shift_gate.py
.py
# SPDX-License-Identifier: Apache-2.0 from typing import Optional, Tuple import torch import torch.nn.functional as F from sglang.multimodal_gen.runtime.layers.custom_op import CustomOp from sglang.multimodal_gen.runtime.platforms import current_platform _is_cuda = current_platform.is_cuda() if _is_cuda: from s...
160
5,433
sglang
python/sglang/multimodal_gen/runtime/layers/parallel_conv.py
.py
import contextvars import math from contextlib import contextmanager import torch import torch.distributed as dist import torch.nn as nn import torch.nn.functional as F from sglang.multimodal_gen.runtime.distributed.parallel_state import ( get_decode_parallel_group_coordinator, get_decode_parallel_rank, g...
802
25,168
sglang
python/sglang/multimodal_gen/runtime/layers/linear.py
.py
# Copied and adapted from: https://github.com/hao-ai-lab/FastVideo # SPDX-License-Identifier: Apache-2.0 # Adapted from vllm: https://github.com/vllm-project/vllm/blob/v0.7.3/vllm/model_executor/layers/linear.py from abc import abstractmethod import torch import torch.distributed as dist import torch.nn.functional a...
1,142
44,593
sglang
python/sglang/multimodal_gen/runtime/layers/layernorm.py
.py
# Copied and adapted from: https://github.com/hao-ai-lab/FastVideo # SPDX-License-Identifier: Apache-2.0 # Adapted from vllm: https://github.com/vllm-project/vllm/blob/v0.7.3/vllm/model_executor/layers/layernorm.py """Custom normalization layers.""" import os from typing import Optional, Tuple, Union import torch im...
1,159
40,300
sglang
python/sglang/multimodal_gen/runtime/layers/activation.py
.py
# Copied and adapted from: https://github.com/hao-ai-lab/FastVideo # SPDX-License-Identifier: Apache-2.0 # Adapted from vllm: https://github.com/vllm-project/vllm/blob/v0.7.3/vllm/model_executor/layers/activation.py """Custom activation functions.""" import math from typing import Any import torch import torch.nn as...
163
5,134
sglang
python/sglang/multimodal_gen/runtime/layers/visual_embedding.py
.py
# Copied and adapted from: https://github.com/hao-ai-lab/FastVideo # SPDX-License-Identifier: Apache-2.0 import math import torch import torch.nn as nn import torch.nn.functional as F from diffusers.models.embeddings import ( CombinedTimestepGuidanceTextProjEmbeddings as _CombinedTimestepGuidanceTextProjEmbeddin...
354
10,995
sglang
python/sglang/multimodal_gen/runtime/layers/custom_op.py
.py
# Copied and adapted from: https://github.com/hao-ai-lab/FastVideo # SPDX-License-Identifier: Apache-2.0 # Adapted from vllm: https://github.com/vllm-project/vllm/blob/v0.7.3/vllm/model_executor/custom_op.py from collections.abc import Callable from typing import Any import torch.nn as nn from sglang.kernel_api_log...
116
3,950
sglang
python/sglang/multimodal_gen/runtime/layers/mlp.py
.py
# Copied and adapted from: https://github.com/hao-ai-lab/FastVideo # SPDX-License-Identifier: Apache-2.0 from typing import Optional import torch import torch.nn as nn from diffusers.models.activations import ( GEGLU, GELU, ApproximateGELU, LinearActivation, SwiGLU, ) from sglang.multimodal_gen....
122
3,831
sglang
python/sglang/multimodal_gen/runtime/layers/elementwise.py
.py
import torch from sglang.kernels.ops.diffusion.triton.scale_shift import fuse_scale_shift_kernel from sglang.multimodal_gen.runtime.layers.custom_op import CustomOp class MulAdd(CustomOp): """ Fuse elementwise mul and add Input: a, b, c, OptionalInt[k] Output: a * (k + b) + c """ def __init_...
54
1,692
sglang
python/sglang/multimodal_gen/runtime/layers/usp.py
.py
# Copied and adapted from: https://github.com/hao-ai-lab/FastVideo import logging from typing import TYPE_CHECKING import torch import torch.distributed as dist import torch.distributed._functional_collectives as ft_c from torch.distributed.tensor.experimental._attention import _cp_options from sglang.kernels.ops.at...
928
35,254
sglang
python/sglang/multimodal_gen/runtime/layers/vocab_parallel_embedding.py
.py
# Copied and adapted from: https://github.com/hao-ai-lab/FastVideo # SPDX-License-Identifier: Apache-2.0 from collections.abc import Sequence from dataclasses import dataclass import torch import torch.distributed as dist import torch.nn.functional as F from torch.nn.parameter import Parameter, UninitializedParamete...
491
19,739
sglang
python/sglang/multimodal_gen/runtime/layers/kvcache/qvg_packed_cache.py
.py
# SPDX-License-Identifier: Apache-2.0 """Quant-VideoGen KV cache with PRQ-packed storage for completed chunks. Storage model (mirrors Quant-VideoGen's ChunkedKVCache, fitted to SGLang's ``update_and_get_attention_kv`` contract): * The retained window is split into frame/chunk-aligned *segments* in global token ...
402
15,396
sglang
python/sglang/multimodal_gen/runtime/layers/kvcache/__init__.py
.py
# SPDX-License-Identifier: Apache-2.0 from sglang.multimodal_gen.runtime.layers.kvcache.causal_attention_cache import ( CausalAttentionKVView, CausalSelfAttentionKVCache, CrossAttentionKVCache, ) __all__ = [ "CausalAttentionKVView", "CausalSelfAttentionKVCache", "CrossAttentionKVCache", ]
14
316
sglang
python/sglang/multimodal_gen/runtime/layers/kvcache/causal_attention_cache.py
.py
# SPDX-License-Identifier: Apache-2.0 from dataclasses import dataclass import torch @dataclass(slots=True) class CausalAttentionKVView: k: torch.Tensor v: torch.Tensor local_start_index: int local_end_index: int visible_local_end: int visible_global_end: int @dataclass(slots=True) class C...
534
21,030
sglang
python/sglang/multimodal_gen/runtime/layers/quantization/modelslim_mxfp8_scheme.py
.py
"""ModelSlim MXFP8 scheme for pre-quantized weight inference on Ascend NPU. Loads weights pre-quantized by msmodelslim (float8_e4m3fn weights, uint8 scales) and runs MXFP8 matmul at inference. """ from typing import List, Optional import torch from sglang.multimodal_gen.runtime.platforms import current_platform _i...
125
4,482
sglang
python/sglang/multimodal_gen/runtime/layers/quantization/bitsandbytes.py
.py
# SPDX-License-Identifier: Apache-2.0 from __future__ import annotations from typing import Any, Optional import torch import torch.nn as nn from packaging import version from sglang.multimodal_gen.runtime.layers.linear import ( LinearBase, LinearMethodBase, UnquantizedLinearMethod, ) from sglang.multim...
438
15,246
sglang
python/sglang/multimodal_gen/runtime/layers/quantization/modelopt_fp8.py
.py
"""ModelOpt FP8 quantization support for diffusion models. Handles checkpoints produced by NVIDIA Model Optimizer (ModelOpt) with ``quant_algo: "FP8"`` and ``quant_method: "modelopt"``. Per quantized linear layer the checkpoint contains: .weight float8_e4m3fn [out, in] FP8 quantized weight .weight_...
211
7,478
sglang
python/sglang/multimodal_gen/runtime/layers/quantization/modelslim.py
.py
from __future__ import annotations import logging from types import MappingProxyType from typing import TYPE_CHECKING, Any, Dict, List, Mapping, Optional, cast import torch from sglang.multimodal_gen.runtime.layers.linear import ( LinearMethodBase, UnquantizedLinearMethod, ) from sglang.multimodal_gen.runtim...
254
9,036
sglang
python/sglang/multimodal_gen/runtime/layers/quantization/fp8.py
.py
from __future__ import annotations import logging from typing import TYPE_CHECKING, Any, Dict, List, Optional, Union import torch from torch.nn import Module from torch.nn.parameter import Parameter from sglang.kernels.ops.quantization.fp8_kernel import ( is_fp8_fnuz, per_token_group_quant_fp8, ) from sglang...
516
20,841
sglang
python/sglang/multimodal_gen/runtime/layers/quantization/mxfp4_npu.py
.py
"""Online MXFP4 quantization for Diffusion models on Ascend NPU. Provides ``NPUMXFP4Config`` (registered as ``"mxfp4_npu"``) and ``NPUMXFP4DiffusionLinearMethod`` which quantises FP16/BF16 weights to MXFP4 at load time using dual-level MX quantization and uses ``npu_dynamic_dual_level_mx_quant`` + ``npu_dual_level_qua...
202
7,563
sglang
python/sglang/multimodal_gen/runtime/layers/quantization/__init__.py
.py
# Copied and adapted from: https://github.com/hao-ai-lab/FastVideo from typing import Literal, get_args from sglang.multimodal_gen.runtime.layers.quantization.bitsandbytes import ( BitsAndBytesConfig, ) from sglang.multimodal_gen.runtime.layers.quantization.configs.base_config import ( QuantizationConfig, ) f...
99
3,160
sglang
python/sglang/multimodal_gen/runtime/layers/quantization/weight_only_fp8.py
.py
# SPDX-License-Identifier: Apache-2.0 import logging import torch import torch.nn as nn import torch.nn.functional as F import sglang.multimodal_gen.envs as envs from sglang.multimodal_gen.runtime.distributed import ( divide, get_tp_group, split_tensor_along_last_dim, tensor_model_parallel_all_gather...
514
18,376
sglang
python/sglang/multimodal_gen/runtime/layers/quantization/modelopt_quant.py
.py
# Adapted from https://github.com/sgl-project/sglang/blob/main/python/sglang/srt/layers/quantization/modelopt_quant.py from __future__ import annotations import logging import re from functools import lru_cache from typing import Any, Dict, List, Optional import torch from sglang.multimodal_gen.runtime.layers.linear...
672
24,738
sglang
python/sglang/multimodal_gen/runtime/layers/quantization/modelslim_mxfp4_scheme.py
.py
"""ModelSlim MXFP4 scheme for pre-quantized weight inference on Ascend NPU. Loads weights pre-quantized by msmodelslim and runs MXFP4 dual-level matmul at inference via npu_dual_level_quant_matmul. Checkpoint tensor formats (verified from msmodelslim export): weight: [out, in] float8_e4m3fn (FP...
198
7,992
sglang
python/sglang/multimodal_gen/runtime/layers/quantization/mxfp4.py
.py
import logging from typing import Dict, List, Optional import torch from torch.nn.parameter import Parameter from sglang.multimodal_gen.runtime.layers.linear import ( LinearMethodBase, UnquantizedLinearMethod, ) from sglang.multimodal_gen.runtime.layers.quantization.configs.base_config import ( Quantizati...
239
8,243
sglang
python/sglang/multimodal_gen/runtime/layers/quantization/mxfp8_npu.py
.py
"""Online MXFP8 quantization for Diffusion models on Ascend NPU. Provides ``MXFP8Config`` (registered as ``"mxfp8"``) and ``NPUMXFP8DiffusionLinearMethod`` which quantise FP16/BF16 weights to MXFP8 at load time and use ``npu_dynamic_mx_quant`` + ``npu_quant_matmul`` for inference, mirroring the LLM-side ``NPUMXFP8Line...
177
6,136
sglang
python/sglang/multimodal_gen/runtime/layers/quantization/nunchaku_linear.py
.py
# SPDX-License-Identifier: Apache-2.0 from typing import List, Optional import torch import torch.nn as nn from torch.nn.parameter import Parameter from sglang.multimodal_gen.runtime.layers.linear import LinearMethodBase from sglang.multimodal_gen.runtime.utils.logging_utils import init_logger from sglang.multimodal_...
292
10,515
sglang
python/sglang/multimodal_gen/runtime/layers/quantization/configs/base_config.py
.py
# Copied and adapted from: https://github.com/hao-ai-lab/FastVideo # SPDX-License-Identifier: Apache-2.0 # Adapted from vllm: https://github.com/vllm-project/vllm/blob/v0.7.3/vllm/model_executor/layers/quantization/base_config.py import inspect from abc import ABC, abstractmethod from typing import TYPE_CHECKING, Any...
156
5,323
sglang
python/sglang/multimodal_gen/runtime/layers/quantization/configs/nunchaku_config.py
.py
# SPDX-License-Identifier: Apache-2.0 import json import os from dataclasses import dataclass from functools import lru_cache from typing import Any, Optional import torch from safetensors.torch import load_file as safetensors_load_file from torch import nn from sglang.multimodal_gen.runtime.layers.linear import Line...
284
9,321
sglang
python/sglang/multimodal_gen/runtime/layers/rotary_embedding/utils.py
.py
"""Primitive RoPE ops: rotate helpers and apply_rotary_emb utilities.""" from typing import Optional, Tuple import torch from sglang.kernel_api_logging import debug_kernel_api from sglang.kernels.ops.diffusion.triton.rotary import apply_rotary_embedding from sglang.multimodal_gen.runtime.platforms import current_pla...
197
7,321
sglang
python/sglang/multimodal_gen/runtime/layers/rotary_embedding/__init__.py
.py
# Copied and adapted from: https://github.com/hao-ai-lab/FastVideo # SPDX-License-Identifier: Apache-2.0 # Adapted from vllm: https://github.com/vllm-project/vllm/blob/v0.7.3/vllm/model_executor/layers/rotary_embedding.py # Adapted from # https://github.com/huggingface/transformers/blob/v4.33.2/src/transformers/model...
55
1,949
sglang
python/sglang/multimodal_gen/runtime/layers/rotary_embedding/factory.py
.py
"""get_rope / get_rotary_pos_embed factory functions and module-level caches.""" from collections import OrderedDict from typing import Any import torch from .base import LinearScalingRotaryEmbedding, RotaryEmbedding from .mrope import NDRotaryEmbedding, _to_tuple _ROPE_DICT: dict[tuple, RotaryEmbedding] = {} _ND_R...
172
5,645
sglang
python/sglang/multimodal_gen/runtime/layers/rotary_embedding/mrope.py
.py
"""MRotaryEmbedding, YaRNScalingMRotaryEmbedding, NDRotaryEmbedding, OneDRotaryEmbedding.""" import functools import torch from sglang.multimodal_gen.runtime.distributed.parallel_state import get_sp_group def _to_tuple(x: int | tuple[int, ...], dim: int = 2) -> tuple[int, ...]: if isinstance(x, int): r...
503
19,659
sglang
python/sglang/multimodal_gen/runtime/layers/rotary_embedding/base.py
.py
"""RotaryEmbedding base class and LinearScalingRotaryEmbedding variant.""" import torch from sglang.multimodal_gen.runtime.layers.custom_op import CustomOp from .utils import _apply_rotary_emb @CustomOp.register("rotary_embedding") class RotaryEmbedding(CustomOp): """Original rotary positional embedding.""" ...
134
4,723
sglang
python/sglang/multimodal_gen/runtime/layers/lora/linear.py
.py
# Copied and adapted from: https://github.com/hao-ai-lab/FastVideo # SPDX-License-Identifier: Apache-2.0 # Code adapted from SGLang https://github.com/sgl-project/sglang/blob/main/python/sglang/srt/lora/layers.py import os import torch from torch import nn from torch.distributed._composable.fsdp import ( CPUOfflo...
771
28,441
sglang
python/sglang/multimodal_gen/runtime/layers/attention/layer.py
.py
# Copied and adapted from: https://github.com/hao-ai-lab/FastVideo # SPDX-License-Identifier: Apache-2.0 import functools import os from collections.abc import Sequence from contextlib import nullcontext from typing import Type import torch import torch.nn as nn from torch.nn.attention import SDPBackend, sdpa_kernel ...
1,773
71,832
sglang
python/sglang/multimodal_gen/runtime/layers/attention/__init__.py
.py
# Copied and adapted from: https://github.com/hao-ai-lab/FastVideo # SPDX-License-Identifier: Apache-2.0 from sglang.multimodal_gen.runtime.layers.attention.backends.attention_backend import ( AttentionBackend, AttentionMetadata, AttentionMetadataBuilder, ) from sglang.multimodal_gen.runtime.layers.attent...
39
1,142
sglang
python/sglang/multimodal_gen/runtime/layers/attention/turbo_layer.py
.py
# copy and modify from https://github.com/thu-ml/TurboDiffusion/blob/main/turbodiffusion/rcm/utils/a2a_cp.py and https://github.com/thu-ml/TurboDiffusion/blob/main/turbodiffusion/SLA/core.py from typing import Any, Callable, List, Tuple, Type, Union import torch import torch.distributed as dist from einops import rea...
326
11,869
sglang
python/sglang/multimodal_gen/runtime/layers/attention/selector.py
.py
# Copied and adapted from: https://github.com/hao-ai-lab/FastVideo # SPDX-License-Identifier: Apache-2.0 # Adapted from vllm: https://github.com/vllm-project/vllm/blob/v0.7.3/vllm/attention/selector.py import os from collections.abc import Generator from contextlib import contextmanager from contextvars import Contex...
381
13,391
sglang
python/sglang/multimodal_gen/runtime/layers/attention/STA_configuration.py
.py
# Copied and adapted from: https://github.com/hao-ai-lab/FastVideo # SPDX-License-Identifier: Apache-2.0 import json import os from collections import defaultdict from typing import Any import numpy as np from sglang.multimodal_gen.utils import dict_to_3d_list def configure_sta( mode: str = "STA_searching", ...
415
16,484
sglang
python/sglang/multimodal_gen/runtime/layers/attention/backends/laser_attn.py
.py
import torch from sglang.multimodal_gen.runtime.layers.attention.backends.attention_backend import ( AttentionBackend, AttentionImpl, AttentionMetadata, ) from sglang.multimodal_gen.runtime.layers.attention.backends.sdpa import SDPABackend from sglang.multimodal_gen.runtime.platforms import AttentionBacken...
192
5,773
sglang
python/sglang/multimodal_gen/runtime/layers/attention/backends/ascend_fa.py
.py
from dataclasses import dataclass from typing import Any import torch from sglang.multimodal_gen.runtime.layers.attention.backends.attention_backend import ( AttentionBackend, AttentionImpl, AttentionMetadata, AttentionMetadataBuilder, ) from sglang.multimodal_gen.runtime.platforms import AttentionBac...
111
2,969
sglang
python/sglang/multimodal_gen/runtime/layers/attention/backends/rain_fusion_attn.py
.py
import math from dataclasses import dataclass from typing import Any, List, Optional import attentions # noqa: F401 import torch from einops import rearrange from sglang.multimodal_gen.runtime.layers.attention.backends.attention_backend import ( AttentionBackend, AttentionImpl, AttentionMetadata, Att...
415
13,622
sglang
python/sglang/multimodal_gen/runtime/layers/attention/backends/xpu_backend.py
.py
# Copied and adapted from: https://github.com/hao-ai-lab/FastVideo # SPDX-License-Identifier: Apache-2.0 from functools import lru_cache import torch from sglang.multimodal_gen.runtime.platforms import AttentionBackendEnum try: from sgl_kernel.flash_attn import flash_attn_varlen_func flash_attn_func = flas...
123
3,473
sglang
python/sglang/multimodal_gen/runtime/layers/attention/backends/sage_attn3.py
.py
# Copied and adapted from: https://github.com/hao-ai-lab/FastVideo # SPDX-License-Identifier: Apache-2.0 import torch import torch.nn.functional as F from sageattn3 import sageattn3_blackwell from sglang.multimodal_gen.runtime.layers.attention.backends.attention_backend import ( AttentionBackend, AttentionIm...
93
2,974
sglang
python/sglang/multimodal_gen/runtime/layers/attention/backends/attention_backend.py
.py
# Copied and adapted from: https://github.com/hao-ai-lab/FastVideo # SPDX-License-Identifier: Apache-2.0 # Adapted from vllm: https://github.com/vllm-project/vllm/blob/v0.7.3/vllm/attention/backends/abstract.py from abc import ABC, abstractmethod from dataclasses import dataclass, fields from typing import TYPE_CHECK...
219
6,246
sglang
python/sglang/multimodal_gen/runtime/layers/attention/backends/sdpa.py
.py
# Copied and adapted from: https://github.com/hao-ai-lab/FastVideo # SPDX-License-Identifier: Apache-2.0 from contextlib import nullcontext import torch from torch.nn.attention import SDPBackend, sdpa_kernel from sglang.multimodal_gen.runtime.layers.attention.backends.attention_backend import ( # FlashAttentionMet...
257
8,295
sglang
python/sglang/multimodal_gen/runtime/layers/attention/backends/sparse_video_gen_2_attn.py
.py
""" Sparse Video Gen 2 (SAP) attention backend. This is a baseline integration that wires the backend into the attention framework. Adapted from https://github.com/svg-project/Sparse-VideoGen/blob/main/svg/models/wan/attention.py """ from dataclasses import dataclass, field from typing import Any import torch impor...
563
18,056
sglang
python/sglang/multimodal_gen/runtime/layers/attention/backends/block_sparse_attn.py
.py
from dataclasses import dataclass from typing import Any import attentions # noqa: F401 import torch from sglang.multimodal_gen.runtime.layers.attention.backends.attention_backend import ( AttentionBackend, AttentionImpl, AttentionMetadata, AttentionMetadataBuilder, ) from sglang.multimodal_gen.runti...
280
8,745
sglang
python/sglang/multimodal_gen/runtime/layers/attention/backends/video_sparse_attn.py
.py
# Copied and adapted from: https://github.com/hao-ai-lab/FastVideo # SPDX-License-Identifier: Apache-2.0 import functools import math from dataclasses import dataclass import torch try: from vsa import video_sparse_attn except ImportError: video_sparse_attn = None from typing import Any from sglang.multimo...
329
10,494
sglang
python/sglang/multimodal_gen/runtime/layers/attention/backends/flash_attn.py
.py
# Copied and adapted from: https://github.com/hao-ai-lab/FastVideo # SPDX-License-Identifier: Apache-2.0 from dataclasses import dataclass from typing import Any, List, Optional, Tuple import torch from sglang.kernels.ops.attention.flash_attention import flash_attn_varlen_func from sglang.multimodal_gen.runtime.layer...
475
15,569
sglang
python/sglang/multimodal_gen/runtime/layers/attention/backends/sliding_tile_attn.py
.py
# Copied and adapted from: https://github.com/hao-ai-lab/FastVideo # SPDX-License-Identifier: Apache-2.0 import json from dataclasses import dataclass from typing import Any import torch from einops import rearrange from sglang.multimodal_gen.runtime.distributed import get_sp_group from sglang.multimodal_gen.runtime...
317
10,801
sglang
python/sglang/multimodal_gen/runtime/layers/attention/backends/aiter_sage.py
.py
# SPDX-License-Identifier: Apache-2.0 import torch from sglang.multimodal_gen.runtime.layers.attention.backends.attention_backend import ( AttentionBackend, AttentionImpl, AttentionMetadata, AttentionMetadataBuilder, ) from sglang.multimodal_gen.runtime.platforms import AttentionBackendEnum class A...
82
2,353
sglang
python/sglang/multimodal_gen/runtime/layers/attention/backends/sol_attn.py
.py
# SPDX-License-Identifier: Apache-2.0 from __future__ import annotations import re import torch from sglang.kernels.ops.attention.flash_attention import flash_attn_varlen_func from sglang.multimodal_gen.runtime.layers.attention.backends.attention_backend import ( AttentionBackend, AttentionImpl, Attenti...
241
7,583
sglang
python/sglang/multimodal_gen/runtime/layers/attention/backends/vmoba.py
.py
# Copied and adapted from: https://github.com/hao-ai-lab/FastVideo # SPDX-License-Identifier: Apache-2.0 import re from dataclasses import dataclass import torch from einops import rearrange from kernel.attn.vmoba_attn.vmoba import ( moba_attn_varlen, process_moba_input, process_moba_output, ) from sgla...
260
8,337
sglang
python/sglang/multimodal_gen/runtime/layers/attention/backends/sparse_linear_attn.py
.py
""" Copyright (c) 2025 by SLA team. Licensed under the Apache License, Version 2.0 (the "License"); This implementation is adapted from: from https://github.com/thu-ml/TurboDiffusion/blob/main/turbodiffusion/SLA/core.py and https://github.com/thu-ml/SLA/blob/main/SageSLA/core.py Citation (please cite if you use this ...
579
19,065
sglang
python/sglang/multimodal_gen/runtime/layers/attention/backends/flash_attn_2.py
.py
# Copied and adapted from: https://github.com/hao-ai-lab/FastVideo # SPDX-License-Identifier: Apache-2.0 import torch from sglang.multimodal_gen.runtime.layers.attention.backends.attention_backend import ( AttentionBackend, AttentionImpl, AttentionMetadata, AttentionMetadataBuilder, ) from sglang.mul...
80
2,121
sglang
python/sglang/multimodal_gen/runtime/layers/attention/backends/sage_attn.py
.py
# Copied and adapted from: https://github.com/hao-ai-lab/FastVideo # SPDX-License-Identifier: Apache-2.0 import torch from sageattention import sageattn from sglang.multimodal_gen.runtime.layers.attention.backends.attention_backend import ( # FlashAttentionMetadata, AttentionBackend, AttentionImpl, Att...
160
4,581
sglang
python/sglang/multimodal_gen/runtime/layers/attention/backends/subblock_sparse_attn.py
.py
# SPDX-License-Identifier: Apache-2.0 """SubBlock block-sparse attention backend. Routes FlashInfer's 64-token block-sparse kernel with a K-side sub-block log-sum-exp score (see ``backends/subblock_sparse/``). Everything is training-free: the router runs before attention and produces the ``q2k_block_index`` the kernel...
408
16,262
sglang
python/sglang/multimodal_gen/runtime/layers/attention/backends/aiter.py
.py
# Copied and adapted from: https://github.com/hao-ai-lab/FastVideo # SPDX-License-Identifier: Apache-2.0 import importlib import logging import os import aiter import torch from sglang.multimodal_gen.runtime.layers.attention.backends.attention_backend import ( AttentionBackend, AttentionImpl, AttentionM...
247
7,707
sglang
python/sglang/multimodal_gen/runtime/layers/attention/backends/subblock_sparse/kernels.py
.py
# SPDX-License-Identifier: Apache-2.0 """Fused sub-block score kernel: bf16 GEMM + segmented log-sum-exp in one pass. score[i, j] = log2 sum_{b < n_k} 2 ** ( qbar_i . kbar_{j,b} ) The PyTorch router materialises ``[B, H, Gq, Gk*n_k]`` fp32 (254 MB at S=96k, n_k=4), reduces it, and throws it away -- the GEMM is 4%...
301
10,512
sglang
python/sglang/multimodal_gen/runtime/layers/attention/backends/subblock_sparse/__init__.py
.py
# SPDX-License-Identifier: Apache-2.0 """SubBlock -- training-free block-sparse attention routing for video DiTs. Originally vendored from the standalone SubBlock repository; ``router.py`` and ``kernels.py`` have since diverged from it. ``router.py`` scores every (query block, key block) pair from sub-block-pooled Q/...
16
650
sglang
python/sglang/multimodal_gen/runtime/layers/attention/backends/subblock_sparse/router.py
.py
# SPDX-License-Identifier: Apache-2.0 """Sub-block block-sparse routing for FlashInfer's ``bsa_attn_blk64_fwd``. Training-free. Runs *before* attention, produces the ``q2k_block_index`` tensor the 64-token block-sparse kernel consumes. Why sub-blocks -------------- The usual proxy score for a 64x64 block is ``mean(Q_...
257
11,811
sglang
python/sglang/multimodal_gen/runtime/entrypoints/utils.py
.py
# Copied and adapted from: https://github.com/hao-ai-lab/FastVideo # SPDX-License-Identifier: Apache-2.0 """ DiffGenerator module for sglang-diffusion. This module provides a consolidated interface for generating videos using diffusion models. """ import atexit import json import mmap import os import shutil import ...
1,288
41,862
sglang
python/sglang/multimodal_gen/runtime/entrypoints/diffusion_generator.py
.py
# Copied and adapted from: https://github.com/hao-ai-lab/FastVideo # SPDX-License-Identifier: Apache-2.0 """ DiffGenerator module for sglang-diffusion. This module provides a consolidated interface for generating images/videos using diffusion models. """ import dataclasses import multiprocessing as mp import os impo...
759
30,351
sglang
python/sglang/multimodal_gen/runtime/entrypoints/http_server.py
.py
# Copied and adapted from: https://github.com/hao-ai-lab/FastVideo import asyncio import base64 import os import signal import uuid from contextlib import asynccontextmanager, suppress from typing import TYPE_CHECKING import httpx import torch from fastapi import APIRouter, FastAPI, Request, Response from fastapi.mid...
436
14,767
sglang
python/sglang/multimodal_gen/runtime/entrypoints/post_training/io_struct.py
.py
"""Request/response data structures for post-training APIs.""" from __future__ import annotations from dataclasses import dataclass from typing import Any, Optional from pydantic import BaseModel @dataclass class UpdateWeightFromDiskReqInput: """Request to update model weights from disk for diffusion models.""...
116
3,206
sglang
python/sglang/multimodal_gen/runtime/entrypoints/post_training/utils.py
.py
"""Tensor serialization for post-training / rollout HTTP responses.""" from __future__ import annotations from typing import Any import numpy as np import torch from safetensors.torch import load, save def tensor_to_bytes(t: torch.Tensor) -> bytes: return save({"t": t.detach().contiguous().cpu()}) def bytes_...
45
1,252
sglang
python/sglang/multimodal_gen/runtime/entrypoints/post_training/rollout_api.py
.py
"""Rollout HTTP API (``POST /rollout/generate``).""" from __future__ import annotations from typing import Any import msgspec import torch from fastapi import APIRouter, HTTPException, Response from sglang.multimodal_gen.configs.sample.sampling_params import generate_request_id from sglang.multimodal_gen.runtime.en...
351
13,024
sglang
python/sglang/multimodal_gen/runtime/entrypoints/post_training/weights_api.py
.py
"""Weight update API for the diffusion engine.""" from fastapi import APIRouter, Request from sglang.multimodal_gen.runtime.entrypoints.post_training.io_struct import ( GetWeightsChecksumReqInput, ReleaseMemoryOccupationReqInput, ResumeMemoryOccupationReqInput, UpdateWeightFromDiskReqInput, Update...
204
6,438
sglang
python/sglang/multimodal_gen/runtime/entrypoints/openai/stores.py
.py
import asyncio from typing import Any, Dict, Optional class AsyncDictStore: """A small async-safe in-memory key-value store for dict items. This encapsulates the usual pattern of a module-level dict guarded by an asyncio.Lock and provides simple CRUD methods that are safe to call concurrently from Fa...
71
2,248
sglang
python/sglang/multimodal_gen/runtime/entrypoints/openai/video_api.py
.py
# Copied and adapted from: https://github.com/hao-ai-lab/FastVideo import asyncio import json import os import shutil import tempfile import time from collections.abc import Coroutine from contextlib import suppress from typing import Any, Dict, Optional from fastapi import ( APIRouter, File, Form, HT...
965
35,717
sglang
python/sglang/multimodal_gen/runtime/entrypoints/openai/utils.py
.py
# Copied and adapted from: https://github.com/hao-ai-lab/FastVideo import asyncio import inspect import json import os import shutil import tempfile import time from contextlib import contextmanager from typing import Any, Generator, List, Optional, Union import httpx from fastapi import HTTPException, UploadFile fro...
472
16,768
sglang
python/sglang/multimodal_gen/runtime/entrypoints/openai/mesh_api.py
.py
import asyncio import os import time from typing import Any, Dict, List, Optional from fastapi import ( APIRouter, File, Form, HTTPException, Path, Query, Request, UploadFile, ) from fastapi.responses import FileResponse from sglang.multimodal_gen.configs.sample.sampling_params import ...
281
9,560
sglang
python/sglang/multimodal_gen/runtime/entrypoints/openai/storage.py
.py
import asyncio import os from typing import Optional from sglang.multimodal_gen.runtime.utils.logging_utils import init_logger logger = init_logger(__name__) class CloudStorage: def __init__(self): self.enabled = os.getenv("SGLANG_CLOUD_STORAGE_TYPE", "").lower() == "s3" if not self.enabled: ...
110
3,635
sglang
python/sglang/multimodal_gen/runtime/entrypoints/openai/image_api.py
.py
# Copied and adapted from: https://github.com/hao-ai-lab/FastVideo import asyncio import base64 import contextlib import json import os import time from typing import Any, List, Optional from fastapi import ( APIRouter, File, Form, HTTPException, Path, Query, Request, UploadFile, ) fro...
598
21,620
sglang
python/sglang/multimodal_gen/runtime/entrypoints/openai/protocol.py
.py
import time import uuid from abc import ABC from dataclasses import dataclass, field from typing import Any, Dict, List, Literal, Optional, Union from pydantic import BaseModel, ConfigDict, Field # Image API protocol models class ImageResponseData(BaseModel): b64_json: Optional[str] = None url: Optional[str]...
246
8,182
sglang
python/sglang/multimodal_gen/runtime/entrypoints/openai/common_api.py
.py
import time from typing import Any, List, Optional, Union from fastapi import APIRouter, Body, HTTPException from pydantic import BaseModel, Field from sglang.multimodal_gen.registry import get_model_info from sglang.multimodal_gen.runtime.entrypoints.utils import ( ListLorasReq, MergeLoraWeightsReq, SetL...
239
8,746
sglang
python/sglang/multimodal_gen/runtime/entrypoints/openai/realtime/generate_session.py
.py
# SPDX-License-Identifier: Apache-2.0 from __future__ import annotations from dataclasses import dataclass from typing import TYPE_CHECKING, Any from uuid import uuid4 from sglang.multimodal_gen.runtime.entrypoints.openai.protocol import ( RealtimeVideoGenerationsRequest, ) from sglang.multimodal_gen.runtime.rea...
85
2,648
sglang
python/sglang/multimodal_gen/runtime/entrypoints/openai/realtime/realtime_adapter.py
.py
# SPDX-License-Identifier: Apache-2.0 from __future__ import annotations import hashlib import os import tempfile from dataclasses import dataclass, field from typing import TYPE_CHECKING, Any from fastapi import WebSocket from sglang.multimodal_gen.runtime.entrypoints.openai.protocol import ( RealtimeEvent, ...
269
8,701
sglang
python/sglang/multimodal_gen/runtime/entrypoints/openai/realtime/registry.py
.py
# SPDX-License-Identifier: Apache-2.0 from __future__ import annotations from typing import TYPE_CHECKING from sglang.multimodal_gen.runtime.entrypoints.openai.realtime.realtime_adapter import ( BaseRealtimeModelAdapter, ) if TYPE_CHECKING: from sglang.multimodal_gen.runtime.server_args import ServerArgs ...
70
2,132
sglang
python/sglang/multimodal_gen/runtime/entrypoints/openai/realtime/timer.py
.py
# SPDX-License-Identifier: Apache-2.0 import time class RealtimeStageTimer: __slots__ = ("_last", "_start") def __init__(self): now = time.perf_counter() self._start = now self._last = now def mark_ms(self) -> float: now = time.perf_counter() elapsed_ms = (now - ...
22
486
sglang
python/sglang/multimodal_gen/runtime/entrypoints/openai/realtime/realtime_output_adapter.py
.py
# SPDX-License-Identifier: Apache-2.0 from __future__ import annotations import asyncio import io from dataclasses import dataclass from typing import TYPE_CHECKING, TypedDict import msgspec.msgpack from fastapi import WebSocket from PIL import Image from sglang.multimodal_gen.runtime.entrypoints.openai.realtime.ti...
611
19,606
sglang
python/sglang/multimodal_gen/runtime/entrypoints/openai/realtime/realtime_video_api.py
.py
# SPDX-License-Identifier: Apache-2.0 import asyncio import shutil import time from typing import TYPE_CHECKING import msgspec.msgpack from fastapi import APIRouter, WebSocket, WebSocketDisconnect from sglang.multimodal_gen.runtime.entrypoints.openai.protocol import ( RealtimeEvent, RealtimeVideoGenerationsR...
501
17,069
sglang
python/sglang/multimodal_gen/runtime/entrypoints/openai/realtime/adapters/lingbot_world_realtime_adapter.py
.py
# SPDX-License-Identifier: Apache-2.0 from __future__ import annotations from typing import TYPE_CHECKING, Any from sglang.multimodal_gen.runtime.entrypoints.openai.protocol import ( RealtimeEvent, RealtimeVideoGenerationsRequest, ) from sglang.multimodal_gen.runtime.entrypoints.openai.realtime.realtime_adap...
353
12,453
sglang
python/sglang/multimodal_gen/runtime/entrypoints/openai/realtime/adapters/sana_wm_realtime_adapter.py
.py
# SPDX-License-Identifier: Apache-2.0 from __future__ import annotations from typing import TYPE_CHECKING, Any from sglang.multimodal_gen.runtime.entrypoints.openai.protocol import ( RealtimeEvent, RealtimeVideoGenerationsRequest, ) from sglang.multimodal_gen.runtime.entrypoints.openai.realtime.realtime_adap...
265
9,942
sglang
python/sglang/multimodal_gen/runtime/entrypoints/action/openpi.py
.py
# SPDX-License-Identifier: Apache-2.0 from __future__ import annotations from typing import Any from fastapi import APIRouter, WebSocket from sglang.multimodal_gen.runtime.entrypoints.action.ws_utils import ( run_action_msgpack_ws, ) from sglang.multimodal_gen.runtime.server_args import ServerArgs router = API...
30
768
sglang
python/sglang/multimodal_gen/runtime/entrypoints/action/protocol.py
.py
# SPDX-License-Identifier: Apache-2.0 from __future__ import annotations import base64 import dataclasses import io import time import uuid from functools import lru_cache from typing import Any import numpy as np from PIL import Image from sglang.multimodal_gen.configs.pipeline_configs.cosmos3 import Cosmos3Config...
663
24,721
sglang
python/sglang/multimodal_gen/runtime/entrypoints/action/api.py
.py
# SPDX-License-Identifier: Apache-2.0 from __future__ import annotations import json import os from contextlib import nullcontext from typing import Any from fastapi import APIRouter, HTTPException, Request, Response, WebSocket from sglang.multimodal_gen.configs.sample.sampling_params import generate_request_id fro...
254
8,100