Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
change
sglang
Commits
79f81629
Unverified
Commit
79f81629
authored
Jul 28, 2024
by
Ying Sheng
Committed by
GitHub
Jul 28, 2024
Browse files
Fix lazy import location (#795)
parent
b688fd85
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
24 additions
and
25 deletions
+24
-25
python/sglang/__init__.py
python/sglang/__init__.py
+2
-25
python/sglang/utils.py
python/sglang/utils.py
+22
-0
No files found.
python/sglang/__init__.py
View file @
79f81629
import
importlib
class
LazyImport
:
def
__init__
(
self
,
module_name
,
class_name
):
self
.
module_name
=
module_name
self
.
class_name
=
class_name
self
.
_module
=
None
def
_load
(
self
):
if
self
.
_module
is
None
:
module
=
importlib
.
import_module
(
self
.
module_name
)
self
.
_module
=
getattr
(
module
,
self
.
class_name
)
return
self
.
_module
def
__getattr__
(
self
,
name
):
module
=
self
.
_load
()
return
getattr
(
module
,
name
)
def
__call__
(
self
,
*
args
,
**
kwargs
):
module
=
self
.
_load
()
return
module
(
*
args
,
**
kwargs
)
# SGL API Components
from
sglang.api
import
(
Runtime
,
...
...
@@ -49,13 +25,14 @@ from sglang.global_config import global_config
# SGL Backends
from
sglang.lang.backend.runtime_endpoint
import
RuntimeEndpoint
from
sglang.utils
import
LazyImport
from
sglang.version
import
__version__
Anthropic
=
LazyImport
(
"sglang.lang.backend.anthropic"
,
"Anthropic"
)
LiteLLM
=
LazyImport
(
"sglang.lang.backend.litellm"
,
"LiteLLM"
)
OpenAI
=
LazyImport
(
"sglang.lang.backend.openai"
,
"OpenAI"
)
VertexAI
=
LazyImport
(
"sglang.lang.backend.vertexai"
,
"VertexAI"
)
from
.version
import
__version__
# public APIs management
__all__
=
[
...
...
python/sglang/utils.py
View file @
79f81629
"""Common utilities."""
import
base64
import
importlib
import
json
import
logging
import
signal
...
...
@@ -261,3 +262,24 @@ def graceful_registry(sub_module_name):
logger
.
info
(
f
"
{
sub_module_name
}
recive sigterm"
)
signal
.
signal
(
signal
.
SIGTERM
,
graceful_shutdown
)
class
LazyImport
:
def
__init__
(
self
,
module_name
,
class_name
):
self
.
module_name
=
module_name
self
.
class_name
=
class_name
self
.
_module
=
None
def
_load
(
self
):
if
self
.
_module
is
None
:
module
=
importlib
.
import_module
(
self
.
module_name
)
self
.
_module
=
getattr
(
module
,
self
.
class_name
)
return
self
.
_module
def
__getattr__
(
self
,
name
):
module
=
self
.
_load
()
return
getattr
(
module
,
name
)
def
__call__
(
self
,
*
args
,
**
kwargs
):
module
=
self
.
_load
()
return
module
(
*
args
,
**
kwargs
)
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment