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/models/encoders/clip.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/models/clip.py
# Adapted from transformers: https://github.com/huggingface/transformers/blob/v4.39.0/src/transformers/models... | 805 | 29,016 |
sglang | python/sglang/multimodal_gen/runtime/models/encoders/qwen3.py | .py | from collections.abc import Iterable
from typing import Any
import torch
from torch import nn
from sglang.multimodal_gen.configs.models.encoders import BaseEncoderOutput
from sglang.multimodal_gen.configs.models.encoders.qwen3 import Qwen3TextConfig
from sglang.multimodal_gen.runtime.distributed import get_tp_world_s... | 488 | 17,175 |
sglang | python/sglang/multimodal_gen/runtime/models/encoders/qwen3vl.py | .py | # SPDX-License-Identifier: Apache-2.0
from transformers import (
Cache,
DynamicCache,
)
from transformers.modeling_flash_attention_utils import FlashAttentionKwargs
from transformers.utils import TransformersKwargs, is_torchdynamo_compiling
from sglang.multimodal_gen.configs.models.encoders.qwen3vl import Qwe... | 1,281 | 50,426 |
sglang | python/sglang/multimodal_gen/runtime/models/encoders/qwen2_5vl.py | .py | # Copied and adapted from: https://github.com/hao-ai-lab/FastVideo
from transformers import (
Cache,
DynamicCache,
PretrainedConfig,
Qwen2_5_VLTextConfig,
Qwen2RMSNorm,
)
from transformers.masking_utils import (
create_causal_mask,
create_sliding_window_causal_mask,
)
from transformers.mode... | 1,448 | 59,821 |
sglang | python/sglang/multimodal_gen/runtime/models/encoders/ideogram.py | .py | # SPDX-License-Identifier: Apache-2.0
from collections.abc import Iterable
from typing import Tuple
import torch
from transformers.models.qwen3_vl.configuration_qwen3_vl import Qwen3VLTextConfig
from sglang.multimodal_gen.configs.models.encoders import BaseEncoderOutput
from sglang.multimodal_gen.configs.models.enco... | 196 | 8,128 |
sglang | python/sglang/multimodal_gen/runtime/models/encoders/gemma_3.py | .py | # Copied and adapted from: https://github.com/hao-ai-lab/FastVideo
# SPDX-License-Identifier: Apache-2.0
# Adapted from sglang: python/sglang/srt/models/gemma3_causal.py
import logging
from functools import partial
from typing import Any, Iterable, Optional, Set, Tuple
import torch
from torch import nn
from sglang.... | 1,251 | 46,791 |
sglang | python/sglang/multimodal_gen/runtime/models/encoders/qwen3vl_vision.py | .py | # SPDX-License-Identifier: Apache-2.0
"""Native Qwen3-VL vision encoder."""
from __future__ import annotations
from dataclasses import dataclass
from typing import Any
import torch
import torch.nn as nn
import torch.nn.functional as F
from sglang.multimodal_gen.runtime.layers.attention.selector import get_attn_back... | 430 | 16,442 |
sglang | python/sglang/multimodal_gen/runtime/models/encoders/gemma2.py | .py | # SPDX-License-Identifier: Apache-2.0
#
# Gemma2 2B text encoder for SANA.
#
# This is a decoder-only language model used as a text encoder: we feed
# in tokenized text and extract the final hidden states (not logits) as
# the conditioning signal for SANA's cross-attention layers.
#
# Architecture follows google/gemma-... | 448 | 15,820 |
sglang | python/sglang/multimodal_gen/runtime/models/encoders/qwen2_5vl_vision.py | .py | # SPDX-License-Identifier: Apache-2.0
"""Native Qwen2.5-VL vision encoder."""
from __future__ import annotations
from dataclasses import dataclass
from typing import Any
import torch
import torch.nn as nn
import torch.nn.functional as F
from sglang.multimodal_gen.runtime.layers.attention.selector import get_attn_ba... | 462 | 16,428 |
sglang | python/sglang/multimodal_gen/runtime/models/encoders/llama.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/models/llama.py
# Adapted from
# https://github.com/huggingface/transformers/blob/v4.28.0/src/transformers/models/llama/mod... | 461 | 17,372 |
sglang | python/sglang/multimodal_gen/runtime/models/encoders/hunyuan3d.py | .py | # Copied and adapted from: https://github.com/Tencent-Hunyuan/Hunyuan3D-2
import numpy as np
import torch
import torch.nn as nn
from torchvision import transforms
from transformers import (
CLIPVisionConfig,
CLIPVisionModelWithProjection,
Dinov2Config,
Dinov2Model,
)
from sglang.multimodal_gen.runtime... | 288 | 9,014 |
sglang | python/sglang/multimodal_gen/runtime/models/encoders/vision.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/models/vision.py
import torch
from sglang.multimodal_gen.runtime.utils.logging_utils import init_logger
logger = init_log... | 58 | 2,301 |
sglang | python/sglang/multimodal_gen/runtime/models/encoders/base.py | .py | # Copied and adapted from: https://github.com/hao-ai-lab/FastVideo
# SPDX-License-Identifier: Apache-2.0
from abc import ABC, abstractmethod
from dataclasses import field
import torch
from torch import nn
from sglang.multimodal_gen.configs.models.encoders import (
BaseEncoderOutput,
EncoderConfig,
ImageE... | 229 | 8,656 |
sglang | python/sglang/multimodal_gen/runtime/models/encoders/t5.py | .py | # Copied and adapted from: https://github.com/hao-ai-lab/FastVideo
# SPDX-License-Identifier: Apache-2.0
# Adapted from transformers: https://github.com/huggingface/transformers/blob/v4.39.0/src/transformers/models/t5/modeling_t5.py
# Derived from T5 implementation posted on HuggingFace; license below:
#
# coding=utf... | 756 | 26,494 |
sglang | python/sglang/multimodal_gen/runtime/models/upsampler/latent_upsampler.py | .py | # Ported from https://github.com/Lightricks/LTX-2
# SPDX-License-Identifier: Apache-2.0
import math
from typing import Optional, Tuple
import torch
import torch.nn.functional as F
from einops import rearrange
from sglang.kernels.ops.diffusion.group_norm_silu import apply_group_norm_silu
from sglang.multimodal_gen.ru... | 278 | 10,264 |
sglang | python/sglang/multimodal_gen/runtime/models/upsampler/__init__.py | .py | from sglang.multimodal_gen.runtime.models.upsampler.latent_upsampler import (
LatentUpsampler,
)
__all__ = ["LatentUpsampler"]
| 6 | 132 |
sglang | python/sglang/multimodal_gen/runtime/models/adapter/ltx_2_duration_head.py | .py | # SPDX-License-Identifier: Apache-2.0
"""LTX-2.5 duration head.
Predicts the shot length a caption implies from the text connector outputs.
Used only when the caller omits `num_frames`.
"""
import torch
import torch.nn.functional as F
from torch import nn
from sglang.multimodal_gen.configs.models.adapter.ltx_2_durat... | 194 | 7,525 |
sglang | python/sglang/multimodal_gen/runtime/models/adapter/ltx_2_connector.py | .py | import functools
import math
from typing import Optional, Tuple, Union
import numpy as np
import torch
import torch.nn as nn
import torch.nn.functional as F
from diffusers.models.attention import FeedForward
from sglang.multimodal_gen.configs.models.adapter.ltx_2_connector import (
LTX2ConnectorConfig,
)
from sgl... | 718 | 27,625 |
sglang | python/sglang/multimodal_gen/runtime/models/vaes/autoencoder_kl_flux2.py | .py | import math
from typing import Dict, Optional, Tuple, Union
import torch
import torch.nn as nn
from diffusers.models.attention_processor import (
ADDED_KV_ATTENTION_PROCESSORS,
CROSS_ATTENTION_PROCESSORS,
AttentionProcessor,
AttnAddedKVProcessor,
AttnProcessor,
)
from diffusers.models.autoencoders.... | 540 | 21,161 |
sglang | python/sglang/multimodal_gen/runtime/models/vaes/autoencoder.py | .py | # Copied and adapted from: https://github.com/hao-ai-lab/FastVideo
from typing import Dict, Optional, Tuple, Union
import torch
from diffusers.models.attention_processor import (
ADDED_KV_ATTENTION_PROCESSORS,
CROSS_ATTENTION_PROCESSORS,
Attention,
AttentionProcessor,
AttnAddedKVProcessor,
Att... | 603 | 24,835 |
sglang | python/sglang/multimodal_gen/runtime/models/vaes/hunyuan3d_vae.py | .py | # Copied and adapted from: https://github.com/Tencent-Hunyuan/Hunyuan3D-2
from __future__ import annotations
from typing import Callable, List, Optional, Tuple, Union
import numpy as np
import torch
import torch.nn as nn
import torch.nn.functional as F
from einops import rearrange, repeat
from tqdm import tqdm
fro... | 1,228 | 41,283 |
sglang | python/sglang/multimodal_gen/runtime/models/vaes/fast_path_gate.py | .py | # SPDX-License-Identifier: Apache-2.0
"""Shared decode-scoped gate for optional VAE fast paths."""
from contextlib import contextmanager
from weakref import WeakKeyDictionary
import torch.nn as nn
class VaeFastPathGate:
"""Mutable flag shared by the wrappers installed on one VAE."""
__slots__ = ("enabled",... | 42 | 986 |
sglang | python/sglang/multimodal_gen/runtime/models/vaes/hunyuanvae.py | .py | # Copied and adapted from: https://github.com/hao-ai-lab/FastVideo
# SPDX-License-Identifier: Apache-2.0
# Adapted from diffusers
# Copyright 2024 The Hunyuan Team, The HuggingFace Team and The sglang-diffusion Team. All rights reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may no... | 979 | 34,489 |
sglang | python/sglang/multimodal_gen/runtime/models/vaes/cosmos3_avae.py | .py | # SPDX-License-Identifier: Apache-2.0
"""Decoder-only audio tokenizer for the Cosmos3 sound modality."""
from __future__ import annotations
import math
from typing import Any
import torch
from torch import nn
from torch.nn.utils import weight_norm
from sglang.multimodal_gen.runtime.managers.memory_managers.layerwis... | 230 | 7,915 |
sglang | python/sglang/multimodal_gen/runtime/models/vaes/ltx_2_audio.py | .py | from typing import Optional, Tuple, Union
import torch
import torch.nn.functional as F
from diffusers.models.autoencoders.vae import (
DecoderOutput,
DiagonalGaussianDistribution,
)
from diffusers.models.modeling_outputs import AutoencoderKLOutput
from torch import nn
from sglang.multimodal_gen.configs.models... | 919 | 32,762 |
sglang | python/sglang/multimodal_gen/runtime/models/vaes/dac.py | .py | # Copied and adapted from: https://github.com/descriptinc/descript-audio-codec
# SPDX-License-Identifier: MIT
import math
from bisect import bisect_right
from typing import Union
import torch
import torch.nn.functional as F
from einops import rearrange
from torch import nn
from sglang.multimodal_gen.configs.models.... | 647 | 23,511 |
sglang | python/sglang/multimodal_gen/runtime/models/vaes/autoencoder_dc.py | .py | # SPDX-License-Identifier: Apache-2.0
from collections.abc import Iterable
import torch
from diffusers.models.autoencoders.vae import DecoderOutput
from torch import nn
from sglang.multimodal_gen.configs.models.vaes.sana import SanaVAEConfig
from sglang.multimodal_gen.runtime.distributed.parallel_state import (
... | 221 | 8,352 |
sglang | python/sglang/multimodal_gen/runtime/models/vaes/ltx_2_3_condition_encoder.py | .py | from typing import Any
import torch
import torch.nn as nn
from sglang.multimodal_gen.runtime.managers.memory_managers.layerwise_offload import (
LayerwiseOffloadableModuleMixin,
)
from sglang.multimodal_gen.runtime.models.vaes.ltx_2_vae import (
LTX2VideoCausalConv3d,
LTX2VideoResnetBlock3d,
LTXVideoD... | 211 | 7,250 |
sglang | python/sglang/multimodal_gen/runtime/models/vaes/minimax_h3.py | .py | # SPDX-License-Identifier: Apache-2.0
from sglang.multimodal_gen.configs.models.vaes.minimax_h3_audio import (
MiniMaxH3AudioVAEConfig,
)
from sglang.multimodal_gen.configs.models.vaes.minimax_h3_video import (
MiniMaxH3VideoVAEConfig,
)
from sglang.multimodal_gen.runtime.managers.memory_managers.layerwise_off... | 119 | 4,370 |
sglang | python/sglang/multimodal_gen/runtime/models/vaes/ltx_2_vae.py | .py | from functools import lru_cache
from typing import Optional, Tuple, Union
import torch
import torch.nn as nn
from diffusers.models.activations import get_activation
from diffusers.models.autoencoders.vae import (
DecoderOutput,
DiagonalGaussianDistribution,
)
from diffusers.models.embeddings import PixArtAlpha... | 2,337 | 89,270 |
sglang | python/sglang/multimodal_gen/runtime/models/vaes/common.py | .py | # Copied and adapted from: https://github.com/hao-ai-lab/FastVideo
# SPDX-License-Identifier: Apache-2.0
from abc import ABC, abstractmethod
from functools import lru_cache
from math import isqrt, prod
from typing import Optional, cast
import numpy as np
import torch
import torch.distributed as dist
from diffusers.m... | 811 | 31,627 |
sglang | python/sglang/multimodal_gen/runtime/models/vaes/autoencoder_kl_qwenimage.py | .py | # Copied and adapted from: https://github.com/hao-ai-lab/FastVideo
from typing import Optional, Tuple, Union
import torch
import torch.distributed as dist
import torch.nn as nn
import torch.nn.functional as F
from diffusers.models.activations import get_activation
from diffusers.models.autoencoders.vae import (
D... | 1,351 | 50,224 |
sglang | python/sglang/multimodal_gen/runtime/models/vaes/flux2_vae_cuda_opt.py | .py | # SPDX-License-Identifier: Apache-2.0
"""CUDA fast paths for KL VAE decoders built on the diffusers ``Decoder``.
Covers the FLUX.2 VAE (``AutoencoderKLFlux2``) and the generic
``AutoencoderKL`` (FLUX.1 / Z-Image / SD3); both share the exact same
decoder module family (``ResnetBlock2D`` GroupNorm+SiLU chains,
``Upsampl... | 425 | 16,040 |
sglang | python/sglang/multimodal_gen/runtime/models/vaes/wan_vae_cuda_opt.py | .py | # SPDX-License-Identifier: Apache-2.0
"""CUDA fast path for the Wan VAE decoder (AutoencoderKLWan).
Fuses every decoder ``WanRMS_norm -> SiLU`` chain into one Triton kernel on
the channels_last_3d layout. Wrappers are installed once at VAE load and
dispatch on a decode-scoped :class:`VaeFastPathGate`: ``quality == "hi... | 141 | 5,080 |
sglang | python/sglang/multimodal_gen/runtime/models/vaes/wanvae.py | .py | # Copied and adapted from: https://github.com/hao-ai-lab/FastVideo
# SPDX-License-Identifier: Apache-2.0
# Copyright 2025 The Wan Team and The HuggingFace Team. All rights reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
#... | 1,700 | 55,317 |
sglang | python/sglang/multimodal_gen/runtime/models/vaes/minimax_h3_video_vae/norm.py | .py | # SPDX-License-Identifier: Apache-2.0
# Torch-native normalization for the MiniMax H3 visual VAE.
import math
import os
import torch
import torch.nn as nn
import torch.nn.functional as F
from .conv import BaseConv3d
def _validate_activation(activation):
valid_activations = {"identity", "silu", "relu"}
if ac... | 284 | 8,521 |
sglang | python/sglang/multimodal_gen/runtime/models/vaes/minimax_h3_video_vae/base_module.py | .py | # SPDX-License-Identifier: Apache-2.0
# Transformer building blocks for the MiniMax H3 visual VAE ViT decoder.
import math
from typing import Optional
import torch
import torch.nn as nn
from diffusers.utils import logging
from diffusers.utils.torch_utils import maybe_allow_in_graph
from sglang.kernels.ops.activation.... | 281 | 9,512 |
sglang | python/sglang/multimodal_gen/runtime/models/vaes/minimax_h3_video_vae/attention.py | .py | # SPDX-License-Identifier: Apache-2.0
# Attention module for the MiniMax H3 visual VAE (inference-only bundle).
from contextlib import nullcontext
from typing import Optional
import torch
import torch.distributed as dist
import torch.nn as nn
import torch.nn.functional as F
from diffusers.utils import logging
from tor... | 153 | 5,699 |
sglang | python/sglang/multimodal_gen/runtime/models/vaes/minimax_h3_video_vae/__init__.py | .py | # SPDX-License-Identifier: Apache-2.0
from .klvae import AutoencoderKLLegacy
__all__ = ["AutoencoderKLLegacy"]
| 6 | 113 |
sglang | python/sglang/multimodal_gen/runtime/models/vaes/minimax_h3_video_vae/vit_utils.py | .py | # SPDX-License-Identifier: Apache-2.0
# ViT runtime helpers for the MiniMax H3 visual VAE.
import os
from collections.abc import Sequence
from typing import Tuple
import torch
from diffusers.utils import logging
def _env_flag(name, default="0"):
value = os.environ.get(name, default)
return str(value).strip()... | 256 | 8,459 |
sglang | python/sglang/multimodal_gen/runtime/models/vaes/minimax_h3_video_vae/vae_vit.py | .py | # SPDX-License-Identifier: Apache-2.0
# ViT3D decoder for the MiniMax H3 visual VAE (inference-only bundle).
import torch
import torch.distributed as dist
import torch.nn as nn
from diffusers.configuration_utils import ConfigMixin, register_to_config
from diffusers.models.modeling_utils import ModelMixin
from diffusers... | 357 | 12,753 |
sglang | python/sglang/multimodal_gen/runtime/models/vaes/minimax_h3_video_vae/conv.py | .py | # SPDX-License-Identifier: Apache-2.0
# 3D convolution for the MiniMax H3 visual VAE.
import torch.nn as nn
import torch.nn.functional as F
class BaseConv3d(nn.Conv3d):
def __init__(
self,
in_channels,
out_channels,
kernel_size,
stride=1,
padding=0,
bias=Tru... | 84 | 2,407 |
sglang | python/sglang/multimodal_gen/runtime/models/vaes/minimax_h3_video_vae/processor.py | .py | # SPDX-License-Identifier: Apache-2.0
# Tensor pre/post-processing for the MiniMax H3 visual VAE.
import math
from typing import Tuple
import numpy as np
import torch
from diffusers.utils import logging
from einops import rearrange
from torchvision.transforms import Normalize
NORM_CONFIGS = {
"imagenet": {
... | 280 | 9,940 |
sglang | python/sglang/multimodal_gen/runtime/models/vaes/minimax_h3_video_vae/vae_cnn.py | .py | # SPDX-License-Identifier: Apache-2.0
# 3D causal CNN encoder for the MiniMax H3 visual VAE (inference-only bundle).
import os
import torch.nn as nn
import torch.nn.functional as F
from .conv import BaseConv3d
from .norm import get_group_norm_3d, get_spatial_norm_3d
# ================================================... | 277 | 8,063 |
sglang | python/sglang/multimodal_gen/runtime/models/vaes/minimax_h3_video_vae/klvae.py | .py | # SPDX-License-Identifier: Apache-2.0
# MiniMax H3 visual VAE: 3D causal CNN encoder + ViT3D decoder (inference-only bundle).
import math
import os
from typing import List, Union
import numpy as np
import torch
import torch.distributed as dist
import torch.nn as nn
from diffusers.configuration_utils import ConfigMixin... | 1,298 | 49,694 |
sglang | python/sglang/multimodal_gen/runtime/models/vaes/parallel/diffusers_spatial.py | .py | import torch
import torch.nn as nn
from sglang.multimodal_gen.runtime.distributed.parallel_state import (
get_decode_parallel_rank,
get_decode_parallel_world_size,
)
from sglang.multimodal_gen.runtime.layers.parallel_conv import (
SpatialParallelConv2d,
chunk_height_by_sizes,
gather_and_trim_height... | 110 | 3,595 |
sglang | python/sglang/multimodal_gen/runtime/models/vaes/minimax_h3_audio_vae/alias_free.py | .py | # SPDX-License-Identifier: Apache-2.0
# Adapted from https://github.com/junjun3518/alias-free-torch under the Apache License 2.0
import math
import torch
import torch.nn as nn
import torch.nn.functional as F
if "sinc" in dir(torch):
sinc = torch.sinc
else:
# This code is adopted from adefossez's julius.core.... | 178 | 5,491 |
sglang | python/sglang/multimodal_gen/runtime/models/vaes/minimax_h3_audio_vae/bigvgan.py | .py | # SPDX-License-Identifier: MIT
# Copyright (c) 2024 NVIDIA CORPORATION.
# Licensed under the MIT license.
# Adapted from https://github.com/jik876/hifi-gan under the MIT license.
import torch
import torch.nn as nn
from torch.nn import Conv1d, ConvTranspose1d, Parameter
from torch.nn.utils.parametrizations import we... | 256 | 8,425 |
sglang | python/sglang/multimodal_gen/runtime/models/vaes/minimax_h3_audio_vae/__init__.py | .py | # SPDX-License-Identifier: Apache-2.0
from .audio_vae import DacAudioVAE
__all__ = ["DacAudioVAE"]
| 6 | 101 |
sglang | python/sglang/multimodal_gen/runtime/models/vaes/minimax_h3_audio_vae/audio_vae.py | .py | # SPDX-License-Identifier: Apache-2.0
# DAC-lineage audio VAE: waveform encoder + BigVGAN decoder (inference-only bundle).
import math
from typing import List
import numpy as np
import torch
import torch.nn.functional as F
from torch import nn
from torch.nn.utils.parametrizations import weight_norm
from sglang.multim... | 341 | 11,393 |
sglang | python/sglang/multimodal_gen/runtime/vla/cuda_graph.py | .py | # SPDX-License-Identifier: Apache-2.0
from __future__ import annotations
from dataclasses import dataclass
from typing import Any, Callable
import torch
from sglang.multimodal_gen.runtime.utils.logging_utils import init_logger
from sglang.multimodal_gen.runtime.vla.prefix_cache import (
PrefixContext,
VLADe... | 330 | 11,422 |
sglang | python/sglang/multimodal_gen/runtime/vla/parallel.py | .py | # SPDX-License-Identifier: Apache-2.0
from __future__ import annotations
from dataclasses import dataclass
import torch
import torch.distributed as dist
from sglang.multimodal_gen.runtime.distributed import (
get_sp_group,
model_parallel_is_initialized,
)
from sglang.multimodal_gen.runtime.distributed.group... | 162 | 5,060 |
sglang | python/sglang/multimodal_gen/runtime/vla/__init__.py | .py | # SPDX-License-Identifier: Apache-2.0
"""Shared VLA runtime contracts and execution infrastructure."""
| 4 | 104 |
sglang | python/sglang/multimodal_gen/runtime/vla/prefix_cache.py | .py | # SPDX-License-Identifier: Apache-2.0
from __future__ import annotations
import hashlib
import json
from collections import OrderedDict
from collections.abc import Iterable
from dataclasses import dataclass, field
from typing import Any
import torch
@dataclass
class PrefixContext:
"""Request-local observation ... | 172 | 5,845 |
sglang | python/sglang/multimodal_gen/runtime/vla/observation.py | .py | # SPDX-License-Identifier: Apache-2.0
from __future__ import annotations
from dataclasses import dataclass, field
from typing import Any
import torch
from sglang.srt.managers.mm_utils import tensor_hash
@dataclass
class VLAObservationBatch:
prompt: list[str]
images: dict[str, torch.Tensor]
image_masks... | 77 | 2,423 |
sglang | python/sglang/multimodal_gen/runtime/cache/cache_dit_integration.py | .py | # SPDX-License-Identifier: Apache-2.0
"""
cache-dit integration module for SGLang DiT pipelines.
This module provides helper functions to enable cache-dit acceleration
on transformer modules in SGLang's modular pipeline architecture.
"""
from dataclasses import dataclass
from typing import List, Optional
import torc... | 710 | 27,247 |
sglang | python/sglang/multimodal_gen/runtime/cache/__init__.py | .py | # SPDX-License-Identifier: Apache-2.0
"""
Cache acceleration module for SGLang-diffusion
This module provides various caching strategies to accelerate
diffusion transformer (DiT) inference:
- TeaCache: Temporal similarity-based caching for diffusion models
- Spectrum: Chebyshev spectral feature forecasting for step s... | 35 | 1,084 |
sglang | python/sglang/multimodal_gen/runtime/cache/teacache.py | .py | # SPDX-License-Identifier: Apache-2.0
"""
TeaCache: Temporal similarity-based caching for diffusion models.
TeaCache accelerates diffusion inference by selectively skipping redundant
computation when consecutive diffusion steps are similar enough. This is
achieved by tracking the L1 distance between modulated inputs a... | 313 | 12,515 |
sglang | python/sglang/multimodal_gen/runtime/cache/spectrum.py | .py | # SPDX-License-Identifier: Apache-2.0
"""
Spectrum: Adaptive Spectral Feature Forecasting for diffusion sampling acceleration.
Training-free step skipping with Chebyshev polynomial ridge regression over
denoiser block outputs. See https://arxiv.org/abs/2603.01623
"""
from __future__ import annotations
import logging... | 647 | 26,404 |
sglang | python/sglang/multimodal_gen/runtime/loader/utils.py | .py | # Copied and adapted from: https://github.com/hao-ai-lab/FastVideo
# SPDX-License-Identifier: Apache-2.0
"""Utilities for selecting and loading models."""
import contextlib
import glob
import json
import os
import re
from collections import defaultdict
from collections.abc import Callable, Iterator
from typing import... | 338 | 12,620 |
sglang | python/sglang/multimodal_gen/runtime/loader/rank_local_checkpoint.py | .py | # SPDX-License-Identifier: Apache-2.0
from collections import defaultdict
from collections.abc import Callable
from contextlib import ExitStack
from dataclasses import dataclass
from types import MethodType
from typing import Any
import torch
import torch.distributed.tensor as dist_tensor
from safetensors.torch impor... | 540 | 17,879 |
sglang | python/sglang/multimodal_gen/runtime/loader/transformer_load_utils.py | .py | """Helpers and adapters for transformer quantized checkpoint loading.
This module keeps format-specific loading quirks out of `TransformerLoader`.
The loader should stay focused on the generic load flow, while special cases
such as Nunchaku validation, NVFP4 fallback adjustments, and post-load patching
are handled her... | 800 | 29,241 |
sglang | python/sglang/multimodal_gen/runtime/loader/weight_load_plan.py | .py | from dataclasses import dataclass
import torch
@dataclass(frozen=True)
class WeightLoadPlan:
"""Device plan for checkpoint loading, before runtime residency takes over."""
# Device used while materializing checkpoint tensors from files.
checkpoint_load_device: torch.device
# Device required while ru... | 40 | 1,536 |
sglang | python/sglang/multimodal_gen/runtime/loader/fsdp_load.py | .py | # Copied and adapted from: https://github.com/hao-ai-lab/FastVideo
# SPDX-License-Identifier: Apache-2.0
# Adapted from torchtune
# Copyright 2024 The TorchTune Authors.
# Copyright 2025 The sglang-diffusion Authors.
from collections import Counter, defaultdict
from collections.abc import Callable, Generator
from it... | 934 | 36,591 |
sglang | python/sglang/multimodal_gen/runtime/loader/weight_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/model_loader/weight_utils.py
"""Utilities for downloading, loading, initializing and verifying model weights."""
import has... | 451 | 18,158 |
sglang | python/sglang/multimodal_gen/runtime/loader/component_loaders/bridge_loader.py | .py | from copy import deepcopy
import torch
from sglang.multimodal_gen.runtime.distributed import get_local_torch_device
from sglang.multimodal_gen.runtime.loader.component_loaders.component_loader import (
ComponentLoader,
)
from sglang.multimodal_gen.runtime.loader.fsdp_load import maybe_load_fsdp_model
from sglang.... | 124 | 5,040 |
sglang | python/sglang/multimodal_gen/runtime/loader/component_loaders/transformer_loader.py | .py | import copy
import logging
from collections.abc import Callable
from contextlib import nullcontext
from typing import Any
import torch
from sglang.multimodal_gen.runtime.distributed import get_local_torch_device
from sglang.multimodal_gen.runtime.layers.attention.selector import (
component_attn_backend_context_m... | 331 | 13,260 |
sglang | python/sglang/multimodal_gen/runtime/loader/component_loaders/component_loader.py | .py | # Copied and adapted from: https://github.com/hao-ai-lab/FastVideo
# SPDX-License-Identifier: Apache-2.0
import importlib
import os
import pkgutil
import traceback
from abc import ABC
from typing import Any, Type
import torch
from diffusers import AutoModel
from torch import nn
from transformers import AutoImageProc... | 539 | 19,534 |
sglang | python/sglang/multimodal_gen/runtime/loader/component_loaders/sound_tokenizer_loader.py | .py | # SPDX-License-Identifier: Apache-2.0
from safetensors.torch import load_file as safetensors_load_file
from sglang.multimodal_gen.runtime.loader.component_loaders.component_loader import (
ComponentLoader,
)
from sglang.multimodal_gen.runtime.loader.utils import (
_list_safetensors_files,
set_default_torch... | 73 | 2,859 |
sglang | python/sglang/multimodal_gen/runtime/loader/component_loaders/upsampler_loader.py | .py | import glob
import json
import os
import re
import safetensors
import torch
from safetensors.torch import load_file as safetensors_load_file
from sglang.multimodal_gen.runtime.loader.component_loaders.component_loader import (
ComponentLoader,
)
from sglang.multimodal_gen.runtime.models.upsampler.latent_upsampler... | 229 | 8,003 |
sglang | python/sglang/multimodal_gen/runtime/loader/component_loaders/text_encoder_loader.py | .py | import dataclasses
import glob
import os
import re
from collections.abc import Callable, Generator, Iterable
from contextlib import nullcontext
from typing import cast
import torch
from torch import nn
from transformers.utils import SAFE_WEIGHTS_INDEX_NAME
from sglang.multimodal_gen.configs.models import EncoderConfi... | 490 | 18,698 |
sglang | python/sglang/multimodal_gen/runtime/loader/component_loaders/adapter_loader.py | .py | import re
from sglang.multimodal_gen.configs.models.adapter.ltx_2_connector import (
LTX2ConnectorConfig,
)
from sglang.multimodal_gen.configs.models.adapter.ltx_2_duration_head import (
LTX2DurationHeadConfig,
)
from sglang.multimodal_gen.runtime.loader.component_loaders.component_loader import (
Componen... | 105 | 3,984 |
sglang | python/sglang/multimodal_gen/runtime/loader/component_loaders/vocoder_loader.py | .py | import re
from safetensors.torch import load_file as safetensors_load_file
from sglang.multimodal_gen.runtime.loader.component_loaders.component_loader import (
ComponentLoader,
)
from sglang.multimodal_gen.runtime.loader.utils import (
_list_safetensors_files,
set_default_torch_dtype,
skip_init_modul... | 87 | 3,481 |
sglang | python/sglang/multimodal_gen/runtime/loader/component_loaders/scheduler_loader.py | .py | import inspect
from sglang.multimodal_gen.runtime.loader.component_loaders.component_loader import (
ComponentLoader,
)
from sglang.multimodal_gen.runtime.models.registry import ModelRegistry
from sglang.multimodal_gen.runtime.server_args import ServerArgs
from sglang.multimodal_gen.runtime.utils.hf_diffusers_util... | 71 | 2,801 |
sglang | python/sglang/multimodal_gen/runtime/loader/component_loaders/vl_encoder_loader.py | .py | import logging
from typing import Any
import requests
from sglang.multimodal_gen.runtime.loader.component_loaders.component_loader import (
ComponentLoader,
)
from sglang.multimodal_gen.runtime.server_args import ServerArgs
from sglang.multimodal_gen.runtime.utils.hf_diffusers_utils import get_hf_config
logger =... | 75 | 3,036 |
sglang | python/sglang/multimodal_gen/runtime/loader/component_loaders/vae_loader.py | .py | import importlib.util
import os
import torch
import torch.nn as nn
from safetensors.torch import load_file as safetensors_load_file
from sglang.multimodal_gen.configs.pipeline_configs.ltx_2 import LTX2PipelineConfig
from sglang.multimodal_gen.configs.pipeline_configs.qwen_image import (
QwenImagePipelineConfig,
)... | 212 | 8,507 |
sglang | python/sglang/multimodal_gen/runtime/loader/component_loaders/pe_loader.py | .py | # SPDX-License-Identifier: Apache-2.0
import json
import os
import requests
import torch
from torch import nn
from transformers import AutoTokenizer
from sglang.multimodal_gen.runtime.distributed import get_local_torch_device
from sglang.multimodal_gen.runtime.loader.component_loaders.component_loader import (
Co... | 196 | 6,745 |
sglang | python/sglang/multimodal_gen/runtime/loader/component_loaders/image_encoder_loader.py | .py | from sglang.multimodal_gen.runtime.loader.component_loaders.text_encoder_loader import (
TextEncoderLoader,
)
from sglang.multimodal_gen.runtime.models.encoders.base import finalize_encoder_folding
from sglang.multimodal_gen.runtime.server_args import ServerArgs
from sglang.multimodal_gen.runtime.utils.hf_diffusers... | 52 | 1,897 |
sglang | python/sglang/multimodal_gen/runtime/loader/component_loaders/diffusion_decoder_loader.py | .py | # SPDX-License-Identifier: Apache-2.0
from sglang.multimodal_gen.configs.models.decoders.ltx_2_5_diffusion_decoder import (
LTX25DiffusionDecoderConfig,
)
from sglang.multimodal_gen.runtime.loader.component_loaders.component_loader import (
ComponentLoader,
)
from sglang.multimodal_gen.runtime.loader.utils imp... | 63 | 2,321 |
sglang | python/sglang/srt/environ.py | .py | import functools
import json
import os
import subprocess
import warnings
from contextlib import ExitStack, contextmanager
from enum import IntEnum
from typing import Any, Dict, Optional
@functools.lru_cache(maxsize=1)
def _default_hip() -> bool:
"""Lazy ROCm/HIP detection for platform-conditional env defaults.
... | 1,735 | 88,786 |
sglang | python/sglang/srt/server_args_config_parser.py | .py | """
Configuration argument parser for command-line applications.
Handles merging of YAML configuration files with command-line arguments.
"""
import argparse
import json
import logging
from pathlib import Path
from typing import Any, Dict, List
import yaml
logger = logging.getLogger(__name__)
class ConfigArgumentM... | 188 | 6,655 |
sglang | python/sglang/srt/constants.py | .py | # GPU Memory Types
GPU_MEMORY_TYPE_KV_CACHE = "kv_cache"
GPU_MEMORY_TYPE_WEIGHTS = "weights"
GPU_MEMORY_TYPE_CUDA_GRAPH = "cuda_graph"
GPU_MEMORY_ALL_TYPES = [
GPU_MEMORY_TYPE_KV_CACHE,
GPU_MEMORY_TYPE_WEIGHTS,
GPU_MEMORY_TYPE_CUDA_GRAPH,
]
HEALTH_CHECK_RID_PREFIX = "HEALTH_CHECK"
GIB_BYTES = 1073741824 ... | 15 | 331 |
sglang | python/sglang/srt/cuda_vmm_utils.py | .py | import array
import ctypes
import logging
import os
import socket
import struct
import tempfile
import threading
import time
from functools import cache
from typing import Any, List, Optional
import torch
import torch.distributed as dist
from torch.distributed import ProcessGroup
from sglang.srt.utils import log_info... | 1,067 | 39,818 |
sglang | python/sglang/srt/runtime_context.py | .py | # Copyright 2023-2026 SGLang Team
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writin... | 1,661 | 67,002 |
sglang | python/sglang/srt/server_args.py | .py | # Copyright 2023-2024 SGLang Team
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writin... | 9,892 | 440,155 |
sglang | python/sglang/srt/speculative/draft_worker_common.py | .py | from __future__ import annotations
import logging
from typing import TYPE_CHECKING, Optional
import msgspec
import torch
from sglang.srt.layers.logits_processor import LogitsProcessorOutput
from sglang.srt.managers.tp_worker import TpModelWorker
from sglang.srt.model_executor.forward_batch_info import CaptureHiddenM... | 162 | 5,741 |
sglang | python/sglang/srt/speculative/eagle_worker_common.py | .py | from __future__ import annotations
from typing import TYPE_CHECKING, Any, Optional
import torch
from sglang.kernels.ops.speculative.cache_locs import (
assign_draft_cache_locs_contiguous,
)
from sglang.kernels.ops.speculative.eagle import fill_bonus_tokens_func
from sglang.srt.layers.logprob_processor import com... | 662 | 25,669 |
sglang | python/sglang/srt/speculative/eagle_draft_extend_cuda_graph_runner.py | .py | from __future__ import annotations
import contextlib
from dataclasses import dataclass
from typing import TYPE_CHECKING, Callable, Optional
import torch
from sglang.srt.compilation.torch_compile_decoration import set_torch_compile_config
from sglang.srt.layers.dp_attention import (
DpPaddingMode,
set_dp_buff... | 610 | 24,979 |
sglang | python/sglang/srt/speculative/draft_utils.py | .py | from sglang.srt.runtime_context import attention_backends, get_spec
from sglang.srt.utils.common import (
cpu_has_amx_support,
is_blackwell,
is_cpu,
is_hip,
is_musa,
is_npu,
)
def _assert_draft_needs_no_conv_sidecar(draft_model_runner) -> None:
"""Refuse a multi-step draft decode backend f... | 532 | 19,265 |
sglang | python/sglang/srt/speculative/standalone_worker_v2.py | .py | import logging
from dataclasses import replace
from typing import Optional
import torch
from sglang.srt.distributed.parallel_state_wrapper import ParallelState
from sglang.srt.layers.moe.utils import (
draft_model_build_scope,
speculative_moe_backend_context,
)
from sglang.srt.managers.tp_worker import TpMode... | 228 | 8,715 |
sglang | python/sglang/srt/speculative/spec_info.py | .py | from __future__ import annotations
import warnings
from abc import ABC
from enum import Enum, IntEnum, auto
from typing import TYPE_CHECKING, Callable, List, Optional, Tuple, Type, Union
import torch
from sglang.srt.speculative.spec_registry import (
CustomSpecAlgo,
ServerArgsValidator,
WorkerFactory,
)
... | 456 | 17,005 |
sglang | python/sglang/srt/speculative/multi_layer_eagle_worker_v2.py | .py | # Copyright 2023-2024 SGLang Team
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writin... | 1,043 | 43,714 |
sglang | python/sglang/srt/speculative/adaptive_spec_params.py | .py | """Adaptive speculative decoding parameters.
Adjusts speculative_num_steps at runtime based on observed acceptance lengths.
"""
from __future__ import annotations
import bisect
import json
import logging
import math
from functools import cached_property
from typing import TYPE_CHECKING
from sglang.srt.utils import ... | 346 | 12,494 |
sglang | python/sglang/srt/speculative/multi_layer_eagle_draft_extend_cuda_graph_runner.py | .py | # Copyright 2023-2024 SGLang Team
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writin... | 990 | 41,204 |
sglang | python/sglang/srt/speculative/dflash_utils.py | .py | from __future__ import annotations
import logging
from collections.abc import Sequence
from dataclasses import dataclass
from numbers import Integral
from typing import Any, List, Optional, Tuple
import torch
import torch.nn.functional as F
import triton
import triton.language as tl
from sglang.srt.layers.quantizati... | 1,057 | 37,847 |
sglang | python/sglang/srt/speculative/ngram_worker.py | .py | import logging
from typing import List, Optional
import numpy as np
import torch
from sgl_kernel.speculative import reconstruct_indices_from_tree_mask
from sglang.kernels.ops.speculative.cache_locs import (
assign_extend_cache_locs_func as assign_extend_cache_locs_func,
)
from sglang.srt.distributed.parallel_stat... | 547 | 23,418 |
sglang | python/sglang/srt/speculative/dflash_worker_v2.py | .py | import logging
import math
from dataclasses import replace
from typing import List, Optional
import torch
from sglang.kernels.ops.speculative.cache_locs import (
assign_extend_cache_locs_func,
rebuild_compact_draft_req_to_token_func,
)
from sglang.kernels.ops.speculative.dflash import (
_compute_dflash_ac... | 1,961 | 84,663 |
sglang | python/sglang/srt/speculative/dflash_info_v2.py | .py | """DFLASH spec-v2 overlap scheduling data structures."""
import contextlib
from dataclasses import dataclass
from typing import List, Optional
import torch
from sglang.srt.environ import envs
from sglang.srt.managers.schedule_batch import ScheduleBatch
from sglang.srt.mem_cache.allocation import alloc_for_spec_decod... | 268 | 11,789 |
sglang | python/sglang/srt/speculative/frozen_kv_mtp_cuda_graph_runner.py | .py | from __future__ import annotations
from dataclasses import dataclass
from typing import TYPE_CHECKING, Callable, Optional
import torch
from sglang.srt.compilation.torch_compile_decoration import set_torch_compile_config
from sglang.srt.layers.dp_attention import (
DpPaddingMode,
set_dp_buffer_len,
set_is... | 473 | 20,416 |
sglang | python/sglang/srt/speculative/dflash_info.py | .py | from __future__ import annotations
from dataclasses import dataclass
from typing import TYPE_CHECKING, Optional
import torch
from sglang.kernels.ops.attention.utils import create_flashinfer_kv_indices_triton
from sglang.srt.managers.schedule_batch import ScheduleBatch
from sglang.srt.model_executor.forward_batch_inf... | 175 | 6,568 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.