Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
11 changes: 10 additions & 1 deletion python/sglang/srt/configs/deepseekvl2.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
from typing import Dict, List, Optional, Tuple

import torch
import torchvision.transforms as T
from PIL import Image, ImageOps
from transformers import (
AutoProcessor,
Expand Down Expand Up @@ -76,6 +75,16 @@ def __init__(
self.std = std
self.normalize = normalize

# only load torchvision.transforms when needed
try:
import torchvision.transforms as T

# FIXME: add version check for gguf
except ImportError as err:
raise ImportError(
"Please install torchvision via `pip install torchvision` to use Deepseek-VL2."
) from err

transform_pipelines = [T.ToTensor()]

if normalize:
Expand Down
12 changes: 11 additions & 1 deletion python/sglang/srt/model_loader/loader.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
from contextlib import contextmanager
from typing import Any, Dict, Generator, Iterable, List, Optional, Tuple, cast

import gguf
import huggingface_hub
import numpy as np
import torch
Expand Down Expand Up @@ -1155,6 +1154,17 @@ def _get_gguf_weights_map(self, model_config: ModelConfig):
See "Standardized tensor names" in
https://github.com/ggerganov/ggml/blob/master/docs/gguf.md for details.
"""

# only load the gguf module when needed
try:
import gguf

# FIXME: add version check for gguf
except ImportError as err:
raise ImportError(
"Please install gguf via `pip install gguf` to use gguf quantizer."
) from err

config = model_config.hf_config
model_type = config.model_type
# hack: ggufs have a different name than transformers
Expand Down
5 changes: 4 additions & 1 deletion python/sglang/srt/model_loader/weight_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
)

import filelock
import gguf
import huggingface_hub.constants
import numpy as np
import safetensors.torch
Expand Down Expand Up @@ -464,6 +463,8 @@ def pt_weights_iterator(
def get_gguf_extra_tensor_names(
gguf_file: str, gguf_to_hf_name_map: Dict[str, str]
) -> List[str]:
import gguf

reader = gguf.GGUFReader(gguf_file)
expected_gguf_keys = set(gguf_to_hf_name_map.keys())
exact_gguf_keys = set([tensor.name for tensor in reader.tensors])
Expand All @@ -479,6 +480,8 @@ def gguf_quant_weights_iterator(
them to torch tensors
"""

import gguf

reader = gguf.GGUFReader(gguf_file)

for tensor in reader.tensors:
Expand Down
Loading