spaces 0.52.0.dev1__tar.gz → 0.52.0.dev3__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {spaces-0.52.0.dev1 → spaces-0.52.0.dev3}/PKG-INFO +1 -1
- {spaces-0.52.0.dev1 → spaces-0.52.0.dev3}/pyproject.toml +1 -1
- {spaces-0.52.0.dev1 → spaces-0.52.0.dev3}/spaces/__init__.py +2 -2
- {spaces-0.52.0.dev1 → spaces-0.52.0.dev3}/spaces/zero/__init__.py +6 -0
- {spaces-0.52.0.dev1 → spaces-0.52.0.dev3}/spaces/zero/client.py +4 -4
- {spaces-0.52.0.dev1 → spaces-0.52.0.dev3}/spaces/zero/context.py +24 -1
- {spaces-0.52.0.dev1 → spaces-0.52.0.dev3}/spaces/zero/gradio.py +83 -51
- {spaces-0.52.0.dev1 → spaces-0.52.0.dev3}/spaces/zero/middleware.py +5 -9
- {spaces-0.52.0.dev1 → spaces-0.52.0.dev3}/spaces/zero/wrappers.py +3 -3
- {spaces-0.52.0.dev1 → spaces-0.52.0.dev3}/README.md +0 -0
- {spaces-0.52.0.dev1 → spaces-0.52.0.dev3}/spaces/_vendor/__init__.py +0 -0
- {spaces-0.52.0.dev1 → spaces-0.52.0.dev3}/spaces/_vendor/asgiref/__init__.py +0 -0
- {spaces-0.52.0.dev1 → spaces-0.52.0.dev3}/spaces/_vendor/asgiref/typing.py +0 -0
- {spaces-0.52.0.dev1 → spaces-0.52.0.dev3}/spaces/_vendor/codefind/LICENSE +0 -0
- {spaces-0.52.0.dev1 → spaces-0.52.0.dev3}/spaces/_vendor/codefind/__init__.py +0 -0
- {spaces-0.52.0.dev1 → spaces-0.52.0.dev3}/spaces/_vendor/codefind/registry.py +0 -0
- {spaces-0.52.0.dev1 → spaces-0.52.0.dev3}/spaces/_vendor/codefind/version.py +0 -0
- {spaces-0.52.0.dev1 → spaces-0.52.0.dev3}/spaces/_vendor/jurigged/LICENSE +0 -0
- {spaces-0.52.0.dev1 → spaces-0.52.0.dev3}/spaces/_vendor/jurigged/__init__.py +0 -0
- {spaces-0.52.0.dev1 → spaces-0.52.0.dev3}/spaces/_vendor/jurigged/codetools.py +0 -0
- {spaces-0.52.0.dev1 → spaces-0.52.0.dev3}/spaces/_vendor/jurigged/parse.py +0 -0
- {spaces-0.52.0.dev1 → spaces-0.52.0.dev3}/spaces/_vendor/jurigged/register.py +0 -0
- {spaces-0.52.0.dev1 → spaces-0.52.0.dev3}/spaces/_vendor/jurigged/utils.py +0 -0
- {spaces-0.52.0.dev1 → spaces-0.52.0.dev3}/spaces/_vendor/jurigged/version.py +0 -0
- {spaces-0.52.0.dev1 → spaces-0.52.0.dev3}/spaces/_vendor/ovld/LICENSE +0 -0
- {spaces-0.52.0.dev1 → spaces-0.52.0.dev3}/spaces/_vendor/ovld/__init__.py +0 -0
- {spaces-0.52.0.dev1 → spaces-0.52.0.dev3}/spaces/_vendor/ovld/abc.py +0 -0
- {spaces-0.52.0.dev1 → spaces-0.52.0.dev3}/spaces/_vendor/ovld/codegen.py +0 -0
- {spaces-0.52.0.dev1 → spaces-0.52.0.dev3}/spaces/_vendor/ovld/core.py +0 -0
- {spaces-0.52.0.dev1 → spaces-0.52.0.dev3}/spaces/_vendor/ovld/dependent.py +0 -0
- {spaces-0.52.0.dev1 → spaces-0.52.0.dev3}/spaces/_vendor/ovld/medley.py +0 -0
- {spaces-0.52.0.dev1 → spaces-0.52.0.dev3}/spaces/_vendor/ovld/mro.py +0 -0
- {spaces-0.52.0.dev1 → spaces-0.52.0.dev3}/spaces/_vendor/ovld/py.typed +0 -0
- {spaces-0.52.0.dev1 → spaces-0.52.0.dev3}/spaces/_vendor/ovld/recode.py +0 -0
- {spaces-0.52.0.dev1 → spaces-0.52.0.dev3}/spaces/_vendor/ovld/signatures.py +0 -0
- {spaces-0.52.0.dev1 → spaces-0.52.0.dev3}/spaces/_vendor/ovld/typemap.py +0 -0
- {spaces-0.52.0.dev1 → spaces-0.52.0.dev3}/spaces/_vendor/ovld/types.py +0 -0
- {spaces-0.52.0.dev1 → spaces-0.52.0.dev3}/spaces/_vendor/ovld/utils.py +0 -0
- {spaces-0.52.0.dev1 → spaces-0.52.0.dev3}/spaces/_vendor/ovld/version.py +0 -0
- {spaces-0.52.0.dev1 → spaces-0.52.0.dev3}/spaces/_vendor/sse_starlette/LICENSE +0 -0
- {spaces-0.52.0.dev1 → spaces-0.52.0.dev3}/spaces/_vendor/sse_starlette/__init__.py +0 -0
- {spaces-0.52.0.dev1 → spaces-0.52.0.dev3}/spaces/_vendor/sse_starlette/event.py +0 -0
- {spaces-0.52.0.dev1 → spaces-0.52.0.dev3}/spaces/_vendor/sse_starlette/py.typed +0 -0
- {spaces-0.52.0.dev1 → spaces-0.52.0.dev3}/spaces/_vendor/sse_starlette/sse.py +0 -0
- {spaces-0.52.0.dev1 → spaces-0.52.0.dev3}/spaces/_vendor/sseclient/LICENSE +0 -0
- {spaces-0.52.0.dev1 → spaces-0.52.0.dev3}/spaces/_vendor/sseclient/__init__.py +0 -0
- {spaces-0.52.0.dev1 → spaces-0.52.0.dev3}/spaces/config.py +0 -0
- {spaces-0.52.0.dev1 → spaces-0.52.0.dev3}/spaces/reloading/__init__.py +0 -0
- {spaces-0.52.0.dev1 → spaces-0.52.0.dev3}/spaces/reloading/client.py +0 -0
- {spaces-0.52.0.dev1 → spaces-0.52.0.dev3}/spaces/reloading/server.py +0 -0
- {spaces-0.52.0.dev1 → spaces-0.52.0.dev3}/spaces/reloading/types.py +0 -0
- {spaces-0.52.0.dev1 → spaces-0.52.0.dev3}/spaces/reloading/types.ts +0 -0
- {spaces-0.52.0.dev1 → spaces-0.52.0.dev3}/spaces/utils.py +0 -0
- {spaces-0.52.0.dev1 → spaces-0.52.0.dev3}/spaces/zero/api.py +0 -0
- {spaces-0.52.0.dev1 → spaces-0.52.0.dev3}/spaces/zero/config.py +0 -0
- {spaces-0.52.0.dev1 → spaces-0.52.0.dev3}/spaces/zero/configs.json +0 -0
- {spaces-0.52.0.dev1 → spaces-0.52.0.dev3}/spaces/zero/decorator.py +0 -0
- {spaces-0.52.0.dev1 → spaces-0.52.0.dev3}/spaces/zero/elf.py +0 -0
- {spaces-0.52.0.dev1 → spaces-0.52.0.dev3}/spaces/zero/lifecycle.py +0 -0
- {spaces-0.52.0.dev1 → spaces-0.52.0.dev3}/spaces/zero/mmap.py +0 -0
- {spaces-0.52.0.dev1 → spaces-0.52.0.dev3}/spaces/zero/torch/__init__.py +0 -0
- {spaces-0.52.0.dev1 → spaces-0.52.0.dev3}/spaces/zero/torch/aoti.py +0 -0
- {spaces-0.52.0.dev1 → spaces-0.52.0.dev3}/spaces/zero/torch/bitsandbytes.py +0 -0
- {spaces-0.52.0.dev1 → spaces-0.52.0.dev3}/spaces/zero/torch/bitsandbytes_legacy.py +0 -0
- {spaces-0.52.0.dev1 → spaces-0.52.0.dev3}/spaces/zero/torch/cudart.py +0 -0
- {spaces-0.52.0.dev1 → spaces-0.52.0.dev3}/spaces/zero/torch/packing.py +0 -0
- {spaces-0.52.0.dev1 → spaces-0.52.0.dev3}/spaces/zero/torch/patching.py +0 -0
- {spaces-0.52.0.dev1 → spaces-0.52.0.dev3}/spaces/zero/torch/patching_legacy.py +0 -0
- {spaces-0.52.0.dev1 → spaces-0.52.0.dev3}/spaces/zero/torch/static.py +0 -0
- {spaces-0.52.0.dev1 → spaces-0.52.0.dev3}/spaces/zero/torch/types.py +0 -0
- {spaces-0.52.0.dev1 → spaces-0.52.0.dev3}/spaces/zero/torch/utils.py +0 -0
- {spaces-0.52.0.dev1 → spaces-0.52.0.dev3}/spaces/zero/tqdm.py +0 -0
- {spaces-0.52.0.dev1 → spaces-0.52.0.dev3}/spaces/zero/types.py +0 -0
- {spaces-0.52.0.dev1 → spaces-0.52.0.dev3}/spaces/zero/utils.py +0 -0
|
@@ -19,8 +19,8 @@ if (gr := sys.modules.get('gradio')) is not None: # pragma: no cover
|
|
|
19
19
|
from .zero.decorator import GPU
|
|
20
20
|
|
|
21
21
|
|
|
22
|
-
def gradio_auto_wrap(
|
|
23
|
-
|
|
22
|
+
def gradio_auto_wrap(task): # pragma: no cover
|
|
23
|
+
return task
|
|
24
24
|
|
|
25
25
|
def disable_gradio_auto_wrap(*args, **kwargs): # pragma: no cover
|
|
26
26
|
warnings.warn("gradio_auto_wrap has no effect and is deprecated")
|
|
@@ -6,6 +6,7 @@ from importlib import metadata
|
|
|
6
6
|
from packaging.version import Version
|
|
7
7
|
|
|
8
8
|
from ..config import Config
|
|
9
|
+
from . import context
|
|
9
10
|
from .context import ZeroGPUError
|
|
10
11
|
from .context import ZeroGPUErrorResponse
|
|
11
12
|
from .context import ZeroGPUException
|
|
@@ -26,6 +27,7 @@ def _maybe_enable_gradio_compat():
|
|
|
26
27
|
if Version(gradio_version) < Version('7.0.0.dev0'):
|
|
27
28
|
from . import gradio
|
|
28
29
|
gradio.patch()
|
|
30
|
+
context.set_context_getter(gradio.get_zerogpu_context)
|
|
29
31
|
|
|
30
32
|
|
|
31
33
|
if Config.zero_gpu:
|
|
@@ -33,6 +35,10 @@ if Config.zero_gpu:
|
|
|
33
35
|
_maybe_enable_gradio_compat()
|
|
34
36
|
|
|
35
37
|
|
|
38
|
+
# Compat
|
|
39
|
+
startup = zerogpu_startup
|
|
40
|
+
|
|
41
|
+
|
|
36
42
|
__all__ = [
|
|
37
43
|
'ZeroGPUError',
|
|
38
44
|
'ZeroGPUErrorResponse',
|
|
@@ -11,6 +11,7 @@ from typing_extensions import assert_never
|
|
|
11
11
|
|
|
12
12
|
from ..config import Config
|
|
13
13
|
from . import config
|
|
14
|
+
from . import context
|
|
14
15
|
from . import default_gpu_size
|
|
15
16
|
from . import utils
|
|
16
17
|
from .api import APIClient
|
|
@@ -18,7 +19,6 @@ from .api import GPUSize
|
|
|
18
19
|
from .api import AuthLevel
|
|
19
20
|
from .api import QuotaInfos
|
|
20
21
|
from .api import ScheduleResponse
|
|
21
|
-
from .context import ctx_var
|
|
22
22
|
from .context import ZeroGPUContext
|
|
23
23
|
|
|
24
24
|
|
|
@@ -104,7 +104,7 @@ def schedule(
|
|
|
104
104
|
_first_attempt: bool = True,
|
|
105
105
|
) -> ScheduleResponse:
|
|
106
106
|
|
|
107
|
-
ctx =
|
|
107
|
+
ctx = context.get()
|
|
108
108
|
token, payload = _get_token_and_payload(ctx.headers)
|
|
109
109
|
if token is not None and (token_error := payload.get('error')):
|
|
110
110
|
message = f"Falling back to IP-based quotas ({token_error})"
|
|
@@ -287,7 +287,7 @@ def release(
|
|
|
287
287
|
allow_404: bool = False,
|
|
288
288
|
) -> None:
|
|
289
289
|
|
|
290
|
-
ctx =
|
|
290
|
+
ctx = context.get()
|
|
291
291
|
res = api_client().release(
|
|
292
292
|
allow_token=allow_token,
|
|
293
293
|
fail=fail,
|
|
@@ -327,7 +327,7 @@ def _get_token_and_payload(headers: dict[str, str]) -> tuple[str | None, dict[st
|
|
|
327
327
|
|
|
328
328
|
|
|
329
329
|
def duration_warning():
|
|
330
|
-
|
|
330
|
+
context.get().warning(
|
|
331
331
|
title="ZeroGPU duration",
|
|
332
332
|
message="GPU task is exceeding its requested duration and might be aborted",
|
|
333
333
|
)
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
"""
|
|
2
2
|
"""
|
|
3
3
|
|
|
4
|
+
from contextlib import contextmanager
|
|
4
5
|
from contextvars import ContextVar
|
|
5
6
|
from typing import Callable
|
|
6
7
|
from typing import Literal
|
|
@@ -119,4 +120,26 @@ class ZeroGPUContext:
|
|
|
119
120
|
return False
|
|
120
121
|
|
|
121
122
|
|
|
122
|
-
|
|
123
|
+
_context_var: ContextVar[ZeroGPUContext] = ContextVar('zerogpu_context', default=ZeroGPUContext())
|
|
124
|
+
_context_getter: Callable[[], ZeroGPUContext | None] | None = None
|
|
125
|
+
|
|
126
|
+
|
|
127
|
+
def get():
|
|
128
|
+
if _context_getter is not None:
|
|
129
|
+
if (ctx := _context_getter()) is not None:
|
|
130
|
+
return ctx
|
|
131
|
+
return _context_var.get()
|
|
132
|
+
|
|
133
|
+
|
|
134
|
+
@contextmanager
|
|
135
|
+
def set_context_var(value: ZeroGPUContext):
|
|
136
|
+
token = _context_var.set(value)
|
|
137
|
+
try:
|
|
138
|
+
yield
|
|
139
|
+
finally:
|
|
140
|
+
_context_var.reset(token)
|
|
141
|
+
|
|
142
|
+
|
|
143
|
+
def set_context_getter(context_getter: Callable[[], ZeroGPUContext | None]):
|
|
144
|
+
global _context_getter
|
|
145
|
+
_context_getter = context_getter
|
|
@@ -5,7 +5,7 @@ import os
|
|
|
5
5
|
from functools import wraps
|
|
6
6
|
from typing import Any
|
|
7
7
|
from typing import Literal
|
|
8
|
-
from typing import
|
|
8
|
+
from typing import cast
|
|
9
9
|
|
|
10
10
|
import gradio as gr
|
|
11
11
|
from fastapi import FastAPI
|
|
@@ -18,8 +18,13 @@ from gradio.routes import App
|
|
|
18
18
|
|
|
19
19
|
from ..utils import create_thread_daemon
|
|
20
20
|
from ..utils import SimpleQueue
|
|
21
|
+
from .context import ZeroGPUContext
|
|
22
|
+
from .context import ZeroGPUErrorResponse
|
|
23
|
+
from .context import ZeroGPULog
|
|
21
24
|
from .lifecycle import zerogpu_mode_enabled
|
|
22
25
|
from .lifecycle import zerogpu_startup
|
|
26
|
+
from .middleware import ASGIScope
|
|
27
|
+
from .middleware import get_server_port
|
|
23
28
|
from .middleware import ZeroGPUMiddleware
|
|
24
29
|
|
|
25
30
|
|
|
@@ -33,6 +38,55 @@ orig_queue_methods: dict[str, Any] = {
|
|
|
33
38
|
}
|
|
34
39
|
|
|
35
40
|
|
|
41
|
+
try:
|
|
42
|
+
Success = gr.Success # pyright: ignore[reportAttributeAccessIssue] (Gradio<5.10)
|
|
43
|
+
except AttributeError: # pragma: no cover
|
|
44
|
+
Success = gr.Info
|
|
45
|
+
|
|
46
|
+
|
|
47
|
+
def info(title: str, message: str, level: Literal['success', 'info', 'warning'] = 'info'): # pragma: no cover
|
|
48
|
+
params = inspect.signature(gr.Info).parameters
|
|
49
|
+
kwargs: dict[str, Any] = {}
|
|
50
|
+
if 'title' in params:
|
|
51
|
+
kwargs = {**kwargs, 'title': title}
|
|
52
|
+
match level:
|
|
53
|
+
case 'info':
|
|
54
|
+
return gr.Info(message, **kwargs)
|
|
55
|
+
case 'success':
|
|
56
|
+
return Success(message, **kwargs)
|
|
57
|
+
case 'warning':
|
|
58
|
+
return gr.Warning(message, **kwargs)
|
|
59
|
+
|
|
60
|
+
|
|
61
|
+
def error(title: str, message: str): # pragma: no cover
|
|
62
|
+
params = inspect.signature(gr.Error).parameters
|
|
63
|
+
kwargs: dict[str, Any] = {}
|
|
64
|
+
if 'title' in params:
|
|
65
|
+
kwargs = {**kwargs, 'title': title}
|
|
66
|
+
if 'print_exception' in params:
|
|
67
|
+
kwargs = {**kwargs, 'print_exception': False}
|
|
68
|
+
return gr.Error(message, **kwargs)
|
|
69
|
+
|
|
70
|
+
|
|
71
|
+
def log_emitter(log: ZeroGPULog):
|
|
72
|
+
return info(
|
|
73
|
+
title=log['title'],
|
|
74
|
+
message=log['message'],
|
|
75
|
+
level=log['level'],
|
|
76
|
+
)
|
|
77
|
+
|
|
78
|
+
|
|
79
|
+
def exception_mapper(err: ZeroGPUErrorResponse, exc: Exception | None):
|
|
80
|
+
if isinstance(exc, gr.Error):
|
|
81
|
+
setattr(exc, 'print_exception', False)
|
|
82
|
+
return exc
|
|
83
|
+
detail = err['detail']
|
|
84
|
+
return error(
|
|
85
|
+
title=detail['title'],
|
|
86
|
+
message=detail['message'],
|
|
87
|
+
)
|
|
88
|
+
|
|
89
|
+
|
|
36
90
|
class WorkerContextualizer:
|
|
37
91
|
def __init__(self):
|
|
38
92
|
self.event_id = LocalContext.event_id.get(None)
|
|
@@ -55,57 +109,33 @@ def disconnect_detector(): # pragma: no cover
|
|
|
55
109
|
return False
|
|
56
110
|
|
|
57
111
|
|
|
58
|
-
def
|
|
112
|
+
def setup_middleware(app: FastAPI, *, skip_zerogpu_startup: bool = False):
|
|
113
|
+
mounted = any(middleware.cls is ZeroGPUMiddleware for middleware in app.user_middleware)
|
|
114
|
+
if not mounted:
|
|
115
|
+
app.add_middleware(
|
|
116
|
+
ZeroGPUMiddleware,
|
|
117
|
+
exception_mapper=exception_mapper,
|
|
118
|
+
log_emitter=log_emitter,
|
|
119
|
+
worker_contextualizer=WorkerContextualizer,
|
|
120
|
+
disconnect_detector=disconnect_detector,
|
|
121
|
+
skip_zerogpu_startup=skip_zerogpu_startup,
|
|
122
|
+
)
|
|
123
|
+
|
|
124
|
+
|
|
125
|
+
def get_zerogpu_context():
|
|
126
|
+
if zerogpu_mode_enabled() and (request := LocalContext.request.get(None)) is not None:
|
|
127
|
+
scope = cast(ASGIScope | None, request.request.scope if request.request is not None else None)
|
|
128
|
+
return ZeroGPUContext(
|
|
129
|
+
exception_mapper=exception_mapper,
|
|
130
|
+
log_emitter=log_emitter,
|
|
131
|
+
worker_contextualizer=WorkerContextualizer,
|
|
132
|
+
disconnect_detector=disconnect_detector,
|
|
133
|
+
server_port=get_server_port(scope) if scope is not None else None,
|
|
134
|
+
headers={key.lower(): value for key, value in dict(getattr(request, 'headers', {})).items()},
|
|
135
|
+
)
|
|
59
136
|
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
except AttributeError: # pragma: no cover
|
|
63
|
-
Success = gr.Info
|
|
64
|
-
|
|
65
|
-
def error(title: str, message: str): # pragma: no cover
|
|
66
|
-
params = inspect.signature(gr.Error).parameters
|
|
67
|
-
kwargs: dict[str, Any] = {}
|
|
68
|
-
if 'title' in params:
|
|
69
|
-
kwargs = {**kwargs, 'title': title}
|
|
70
|
-
if 'print_exception' in params:
|
|
71
|
-
kwargs = {**kwargs, 'print_exception': False}
|
|
72
|
-
return gr.Error(message, **kwargs)
|
|
73
|
-
|
|
74
|
-
def info(title: str, message: str, level: Literal['success', 'info', 'warning'] = 'info'): # pragma: no cover
|
|
75
|
-
params = inspect.signature(gr.Info).parameters
|
|
76
|
-
kwargs: dict[str, Any] = {}
|
|
77
|
-
if 'title' in params:
|
|
78
|
-
kwargs = {**kwargs, 'title': title}
|
|
79
|
-
match level:
|
|
80
|
-
case 'info':
|
|
81
|
-
return gr.Info(message, **kwargs)
|
|
82
|
-
case 'success':
|
|
83
|
-
return Success(message, **kwargs)
|
|
84
|
-
case 'warning':
|
|
85
|
-
return gr.Warning(message, **kwargs)
|
|
86
|
-
|
|
87
|
-
def setup_middleware(app: FastAPI, *, skip_zerogpu_startup: bool = False):
|
|
88
|
-
mounted = any(middleware.cls is ZeroGPUMiddleware for middleware in app.user_middleware)
|
|
89
|
-
if not mounted:
|
|
90
|
-
app.add_middleware(
|
|
91
|
-
ZeroGPUMiddleware,
|
|
92
|
-
exception_mapper=lambda err, exc: (
|
|
93
|
-
setattr(exc, 'print_exception', False) or exc
|
|
94
|
-
if isinstance(exc, gr.Error)
|
|
95
|
-
else error(
|
|
96
|
-
title=err['detail']['title'],
|
|
97
|
-
message=err['detail']['message'],
|
|
98
|
-
)
|
|
99
|
-
),
|
|
100
|
-
log_emitter=lambda log: info(
|
|
101
|
-
title=log['title'],
|
|
102
|
-
message=log['message'],
|
|
103
|
-
level=log['level'],
|
|
104
|
-
),
|
|
105
|
-
worker_contextualizer=WorkerContextualizer,
|
|
106
|
-
disconnect_detector=disconnect_detector,
|
|
107
|
-
skip_zerogpu_startup=skip_zerogpu_startup,
|
|
108
|
-
)
|
|
137
|
+
|
|
138
|
+
def patch():
|
|
109
139
|
|
|
110
140
|
@wraps(orig_create_app)
|
|
111
141
|
def create_app(*args, **kwargs):
|
|
@@ -113,12 +143,14 @@ def patch():
|
|
|
113
143
|
setup_middleware(app, skip_zerogpu_startup=True)
|
|
114
144
|
return app
|
|
115
145
|
|
|
146
|
+
|
|
116
147
|
@wraps(orig_mount_gradio_app)
|
|
117
148
|
def mount_gradio_app(*args, **kwargs):
|
|
118
149
|
app = orig_mount_gradio_app(*args, **kwargs)
|
|
119
150
|
setup_middleware(app)
|
|
120
151
|
return app
|
|
121
152
|
|
|
153
|
+
|
|
122
154
|
@wraps(orig_start_server)
|
|
123
155
|
def start_server(*args, **kwargs):
|
|
124
156
|
if zerogpu_mode_enabled():
|
|
@@ -15,7 +15,7 @@ from .._vendor.asgiref.typing import ASGIReceiveEvent
|
|
|
15
15
|
from .._vendor.asgiref.typing import ASGISendCallable
|
|
16
16
|
from .._vendor.asgiref.typing import Scope as ASGIScope
|
|
17
17
|
|
|
18
|
-
from .
|
|
18
|
+
from . import context
|
|
19
19
|
from .context import ConnectionState
|
|
20
20
|
from .context import ZeroGPUErrorResponse
|
|
21
21
|
from .context import ZeroGPUContext
|
|
@@ -81,23 +81,19 @@ class ZeroGPUMiddleware:
|
|
|
81
81
|
connection_state.alive = False
|
|
82
82
|
return message
|
|
83
83
|
|
|
84
|
-
|
|
84
|
+
with context.set_context_var(ZeroGPUContext(
|
|
85
85
|
exception_mapper=self.exception_mapper,
|
|
86
86
|
log_emitter=self.log_emitter,
|
|
87
87
|
worker_contextualizer=self.worker_contextualizer,
|
|
88
88
|
disconnect_detector=self.disconnect_detector,
|
|
89
89
|
connection_state=connection_state,
|
|
90
|
-
server_port=
|
|
90
|
+
server_port=get_server_port(asgi_scope),
|
|
91
91
|
headers=_decode_headers(asgi_scope.get('headers', [])),
|
|
92
|
-
))
|
|
93
|
-
|
|
94
|
-
try:
|
|
92
|
+
)):
|
|
95
93
|
await asgi_app(asgi_scope, wrapped_receive, asgi_send)
|
|
96
|
-
finally:
|
|
97
|
-
ctx_var.reset(token)
|
|
98
94
|
|
|
99
95
|
|
|
100
|
-
def
|
|
96
|
+
def get_server_port(scope: ASGIScope):
|
|
101
97
|
match scope.get('server'):
|
|
102
98
|
case (_, int() as port):
|
|
103
99
|
return port
|
|
@@ -29,12 +29,12 @@ from ..utils import debug
|
|
|
29
29
|
from ..utils import drop_params
|
|
30
30
|
from ..utils import SimpleQueue as Queue
|
|
31
31
|
from . import client
|
|
32
|
+
from . import context
|
|
32
33
|
from . import torch
|
|
33
34
|
from .api import AllowToken
|
|
34
35
|
from .api import GPUSize
|
|
35
36
|
from .api import NvidiaIndex
|
|
36
37
|
from .api import NvidiaUUID
|
|
37
|
-
from .context import ctx_var
|
|
38
38
|
from .tqdm import remove_tqdm_multiprocessing_lock
|
|
39
39
|
from .tqdm import tqdm
|
|
40
40
|
from .utils import apply_cleanups
|
|
@@ -170,7 +170,7 @@ def regular_function_wrapper(
|
|
|
170
170
|
if forked:
|
|
171
171
|
return task(*args, **kwargs)
|
|
172
172
|
|
|
173
|
-
ctx =
|
|
173
|
+
ctx = context.get()
|
|
174
174
|
duration_ = static_duration(duration, *args, **kwargs)
|
|
175
175
|
duration_ = process_duration(duration_)
|
|
176
176
|
schedule_response = client.schedule(task_id=task_id, duration=duration_, gpu_size=gpu_size)
|
|
@@ -297,7 +297,7 @@ def generator_function_wrapper(
|
|
|
297
297
|
yield from task(*args, **kwargs)
|
|
298
298
|
return
|
|
299
299
|
|
|
300
|
-
ctx =
|
|
300
|
+
ctx = context.get()
|
|
301
301
|
duration_ = static_duration(duration, *args, **kwargs)
|
|
302
302
|
duration_ = process_duration(duration_)
|
|
303
303
|
schedule_response = client.schedule(task_id=task_id, duration=duration_, gpu_size=gpu_size)
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|