ERROR: Traceback (most recent call last):
File "/Users/aniket/miniconda3/envs/am/lib/python3.10/site-packages/starlette/routing.py", line 738, in lifespan
async with self.lifespan_context(app) as maybe_state:
File "/Users/aniket/miniconda3/envs/am/lib/python3.10/contextlib.py", line 199, in __aenter__
return await anext(self.gen)
File "/Users/aniket/Projects/github/litserve/src/litserve/server.py", line 135, in lifespan
manager = Manager()
File "/Users/aniket/miniconda3/envs/am/lib/python3.10/multiprocessing/context.py", line 57, in Manager
m.start()
File "/Users/aniket/miniconda3/envs/am/lib/python3.10/multiprocessing/managers.py", line 562, in start
self._process.start()
File "/Users/aniket/miniconda3/envs/am/lib/python3.10/multiprocessing/process.py", line 121, in start
self._popen = self._Popen(self)
File "/Users/aniket/miniconda3/envs/am/lib/python3.10/multiprocessing/context.py", line 288, in _Popen
return Popen(process_obj)
File "/Users/aniket/miniconda3/envs/am/lib/python3.10/multiprocessing/popen_spawn_posix.py", line 32, in __init__
super().__init__(process_obj)
File "/Users/aniket/miniconda3/envs/am/lib/python3.10/multiprocessing/popen_fork.py", line 19, in __init__
self._launch(process_obj)
File "/Users/aniket/miniconda3/envs/am/lib/python3.10/multiprocessing/popen_spawn_posix.py", line 42, in _launch
prep_data = spawn.get_preparation_data(process_obj._name)
File "/Users/aniket/miniconda3/envs/am/lib/python3.10/multiprocessing/spawn.py", line 154, in get_preparation_data
_check_not_importing_main()
File "/Users/aniket/miniconda3/envs/am/lib/python3.10/multiprocessing/spawn.py", line 134, in _check_not_importing_main
raise RuntimeError('''
RuntimeError:
An attempt has been made to start a new process before the
current process has finished its bootstrapping phase.
This probably means that you are not using fork to start your
child processes and you have forgotten to use the proper idiom
in the main module:
if __name__ == '__main__':
freeze_support()
...
The "freeze_support()" line can be omitted if the program
is not going to be frozen to produce an executable.
ERROR: Application startup failed. Exiting.
# server.py
import litserve as ls
# STEP 1: DEFINE YOUR MODEL API
class SimpleLitAPI(ls.LitAPI):
def setup(self, device):
# Setup the model so it can be called in `predict`.
self.model = lambda x: x**2
def decode_request(self, request):
# Convert the request payload to your model input.
return request["input"]
def predict(self, x):
# Run the model on the input and return the output.
return self.model(x)
def encode_response(self, output):
# Convert the model output to a response payload.
return {"output": output}
# STEP 2: START THE SERVER
api = SimpleLitAPI()
server = ls.LitServer(api, accelerator="gpu")
server.run(port=8000)