Possible model isolation issue
When a model handler has an intermittent crash during initialization - that is, immediately after the model archive's scale-up call, but before any inference call - then all worker threads for that model get taken down and the model removed from memory - even threads that could have continued processing correctly.
Some notes:
- This does not happen during inference calls. A crash during inference kills and restarts the offending worker(s), which is the expected behavior.
- This does not affect models already loaded and running. I verified this by loading a good model, loading my crashy model archive, checking which models were still running via the Management API, and running inference on the non-crashy model.
If you'd like to make your own intermittent crasher, you can add the following to the Resnet-152 handler's initialize() method:
x = abs(hash(properties['model_dir'])) % 2 # model_dir is a long, random hex string
if x == 1:
# induce the crash of your choice - I divided by 0
@fbbradheintz : Out of curiosity, is this scale-up call ie., PUT /models call? or a register model call ie.,POST /models call with initial_workers? Also, is this a synchronous call? I pasted my findings below. Please correct me if I am missing something...
Findings
I ran
curl -X PUT "localhost:8081/models/squeezenet1_1?min_worker=3"
with the following hanlder
from torchvision.models.squeezenet import SqueezeNet
import os
import sys
class ImageClassifier(SqueezeNet):
def __init__(self):
print(f"Current PID is {int(os.getpid())}")
if int(os.getpid()) % 2:
print(f"Exiting the PID {int(os.getpid())}")
raise Exception("JACKPOT!!! Exiting {}".format(int(os.getpid())))
sys.stdout.flush()
super(ImageClassifier, self).__init__('1_1')
it seems like only the backend worker which was killed (the process with odd number pid) is restarted.
Three PIDs were initially created 28152, 28156 and 28151. Since 28151 was odd number, it crashed and was restarted, this time with 28168.
NOTE: If you run register command POST /models?...&initial_workers=..., and one of worker dies, then all the workers are removed. If this is run with synchronous option, customers would get failure code as well. This was intentionally designed to provide customers with a "register+scale-up" in one call and clean the memory fully if something went wrong in that call. But the scale-up call PUT models?...min_workers=... currently behaves differently. It was designed to be best effort and non-transactional. Hence if one of the workers die during PUT /models?...min_workers=..., the server tries to bring up that worker.
TL;DR Logs
I have attached the logs below.
2020-04-18 11:36:50,284 [INFO ] W-9039-squeezenet1_1_1.0-stdout org.pytorch.serve.wlm.WorkerLifeCycle - Listening on port: /var/folders/86/cslbmm0j0glf7d1qwwltjsvx0sl6df/T//.ts.sock.9039
2020-04-18 11:36:50,284 [INFO ] W-9039-squeezenet1_1_1.0-stdout org.pytorch.serve.wlm.WorkerLifeCycle - [PID]28152
2020-04-18 11:36:50,284 [INFO ] W-9039-squeezenet1_1_1.0-stdout org.pytorch.serve.wlm.WorkerLifeCycle - Torch worker started.
2020-04-18 11:36:50,284 [DEBUG] W-9039-squeezenet1_1_1.0 org.pytorch.serve.wlm.WorkerThread - W-9039-squeezenet1_1_1.0 State change null -> WORKER_STARTED
2020-04-18 11:36:50,284 [INFO ] W-9039-squeezenet1_1_1.0-stdout org.pytorch.serve.wlm.WorkerLifeCycle - Python runtime: 3.6.5
2020-04-18 11:36:50,284 [INFO ] W-9039-squeezenet1_1_1.0 org.pytorch.serve.wlm.WorkerThread - Connecting to: /var/folders/86/cslbmm0j0glf7d1qwwltjsvx0sl6df/T//.ts.sock.9039
2020-04-18 11:36:50,285 [INFO ] W-9039-squeezenet1_1_1.0-stdout org.pytorch.serve.wlm.WorkerLifeCycle - Connection accepted: /var/folders/86/cslbmm0j0glf7d1qwwltjsvx0sl6df/T//.ts.sock.9039.
2020-04-18 11:36:50,395 [INFO ] W-9037-squeezenet1_1_1.0-stdout org.pytorch.serve.wlm.WorkerLifeCycle - Listening on port: /var/folders/86/cslbmm0j0glf7d1qwwltjsvx0sl6df/T//.ts.sock.9037
2020-04-18 11:36:50,396 [INFO ] W-9037-squeezenet1_1_1.0-stdout org.pytorch.serve.wlm.WorkerLifeCycle - [PID]28151
2020-04-18 11:36:50,396 [INFO ] W-9037-squeezenet1_1_1.0-stdout org.pytorch.serve.wlm.WorkerLifeCycle - Torch worker started.
2020-04-18 11:36:50,396 [DEBUG] W-9037-squeezenet1_1_1.0 org.pytorch.serve.wlm.WorkerThread - W-9037-squeezenet1_1_1.0 State change null -> WORKER_STARTED
2020-04-18 11:36:50,396 [INFO ] W-9037-squeezenet1_1_1.0-stdout org.pytorch.serve.wlm.WorkerLifeCycle - Python runtime: 3.6.5
2020-04-18 11:36:50,396 [INFO ] W-9037-squeezenet1_1_1.0 org.pytorch.serve.wlm.WorkerThread - Connecting to: /var/folders/86/cslbmm0j0glf7d1qwwltjsvx0sl6df/T//.ts.sock.9037
2020-04-18 11:36:50,396 [INFO ] W-9037-squeezenet1_1_1.0-stdout org.pytorch.serve.wlm.WorkerLifeCycle - Connection accepted: /var/folders/86/cslbmm0j0glf7d1qwwltjsvx0sl6df/T//.ts.sock.9037.
2020-04-18 11:36:50,882 [INFO ] W-9038-squeezenet1_1_1.0-stdout org.pytorch.serve.wlm.WorkerLifeCycle - Listening on port: /var/folders/86/cslbmm0j0glf7d1qwwltjsvx0sl6df/T//.ts.sock.9038
2020-04-18 11:36:50,882 [INFO ] W-9038-squeezenet1_1_1.0-stdout org.pytorch.serve.wlm.WorkerLifeCycle - [PID]28156
2020-04-18 11:36:50,882 [INFO ] W-9038-squeezenet1_1_1.0-stdout org.pytorch.serve.wlm.WorkerLifeCycle - Torch worker started.
2020-04-18 11:36:50,882 [DEBUG] W-9038-squeezenet1_1_1.0 org.pytorch.serve.wlm.WorkerThread - W-9038-squeezenet1_1_1.0 State change null -> WORKER_STARTED
2020-04-18 11:36:50,882 [INFO ] W-9038-squeezenet1_1_1.0-stdout org.pytorch.serve.wlm.WorkerLifeCycle - Python runtime: 3.6.5
2020-04-18 11:36:50,882 [INFO ] W-9038-squeezenet1_1_1.0 org.pytorch.serve.wlm.WorkerThread - Connecting to: /var/folders/86/cslbmm0j0glf7d1qwwltjsvx0sl6df/T//.ts.sock.9038
2020-04-18 11:36:50,883 [INFO ] W-9038-squeezenet1_1_1.0-stdout org.pytorch.serve.wlm.WorkerLifeCycle - Connection accepted: /var/folders/86/cslbmm0j0glf7d1qwwltjsvx0sl6df/T//.ts.sock.9038.
2020-04-18 11:36:51,764 [INFO ] W-9039-squeezenet1_1_1.0-stdout org.pytorch.serve.wlm.WorkerLifeCycle - Current PID is 28152
2020-04-18 11:36:51,788 [INFO ] W-9039-squeezenet1_1_1.0 org.pytorch.serve.wlm.WorkerThread - Backend response time: 1503
2020-04-18 11:36:51,788 [DEBUG] W-9039-squeezenet1_1_1.0 org.pytorch.serve.wlm.WorkerThread - W-9039-squeezenet1_1_1.0 State change WORKER_STARTED -> WORKER_MODEL_LOADED
2020-04-18 11:36:51,788 [INFO ] W-9039-squeezenet1_1_1.0 TS_METRICS - W-9039-squeezenet1_1_1.0.ms:2010|#Level:Host|#hostname:f01898723b72.ant.amazon.com,timestamp:1587235011
2020-04-18 11:36:51,842 [INFO ] W-9037-squeezenet1_1_1.0-stdout org.pytorch.serve.wlm.WorkerLifeCycle - Current PID is 28151
2020-04-18 11:36:51,842 [INFO ] W-9037-squeezenet1_1_1.0-stdout org.pytorch.serve.wlm.WorkerLifeCycle - Exiting the PID 28151
2020-04-18 11:36:51,842 [INFO ] W-9037-squeezenet1_1_1.0-stdout org.pytorch.serve.wlm.WorkerLifeCycle - Backend worker process die.
2020-04-18 11:36:51,842 [INFO ] W-9037-squeezenet1_1_1.0-stdout org.pytorch.serve.wlm.WorkerLifeCycle - Traceback (most recent call last):
2020-04-18 11:36:51,842 [INFO ] W-9037-squeezenet1_1_1.0-stdout org.pytorch.serve.wlm.WorkerLifeCycle - File "/Users/dantu/PycharmProjects/serve/ts/torch_handler/base_handler.py", line 42, in initialize
2020-04-18 11:36:51,842 [INFO ] W-9037-squeezenet1_1_1.0-stdout org.pytorch.serve.wlm.WorkerLifeCycle - self.model = torch.jit.load(model_pt_path)
2020-04-18 11:36:51,842 [INFO ] W-9037-squeezenet1_1_1.0-stdout org.pytorch.serve.wlm.WorkerLifeCycle - File "/Users/dantu/Workplace/py3env/lib/python3.6/site-packages/torch/jit/__init__.py", line 235, in load
...
"/private/var/folders/86/cslbmm0j0glf7d1qwwltjsvx0sl6df/T/models/0acb80c75ab9b8c1ebd8ec423f47fc6f5bfea2f5/model.py", line 10, in __init__
2020-04-18 11:36:51,845 [INFO ] W-9037-squeezenet1_1_1.0-stdout org.pytorch.serve.wlm.WorkerLifeCycle - raise Exception("JACKPOT!!! Exiting {}".format(int(os.getpid())))
2020-04-18 11:36:51,845 [INFO ] W-9037-squeezenet1_1_1.0-stdout org.pytorch.serve.wlm.WorkerLifeCycle - Exception: JACKPOT!!! Exiting 28151
...
2020-04-18 11:36:51,845 [INFO ] W-9037-squeezenet1_1_1.0-stdout org.pytorch.serve.wlm.WorkerLifeCycle - Exception: Please provide a custom handler in the model archive.
2020-04-18 11:36:52,260 [INFO ] W-9038-squeezenet1_1_1.0-stdout org.pytorch.serve.wlm.WorkerLifeCycle - Current PID is 28156
2020-04-18 11:36:52,288 [INFO ] W-9038-squeezenet1_1_1.0 org.pytorch.serve.wlm.WorkerThread - Backend response time: 1405
2020-04-18 11:36:52,288 [DEBUG] W-9038-squeezenet1_1_1.0 org.pytorch.serve.wlm.WorkerThread - W-9038-squeezenet1_1_1.0 State change WORKER_STARTED -> WORKER_MODEL_LOADED
2020-04-18 11:36:52,288 [INFO ] W-9038-squeezenet1_1_1.0 TS_METRICS - W-9038-squeezenet1_1_1.0.ms:2510|#Level:Host|#hostname:f01898723b72.ant.amazon.com,timestamp:1587235012
2020-04-18 11:36:52,957 [INFO ] W-9037-squeezenet1_1_1.0-stdout org.pytorch.serve.wlm.WorkerLifeCycle - Listening on port: /var/folders/86/cslbmm0j0glf7d1qwwltjsvx0sl6df/T//.ts.sock.9037
2020-04-18 11:36:52,958 [INFO ] W-9037-squeezenet1_1_1.0-stdout org.pytorch.serve.wlm.WorkerLifeCycle - [PID]28168
2020-04-18 11:36:52,958 [INFO ] W-9037-squeezenet1_1_1.0-stdout org.pytorch.serve.wlm.WorkerLifeCycle - Torch worker started.
2020-04-18 11:36:52,958 [INFO ] W-9037-squeezenet1_1_1.0-stdout org.pytorch.serve.wlm.WorkerLifeCycle - Python runtime: 3.6.5
2020-04-18 11:36:52,958 [DEBUG] W-9037-squeezenet1_1_1.0 org.pytorch.serve.wlm.WorkerThread - W-9037-squeezenet1_1_1.0 State change WORKER_STOPPED -> WORKER_STARTED
2020-04-18 11:36:52,958 [INFO ] W-9037-squeezenet1_1_1.0 org.pytorch.serve.wlm.WorkerThread - Connecting to: /var/folders/86/cslbmm0j0glf7d1qwwltjsvx0sl6df/T//.ts.sock.9037
2020-04-18 11:36:52,959 [INFO ] W-9037-squeezenet1_1_1.0-stdout org.pytorch.serve.wlm.WorkerLifeCycle - Connection accepted: /var/folders/86/cslbmm0j0glf7d1qwwltjsvx0sl6df/T//.ts.sock.9037.
2020-04-18 11:36:54,321 [INFO ] W-9037-squeezenet1_1_1.0-stdout org.pytorch.serve.wlm.WorkerLifeCycle - Current PID is 28168
2020-04-18 11:36:54,350 [INFO ] W-9037-squeezenet1_1_1.0 org.pytorch.serve.wlm.WorkerThread - Backend response time: 1391
@fbbradheintz Do we want to change existing behavior for registration api with initial workers to have model isolation like scale up and inference api call? Also, can you confirm comments by @vdantu .
Closing due to no activity.