fix: prevent HugginqFace access when SGLANG_USE_MODELSCOPE is enabled (#12039)
This commit is contained in:
@@ -524,12 +524,17 @@ class ModelConfig:
|
|||||||
# example: https://huggingface.co/Barrrrry/DeepSeek-R1-W4AFP8/tree/main
|
# example: https://huggingface.co/Barrrrry/DeepSeek-R1-W4AFP8/tree/main
|
||||||
is_local = os.path.exists(self.model_path)
|
is_local = os.path.exists(self.model_path)
|
||||||
if not is_local:
|
if not is_local:
|
||||||
import huggingface_hub
|
# Conditional import based on SGLANG_USE_MODELSCOPE environment variable
|
||||||
|
if envs.SGLANG_USE_MODELSCOPE is True:
|
||||||
|
from modelscope import HubApi, model_file_download
|
||||||
|
|
||||||
try:
|
hf_api = HubApi()
|
||||||
|
else:
|
||||||
|
import huggingface_hub
|
||||||
from huggingface_hub import HfApi, hf_hub_download
|
from huggingface_hub import HfApi, hf_hub_download
|
||||||
|
|
||||||
hf_api = HfApi()
|
hf_api = HfApi()
|
||||||
|
try:
|
||||||
# Retry HF API call up to 3 times
|
# Retry HF API call up to 3 times
|
||||||
file_exists = retry(
|
file_exists = retry(
|
||||||
lambda: hf_api.file_exists(
|
lambda: hf_api.file_exists(
|
||||||
@@ -541,11 +546,18 @@ class ModelConfig:
|
|||||||
)
|
)
|
||||||
if file_exists:
|
if file_exists:
|
||||||
# Download and parse the quantization config for remote models
|
# Download and parse the quantization config for remote models
|
||||||
quant_config_file = hf_hub_download(
|
if envs.SGLANG_USE_MODELSCOPE.get():
|
||||||
repo_id=self.model_path,
|
quant_config_file = model_file_download(
|
||||||
filename="hf_quant_config.json",
|
model_id=self.model_path,
|
||||||
revision=self.revision,
|
file_path="hf_quant_config.json",
|
||||||
)
|
revision=self.revision,
|
||||||
|
)
|
||||||
|
else:
|
||||||
|
quant_config_file = hf_hub_download(
|
||||||
|
repo_id=self.model_path,
|
||||||
|
filename="hf_quant_config.json",
|
||||||
|
revision=self.revision,
|
||||||
|
)
|
||||||
with open(quant_config_file) as f:
|
with open(quant_config_file) as f:
|
||||||
quant_config_dict = json.load(f)
|
quant_config_dict = json.load(f)
|
||||||
quant_cfg = self._parse_modelopt_quant_config(quant_config_dict)
|
quant_cfg = self._parse_modelopt_quant_config(quant_config_dict)
|
||||||
|
|||||||
@@ -24,11 +24,18 @@ from typing import Any, Dict, List, Optional, Type, Union
|
|||||||
|
|
||||||
import torch
|
import torch
|
||||||
from huggingface_hub import snapshot_download
|
from huggingface_hub import snapshot_download
|
||||||
|
|
||||||
|
from sglang.srt.utils import get_bool_env_var
|
||||||
|
|
||||||
|
# Conditional import based on SGLANG_USE_MODELSCOPE environment variable
|
||||||
|
if get_bool_env_var("SGLANG_USE_MODELSCOPE"):
|
||||||
|
from modelscope import AutoConfig, GenerationConfig
|
||||||
|
else:
|
||||||
|
from transformers import AutoConfig, GenerationConfig
|
||||||
|
|
||||||
from transformers import (
|
from transformers import (
|
||||||
AutoConfig,
|
|
||||||
AutoProcessor,
|
AutoProcessor,
|
||||||
AutoTokenizer,
|
AutoTokenizer,
|
||||||
GenerationConfig,
|
|
||||||
PretrainedConfig,
|
PretrainedConfig,
|
||||||
PreTrainedTokenizer,
|
PreTrainedTokenizer,
|
||||||
PreTrainedTokenizerBase,
|
PreTrainedTokenizerBase,
|
||||||
|
|||||||
Reference in New Issue
Block a user