From 229677aa759c32cae01cd941cf02e8a7d5851c5e Mon Sep 17 00:00:00 2001 From: thomas Date: Wed, 7 Dec 2022 21:21:04 +0000 Subject: [PATCH 01/21] update --- .../components/serve/python_server.py | 63 ++++++------------- 1 file changed, 20 insertions(+), 43 deletions(-) diff --git a/src/lightning_app/components/serve/python_server.py b/src/lightning_app/components/serve/python_server.py index 99d51ac1cf4fc..070147fea049a 100644 --- a/src/lightning_app/components/serve/python_server.py +++ b/src/lightning_app/components/serve/python_server.py @@ -9,12 +9,11 @@ from lightning_utilities.core.imports import module_available from pydantic import BaseModel from starlette.staticfiles import StaticFiles - -from lightning_app.core.queues import MultiProcessQueue +import platform from lightning_app.core.work import LightningWork from lightning_app.utilities.app_helpers import Logger from lightning_app.utilities.imports import _is_torch_available, requires -from lightning_app.utilities.proxies import _proxy_setattr, unwrap, WorkRunExecutor, WorkStateObserver +from lightning_utilities.core.imports import compare_version logger = Logger(__name__) @@ -28,44 +27,24 @@ __doctest_skip__ += ["PythonServer", "PythonServer.*"] -class _PyTorchSpawnRunExecutor(WorkRunExecutor): - - """This Executor enables to move PyTorch tensors on GPU. - - Without this executor, it would raise the following exception: - RuntimeError: Cannot re-initialize CUDA in forked subprocess. - To use CUDA with multiprocessing, you must use the 'spawn' start method - """ - - enable_start_observer: bool = False - - def __call__(self, *args: Any, **kwargs: Any): - import torch - - with self.enable_spawn(): - queue = self.delta_queue if isinstance(self.delta_queue, MultiProcessQueue) else self.delta_queue.to_dict() - torch.multiprocessing.spawn( - self.dispatch_run, - args=(self.__class__, self.work, queue, args, kwargs), - nprocs=1, - ) - - @staticmethod - def dispatch_run(local_rank, cls, work, delta_queue, args, kwargs): - if local_rank == 0: - if isinstance(delta_queue, dict): - delta_queue = cls.process_queue(delta_queue) - work._request_queue = cls.process_queue(work._request_queue) - work._response_queue = cls.process_queue(work._response_queue) +def get_device(): + import torch + import operator - state_observer = WorkStateObserver(work, delta_queue=delta_queue) - state_observer.start() - _proxy_setattr(work, delta_queue, state_observer) + _TORCH_GREATER_EQUAL_1_12 = compare_version("torch", operator.ge, "1.12.0") - unwrap(work.run)(*args, **kwargs) + local_rank = int(os.getenv("LOCAL_RANK", "0")) - if local_rank == 0: - state_observer.join(0) + if ( + _TORCH_GREATER_EQUAL_1_12 + and torch.backends.mps.is_available() + and platform.processor() in ("arm", "arm64") + ): + return torch.device("mps", local_rank) + else: + return torch.device( + f"cuda:{local_rank}" if torch.cuda.is_available() else "cpu" + ) class _DefaultInputData(BaseModel): @@ -96,6 +75,9 @@ def _get_sample_data() -> Dict[Any, Any]: class PythonServer(LightningWork, abc.ABC): + + _start_method = "spawn" + @requires(["torch", "lightning_api_access"]) def __init__( # type: ignore self, @@ -161,11 +143,6 @@ def predict(self, request): self._input_type = input_type self._output_type = output_type - # Note: Enable to run inference on GPUs. - self._run_executor_cls = ( - WorkRunExecutor if os.getenv("LIGHTNING_CLOUD_APP_ID", None) else _PyTorchSpawnRunExecutor - ) - def setup(self, *args, **kwargs) -> None: """This method is called before the server starts. Override this if you need to download the model or initialize the weights, setting up pipelines etc. From c6191c2cebba3e1ffb0ef70115a0f5dd2836f5dc Mon Sep 17 00:00:00 2001 From: thomas Date: Wed, 7 Dec 2022 21:22:25 +0000 Subject: [PATCH 02/21] update --- src/lightning_app/components/serve/python_server.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/lightning_app/components/serve/python_server.py b/src/lightning_app/components/serve/python_server.py index 070147fea049a..8c0ebed097d2b 100644 --- a/src/lightning_app/components/serve/python_server.py +++ b/src/lightning_app/components/serve/python_server.py @@ -188,13 +188,16 @@ def _get_sample_dict_from_datatype(datatype: Any) -> dict: return out def _attach_predict_fn(self, fastapi_app: FastAPI) -> None: - from torch import inference_mode + from torch import inference_mode, no_grad input_type: type = self.configure_input_type() output_type: type = self.configure_output_type() + device = get_device() + context = no_grad if device.type == "mps" else inference_mode + def predict_fn(request: input_type): # type: ignore - with inference_mode(): + with context: return self.predict(request) fastapi_app.post("/predict", response_model=output_type)(predict_fn) From 6805e0a422918b6489ae4dd1d9783c608eb915cf Mon Sep 17 00:00:00 2001 From: thomas Date: Wed, 7 Dec 2022 21:23:33 +0000 Subject: [PATCH 03/21] update --- src/lightning_app/CHANGELOG.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/lightning_app/CHANGELOG.md b/src/lightning_app/CHANGELOG.md index c5b60b4ac96e1..071803e8c53d7 100644 --- a/src/lightning_app/CHANGELOG.md +++ b/src/lightning_app/CHANGELOG.md @@ -58,6 +58,8 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/). - Fixed Sigterm Handler causing thread lock which caused KeyboardInterrupt to hang ([#15881](https://github.com/Lightning-AI/lightning/pull/15881)) +- Fixed PythonServer generating noise on M1 ([#15949](https://github.com/Lightning-AI/lightning/pull/15949)) + ## [1.8.3] - 2022-11-22 From 3abe2451ddd53d5881fd4c7d4499ade2d5de2fc5 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Wed, 7 Dec 2022 21:24:01 +0000 Subject: [PATCH 04/21] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- .../components/serve/python_server.py | 19 +++++++------------ 1 file changed, 7 insertions(+), 12 deletions(-) diff --git a/src/lightning_app/components/serve/python_server.py b/src/lightning_app/components/serve/python_server.py index 8c0ebed097d2b..842257daa8401 100644 --- a/src/lightning_app/components/serve/python_server.py +++ b/src/lightning_app/components/serve/python_server.py @@ -1,19 +1,19 @@ import abc import base64 import os +import platform from pathlib import Path from typing import Any, Dict, Optional import uvicorn from fastapi import FastAPI -from lightning_utilities.core.imports import module_available +from lightning_utilities.core.imports import compare_version, module_available from pydantic import BaseModel from starlette.staticfiles import StaticFiles -import platform + from lightning_app.core.work import LightningWork from lightning_app.utilities.app_helpers import Logger from lightning_app.utilities.imports import _is_torch_available, requires -from lightning_utilities.core.imports import compare_version logger = Logger(__name__) @@ -28,23 +28,18 @@ def get_device(): - import torch import operator + import torch + _TORCH_GREATER_EQUAL_1_12 = compare_version("torch", operator.ge, "1.12.0") local_rank = int(os.getenv("LOCAL_RANK", "0")) - if ( - _TORCH_GREATER_EQUAL_1_12 - and torch.backends.mps.is_available() - and platform.processor() in ("arm", "arm64") - ): + if _TORCH_GREATER_EQUAL_1_12 and torch.backends.mps.is_available() and platform.processor() in ("arm", "arm64"): return torch.device("mps", local_rank) else: - return torch.device( - f"cuda:{local_rank}" if torch.cuda.is_available() else "cpu" - ) + return torch.device(f"cuda:{local_rank}" if torch.cuda.is_available() else "cpu") class _DefaultInputData(BaseModel): From b05927d0f2aa3baddb8185d859bac6d47331e413 Mon Sep 17 00:00:00 2001 From: thomas Date: Wed, 7 Dec 2022 21:32:35 +0000 Subject: [PATCH 05/21] update --- src/lightning_app/components/serve/gradio.py | 7 ++----- src/lightning_app/components/serve/python_server.py | 2 +- 2 files changed, 3 insertions(+), 6 deletions(-) diff --git a/src/lightning_app/components/serve/gradio.py b/src/lightning_app/components/serve/gradio.py index 6e9b1d8777f67..071a73560a5f2 100644 --- a/src/lightning_app/components/serve/gradio.py +++ b/src/lightning_app/components/serve/gradio.py @@ -4,7 +4,6 @@ from types import ModuleType from typing import Any, List, Optional -from lightning_app.components.serve.python_server import _PyTorchSpawnRunExecutor, WorkRunExecutor from lightning_app.core.work import LightningWork from lightning_app.utilities.imports import _is_gradio_available, requires @@ -36,15 +35,13 @@ class ServeGradio(LightningWork, abc.ABC): title: Optional[str] = None description: Optional[str] = None + _start_method = "spawn" + def __init__(self, *args, **kwargs): requires("gradio")(super().__init__(*args, **kwargs)) assert self.inputs assert self.outputs self._model = None - # Note: Enable to run inference on GPUs. - self._run_executor_cls = ( - WorkRunExecutor if os.getenv("LIGHTNING_CLOUD_APP_ID", None) else _PyTorchSpawnRunExecutor - ) @property def model(self): diff --git a/src/lightning_app/components/serve/python_server.py b/src/lightning_app/components/serve/python_server.py index 8c0ebed097d2b..fdb7995b6763c 100644 --- a/src/lightning_app/components/serve/python_server.py +++ b/src/lightning_app/components/serve/python_server.py @@ -197,7 +197,7 @@ def _attach_predict_fn(self, fastapi_app: FastAPI) -> None: context = no_grad if device.type == "mps" else inference_mode def predict_fn(request: input_type): # type: ignore - with context: + with context(): return self.predict(request) fastapi_app.post("/predict", response_model=output_type)(predict_fn) From 95b70684a99e6861b72134d1c33a40291406268c Mon Sep 17 00:00:00 2001 From: thomas Date: Wed, 7 Dec 2022 21:41:52 +0000 Subject: [PATCH 06/21] update --- src/lightning_app/components/serve/python_server.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/lightning_app/components/serve/python_server.py b/src/lightning_app/components/serve/python_server.py index c6a88cf6e6140..aaf9b86b69c62 100644 --- a/src/lightning_app/components/serve/python_server.py +++ b/src/lightning_app/components/serve/python_server.py @@ -27,7 +27,7 @@ __doctest_skip__ += ["PythonServer", "PythonServer.*"] -def get_device(): +def _get_device(): import operator import torch @@ -188,7 +188,7 @@ def _attach_predict_fn(self, fastapi_app: FastAPI) -> None: input_type: type = self.configure_input_type() output_type: type = self.configure_output_type() - device = get_device() + device = _get_device() context = no_grad if device.type == "mps" else inference_mode def predict_fn(request: input_type): # type: ignore From a82d8ca5402abf3a0aa4efe9a2f8684ece70c097 Mon Sep 17 00:00:00 2001 From: thomas Date: Wed, 7 Dec 2022 21:46:32 +0000 Subject: [PATCH 07/21] update --- src/lightning_app/components/serve/gradio.py | 1 - 1 file changed, 1 deletion(-) diff --git a/src/lightning_app/components/serve/gradio.py b/src/lightning_app/components/serve/gradio.py index 071a73560a5f2..16dea12098d58 100644 --- a/src/lightning_app/components/serve/gradio.py +++ b/src/lightning_app/components/serve/gradio.py @@ -1,5 +1,4 @@ import abc -import os from functools import partial from types import ModuleType from typing import Any, List, Optional From e1e41da4f2800902a04dc8c3cfaf840416242265 Mon Sep 17 00:00:00 2001 From: thomas Date: Wed, 7 Dec 2022 21:56:13 +0000 Subject: [PATCH 08/21] update --- requirements/app/ui.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/requirements/app/ui.txt b/requirements/app/ui.txt index fa051d284f0b8..17ff0302f7e91 100644 --- a/requirements/app/ui.txt +++ b/requirements/app/ui.txt @@ -1,2 +1,2 @@ -streamlit>=1.3.1, <=1.11.1 +streamlit panel>=0.12.7, <=0.13.1 From 5dd92c053d9de5bc3f3df60c484ebc0ec2814d5e Mon Sep 17 00:00:00 2001 From: thomas Date: Wed, 7 Dec 2022 22:10:07 +0000 Subject: [PATCH 09/21] update --- src/lightning_app/frontend/streamlit_base.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/lightning_app/frontend/streamlit_base.py b/src/lightning_app/frontend/streamlit_base.py index 2cae7190cbdb0..a06ec8e083012 100644 --- a/src/lightning_app/frontend/streamlit_base.py +++ b/src/lightning_app/frontend/streamlit_base.py @@ -9,7 +9,7 @@ from lightning_app.frontend.utils import _reduce_to_flow_scope from lightning_app.utilities.app_helpers import StreamLitStatePlugin from lightning_app.utilities.state import AppState - +import asyncio def _get_render_fn_from_environment() -> Callable: render_fn_name = os.environ["LIGHTNING_RENDER_FUNCTION"] @@ -20,6 +20,10 @@ def _get_render_fn_from_environment() -> Callable: def _main(): """Run the render_fn with the current flow_state.""" + loop = asyncio.new_event_loop() + asyncio.set_event_loop(loop) + + app_state = AppState(plugin=StreamLitStatePlugin()) # Fetch the information of which flow attaches to this streamlit instance From 6df486f89b1e0d52a3082205064b596205a75e37 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Wed, 7 Dec 2022 22:11:39 +0000 Subject: [PATCH 10/21] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- src/lightning_app/frontend/streamlit_base.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/lightning_app/frontend/streamlit_base.py b/src/lightning_app/frontend/streamlit_base.py index a06ec8e083012..f146148734329 100644 --- a/src/lightning_app/frontend/streamlit_base.py +++ b/src/lightning_app/frontend/streamlit_base.py @@ -2,6 +2,7 @@ From here, we will call the render function that the user provided in ``configure_layout``. """ +import asyncio import os import pydoc from typing import Callable @@ -9,7 +10,7 @@ from lightning_app.frontend.utils import _reduce_to_flow_scope from lightning_app.utilities.app_helpers import StreamLitStatePlugin from lightning_app.utilities.state import AppState -import asyncio + def _get_render_fn_from_environment() -> Callable: render_fn_name = os.environ["LIGHTNING_RENDER_FUNCTION"] @@ -23,7 +24,6 @@ def _main(): loop = asyncio.new_event_loop() asyncio.set_event_loop(loop) - app_state = AppState(plugin=StreamLitStatePlugin()) # Fetch the information of which flow attaches to this streamlit instance From 1e9d1e2229ea430734b0c9dfd9fc851d8f3ef3f4 Mon Sep 17 00:00:00 2001 From: thomas Date: Wed, 7 Dec 2022 22:11:43 +0000 Subject: [PATCH 11/21] update --- src/lightning_app/frontend/streamlit_base.py | 1 - 1 file changed, 1 deletion(-) diff --git a/src/lightning_app/frontend/streamlit_base.py b/src/lightning_app/frontend/streamlit_base.py index a06ec8e083012..e7316f041e2d0 100644 --- a/src/lightning_app/frontend/streamlit_base.py +++ b/src/lightning_app/frontend/streamlit_base.py @@ -23,7 +23,6 @@ def _main(): loop = asyncio.new_event_loop() asyncio.set_event_loop(loop) - app_state = AppState(plugin=StreamLitStatePlugin()) # Fetch the information of which flow attaches to this streamlit instance From cdd8226fca5de776134873ee5ff211edb5ec5ccf Mon Sep 17 00:00:00 2001 From: thomas Date: Wed, 7 Dec 2022 22:22:55 +0000 Subject: [PATCH 12/21] update --- src/lightning_app/frontend/streamlit_base.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/lightning_app/frontend/streamlit_base.py b/src/lightning_app/frontend/streamlit_base.py index f146148734329..64ad4dc361955 100644 --- a/src/lightning_app/frontend/streamlit_base.py +++ b/src/lightning_app/frontend/streamlit_base.py @@ -24,6 +24,10 @@ def _main(): loop = asyncio.new_event_loop() asyncio.set_event_loop(loop) + import streamlit as st + + st.write(os.environ) + app_state = AppState(plugin=StreamLitStatePlugin()) # Fetch the information of which flow attaches to this streamlit instance From 07e9b3556b2988320fda206fd1f2f5f4be02639a Mon Sep 17 00:00:00 2001 From: thomas Date: Wed, 7 Dec 2022 22:32:47 +0000 Subject: [PATCH 13/21] update --- examples/app_template_streamlit_ui/app.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/examples/app_template_streamlit_ui/app.py b/examples/app_template_streamlit_ui/app.py index 6f344ac98eb8d..92f17978365df 100644 --- a/examples/app_template_streamlit_ui/app.py +++ b/examples/app_template_streamlit_ui/app.py @@ -1,8 +1,8 @@ import logging -from lightning_app import LightningApp, LightningFlow -from lightning_app.frontend import StreamlitFrontend -from lightning_app.utilities.state import AppState +from lightning.app import LightningApp, LightningFlow +from lightning.app.frontend import StreamlitFrontend +from lightning.app.utilities.state import AppState logger = logging.getLogger(__name__) From 8c486283754ffa4b763885fe2c945421b50ed68c Mon Sep 17 00:00:00 2001 From: thomas Date: Wed, 7 Dec 2022 22:32:59 +0000 Subject: [PATCH 14/21] update --- src/lightning_app/frontend/streamlit_base.py | 4 ---- 1 file changed, 4 deletions(-) diff --git a/src/lightning_app/frontend/streamlit_base.py b/src/lightning_app/frontend/streamlit_base.py index 64ad4dc361955..f146148734329 100644 --- a/src/lightning_app/frontend/streamlit_base.py +++ b/src/lightning_app/frontend/streamlit_base.py @@ -24,10 +24,6 @@ def _main(): loop = asyncio.new_event_loop() asyncio.set_event_loop(loop) - import streamlit as st - - st.write(os.environ) - app_state = AppState(plugin=StreamLitStatePlugin()) # Fetch the information of which flow attaches to this streamlit instance From 02aff87346a696c1505bf87f128a6c86b225d3eb Mon Sep 17 00:00:00 2001 From: thomas Date: Wed, 7 Dec 2022 22:39:03 +0000 Subject: [PATCH 15/21] update --- src/lightning_app/components/auto_scaler.py | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/src/lightning_app/components/auto_scaler.py b/src/lightning_app/components/auto_scaler.py index ad9d69690b23d..1e479601f1eff 100644 --- a/src/lightning_app/components/auto_scaler.py +++ b/src/lightning_app/components/auto_scaler.py @@ -25,8 +25,6 @@ from lightning_app.utilities.packaging.cloud_compute import CloudCompute logger = Logger(__name__) -lock = asyncio.Lock() - def _raise_granular_exception(exception: Exception) -> None: """Handle an exception from hitting the model servers.""" @@ -269,9 +267,7 @@ async def sys_info(authenticated: bool = Depends(authenticate_private_endpoint)) @fastapi_app.put("/system/update-servers") async def update_servers(servers: List[str], authenticated: bool = Depends(authenticate_private_endpoint)): - async with lock: - self.servers = servers - + self.servers = servers self._iter = cycle(self.servers) @fastapi_app.post(self.endpoint, response_model=self._output_type) From 9073c1a0623d23c290257926e3de48c12e0ef027 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Wed, 7 Dec 2022 22:40:27 +0000 Subject: [PATCH 16/21] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- src/lightning_app/components/auto_scaler.py | 1 + 1 file changed, 1 insertion(+) diff --git a/src/lightning_app/components/auto_scaler.py b/src/lightning_app/components/auto_scaler.py index 1e479601f1eff..fc7fee2c57281 100644 --- a/src/lightning_app/components/auto_scaler.py +++ b/src/lightning_app/components/auto_scaler.py @@ -26,6 +26,7 @@ logger = Logger(__name__) + def _raise_granular_exception(exception: Exception) -> None: """Handle an exception from hitting the model servers.""" if not isinstance(exception, Exception): From bee3c70170c8ab99b88d7213752d645b136e12c2 Mon Sep 17 00:00:00 2001 From: thomas Date: Thu, 8 Dec 2022 11:13:17 +0000 Subject: [PATCH 17/21] update --- requirements/app/ui.txt | 2 +- src/lightning_app/frontend/streamlit_base.py | 4 ---- 2 files changed, 1 insertion(+), 5 deletions(-) diff --git a/requirements/app/ui.txt b/requirements/app/ui.txt index 17ff0302f7e91..7480379c9548b 100644 --- a/requirements/app/ui.txt +++ b/requirements/app/ui.txt @@ -1,2 +1,2 @@ -streamlit +streamlit>=1.0.0 panel>=0.12.7, <=0.13.1 diff --git a/src/lightning_app/frontend/streamlit_base.py b/src/lightning_app/frontend/streamlit_base.py index f146148734329..2cae7190cbdb0 100644 --- a/src/lightning_app/frontend/streamlit_base.py +++ b/src/lightning_app/frontend/streamlit_base.py @@ -2,7 +2,6 @@ From here, we will call the render function that the user provided in ``configure_layout``. """ -import asyncio import os import pydoc from typing import Callable @@ -21,9 +20,6 @@ def _get_render_fn_from_environment() -> Callable: def _main(): """Run the render_fn with the current flow_state.""" - loop = asyncio.new_event_loop() - asyncio.set_event_loop(loop) - app_state = AppState(plugin=StreamLitStatePlugin()) # Fetch the information of which flow attaches to this streamlit instance From a362f33d11c79d2274b5ca3344edebb4bd296d31 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Thu, 8 Dec 2022 11:14:01 +0000 Subject: [PATCH 18/21] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- src/lightning_app/components/auto_scaler.py | 1 + 1 file changed, 1 insertion(+) diff --git a/src/lightning_app/components/auto_scaler.py b/src/lightning_app/components/auto_scaler.py index f97082b7b6117..8e9c5663b83c5 100644 --- a/src/lightning_app/components/auto_scaler.py +++ b/src/lightning_app/components/auto_scaler.py @@ -26,6 +26,7 @@ logger = Logger(__name__) + def _raise_granular_exception(exception: Exception) -> None: """Handle an exception from hitting the model servers.""" if not isinstance(exception, Exception): From 33b5e7620b5682f4ea5320532229633342e2f138 Mon Sep 17 00:00:00 2001 From: thomas Date: Thu, 8 Dec 2022 11:33:38 +0000 Subject: [PATCH 19/21] update --- src/lightning_app/components/auto_scaler.py | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/lightning_app/components/auto_scaler.py b/src/lightning_app/components/auto_scaler.py index f97082b7b6117..c2dd8945a3d54 100644 --- a/src/lightning_app/components/auto_scaler.py +++ b/src/lightning_app/components/auto_scaler.py @@ -205,9 +205,7 @@ async def process_request(self, data: BaseModel): return result def run(self): - logger.info(f"servers: {self.servers}") - lock = asyncio.Lock() self._iter = cycle(self.servers) self._last_batch_sent = time.time() From dbf5a63052c2ec8ac4947f43e812953713e60367 Mon Sep 17 00:00:00 2001 From: thomas Date: Thu, 8 Dec 2022 11:54:48 +0000 Subject: [PATCH 20/21] update --- requirements/app/ui.txt | 2 +- src/lightning_app/components/auto_scaler.py | 4 +++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/requirements/app/ui.txt b/requirements/app/ui.txt index 7480379c9548b..6e73b96c317d3 100644 --- a/requirements/app/ui.txt +++ b/requirements/app/ui.txt @@ -1,2 +1,2 @@ -streamlit>=1.0.0 +streamlit>=1.0.0, <=1.15.2 panel>=0.12.7, <=0.13.1 diff --git a/src/lightning_app/components/auto_scaler.py b/src/lightning_app/components/auto_scaler.py index f57a7c3770844..62e6180c49665 100644 --- a/src/lightning_app/components/auto_scaler.py +++ b/src/lightning_app/components/auto_scaler.py @@ -207,6 +207,7 @@ async def process_request(self, data: BaseModel): def run(self): logger.info(f"servers: {self.servers}") + lock = asyncio.Lock() self._iter = cycle(self.servers) self._last_batch_sent = time.time() @@ -267,7 +268,8 @@ async def sys_info(authenticated: bool = Depends(authenticate_private_endpoint)) @fastapi_app.put("/system/update-servers") async def update_servers(servers: List[str], authenticated: bool = Depends(authenticate_private_endpoint)): - self.servers = servers + async with lock: + self.servers = servers self._iter = cycle(self.servers) @fastapi_app.post(self.endpoint, response_model=self._output_type) From f45c61a820fa7a618764978bad174b3b44964c57 Mon Sep 17 00:00:00 2001 From: thomas Date: Thu, 8 Dec 2022 12:12:45 +0000 Subject: [PATCH 21/21] update --- src/lightning_app/components/python/tracer.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/lightning_app/components/python/tracer.py b/src/lightning_app/components/python/tracer.py index c476f083258fc..d10ca92252ed8 100644 --- a/src/lightning_app/components/python/tracer.py +++ b/src/lightning_app/components/python/tracer.py @@ -22,6 +22,9 @@ class Code(TypedDict): class TracerPythonScript(LightningWork): + + _start_method = "spawn" + def on_before_run(self): """Called before the python script is executed."""