Fix env (docker) compat due to __file__ usage (#288)
This commit is contained in:
@@ -4,6 +4,7 @@ import inspect
|
|||||||
from dataclasses import dataclass
|
from dataclasses import dataclass
|
||||||
from functools import lru_cache
|
from functools import lru_cache
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
|
import importlib.resources
|
||||||
|
|
||||||
import numpy as np
|
import numpy as np
|
||||||
import torch
|
import torch
|
||||||
@@ -31,8 +32,10 @@ global_server_args_dict: dict = None
|
|||||||
@lru_cache()
|
@lru_cache()
|
||||||
def import_model_classes():
|
def import_model_classes():
|
||||||
model_arch_name_to_cls = {}
|
model_arch_name_to_cls = {}
|
||||||
for module_path in (Path(sglang.__file__).parent / "srt" / "models").glob("*.py"):
|
for f in importlib.resources.files("sglang.srt.models").iterdir():
|
||||||
module = importlib.import_module(f"sglang.srt.models.{module_path.stem}")
|
if f.name.endswith(".py"):
|
||||||
|
module_name = Path(f.name).with_suffix('')
|
||||||
|
module = importlib.import_module(f"sglang.srt.models.{module_name}")
|
||||||
if hasattr(module, "EntryClass"):
|
if hasattr(module, "EntryClass"):
|
||||||
model_arch_name_to_cls[module.EntryClass.__name__] = module.EntryClass
|
model_arch_name_to_cls[module.EntryClass.__name__] = module.EntryClass
|
||||||
return model_arch_name_to_cls
|
return model_arch_name_to_cls
|
||||||
|
|||||||
Reference in New Issue
Block a user