serve icon indicating copy to clipboard operation
serve copied to clipboard

Worker dies, unclear error message given

Open nihiluis opened this issue 6 years ago • 4 comments

Your issue may already be reported! Please search on the issue tracker before creating one.

Thank you for the lib.

Context

  • torchserve version: 0.1.1
  • torch version: 1.5.1
  • torchvision version [if any]:
  • torchtext version [if any]:
  • torchaudio version [if any]:
  • java version: 11.0.7
  • Operating System and version: arch linux

Your Environment

  • Installed using source? [yes/no]:no

  • Are you planning to deploy it using docker container? [yes/no]:no

  • Is it a CPU or GPU environment?:both

  • Using a default/custom handler? [If possible upload/share custom handler/model]: yes

  • What kind of model is it e.g. vision, text, audio?:text from huggingface transforomers, then saved via torch.save(model, "./x"). used this guide: https://medium.com/analytics-vidhya/deploy-huggingface-s-bert-to-production-with-pytorch-serve-27b068026d18

  • Are you planning to use local models from model-store or public url being used e.g. from S3 bucket etc.? [If public url then provide link.]: local models

  • Provide config.properties, logs [ts.log] and parameters used for model registration/update APIs:

  • Link to your project [if any]:

Expected Behavior

give me some directions on how my model is corrupted

or

don't die

Current Behavior

worker dies but no indications are given on why it does

Possible Solution

Steps to Reproduce

1. 2. ...

this is the code. I'm pretty sure the preprocessing is wrong, but haven't had a chance to test it yet. maybe that's a reason why it fails? seems unlikely though.

I use this model: elgeish/cs224n-squad2.0-albert-base-v2

from abc import ABC
import json
import logging
import os

import torch
from transformers import AutoModelForQuestionAnswering, AutoTokenizer

from ts.torch_handler.base_handler import BaseHandler

logger = logging.getLogger(__name__)


class TransformersQuestionAnswerHandler(BaseHandler, ABC):
    """
    Transformers text classifier handler class. This handler takes a text (string) and
    as input and returns the classification text based on the serialized transformers checkpoint.

    Adapted from https://medium.com/analytics-vidhya/deploy-huggingface-s-bert-to-production-with-pytorch-serve-27b068026d18
    """
    def __init__(self):
        super(TransformersQuestionAnswerHandler, self).__init__()
        self.initialized = False

    def initialize(self, ctx):
        self.manifest = ctx.manifest

        properties = ctx.system_properties
        model_dir = properties.get("model_dir")
        self.device = torch.device("cuda:" + str(properties.get("gpu_id")) if torch.cuda.is_available() else "cpu")

        # Read model serialize/pt file
        self.model = AutoModelForQuestionAnswering.from_pretrained(model_dir)
        self.tokenizer = AutoTokenizer.from_pretrained(model_dir)

        self.model.to(self.device)
        self.model.eval()

        logger.debug('Transformer model from path {0} loaded successfully'.format(model_dir))

        self.initialized = True

    def preprocess(self, data):
        """ Very basic preprocessing code - only tokenizes. 
            Extend with your own preprocessing steps as needed.
        """
        body = data[0].get("data")
        if body is None:
            body = data[0].get("body")

        question = body.get("question")
        text = body.get("text")
        
        decoded_text = text.decode('utf-8')
        logger.info("Received text: '%s'", decoded_text)

        inputs = self.tokenizer.encode_plus(
            question,
            text,
            add_special_tokens=True,
            return_tensors="pt"
        )
        return inputs

    def inference(self, inputs):
        """
        Predict the answer for a question in the text using a trained transformer model.
        """
        input_ids = inputs["input_ids"].tolist()[0]

        answer_start_scores, answer_end_scores = self.model(**inputs)

        answer_start = torch.argmax(
            answer_start_scores
        )  # Get the most likely beginning of answer with the argmax of the score
        answer_end = torch.argmax(answer_end_scores) + 1  # Get the most likely end of answer with the argmax of the score

        answer = self.tokenizer.convert_tokens_to_string(self.tokenizer.convert_ids_to_tokens(input_ids[answer_start:answer_end]))

        return [answer]

    def postprocess(self, inference_output):
        return inference_output


_service = TransformersQuestionAnswerHandler()

def handle(data, context):
    try:
        if not _service.initialized:
            _service.initialize(context)

        if data is None:
            return None

        data = _service.preprocess(data)
        data = _service.inference(data)
        data = _service.postprocess(data)

        return [data]
    except Exception as e:
        raise e

Failure Logs [if any]

2020-07-05 14:38:58,251 [INFO ] main org.pytorch.serve.ModelServer - Loading initial models: albert_squad.mar 2020-07-05 14:38:58,627 [DEBUG] main org.pytorch.serve.wlm.ModelVersionedRefs - Adding new version 1.0 for model albert_squad 2020-07-05 14:38:58,627 [DEBUG] main org.pytorch.serve.wlm.ModelVersionedRefs - Setting default version to 1.0 for model albert_squad 2020-07-05 14:38:58,627 [INFO ] main org.pytorch.serve.wlm.ModelManager - Model albert_squad loaded. 2020-07-05 14:38:58,627 [DEBUG] main org.pytorch.serve.wlm.ModelManager - updateModel: albert_squad, count: 1 2020-07-05 14:38:58,634 [INFO ] main org.pytorch.serve.ModelServer - Loading initial models: qgen.mar 2020-07-05 14:38:58,729 [INFO ] W-9000-albert_squad_1.0-stdout org.pytorch.serve.wlm.WorkerLifeCycle - Listening on port: /tmp/.ts.sock.9000 2020-07-05 14:38:58,730 [INFO ] W-9000-albert_squad_1.0-stdout org.pytorch.serve.wlm.WorkerLifeCycle - [PID]106191 2020-07-05 14:38:58,730 [INFO ] W-9000-albert_squad_1.0-stdout org.pytorch.serve.wlm.WorkerLifeCycle - Torch worker started. 2020-07-05 14:38:58,730 [INFO ] W-9000-albert_squad_1.0-stdout org.pytorch.serve.wlm.WorkerLifeCycle - Python runtime: 3.8.3 2020-07-05 14:38:58,731 [DEBUG] W-9000-albert_squad_1.0 org.pytorch.serve.wlm.WorkerThread - W-9000-albert_squad_1.0 State change null -> WORKER_STARTED 2020-07-05 14:38:58,737 [INFO ] W-9000-albert_squad_1.0 org.pytorch.serve.wlm.WorkerThread - Connecting to: /tmp/.ts.sock.9000 2020-07-05 14:38:58,788 [INFO ] W-9000-albert_squad_1.0-stdout org.pytorch.serve.wlm.WorkerLifeCycle - Connection accepted: /tmp/.ts.sock.9000. 2020-07-05 14:38:59,213 [INFO ] W-9000-albert_squad_1.0-stdout org.pytorch.serve.wlm.WorkerLifeCycle - Backend worker process died. 2020-07-05 14:38:59,213 [INFO ] W-9000-albert_squad_1.0-stdout org.pytorch.serve.wlm.WorkerLifeCycle - Traceback (most recent call last): 2020-07-05 14:38:59,213 [INFO ] W-9000-albert_squad_1.0-stdout org.pytorch.serve.wlm.WorkerLifeCycle - File "/run/media/pablo/084A2BF94A2BE264/ml/venv_torch/lib/python3.8/site-packages/ts/model_loader.py", line 85, in load 2020-07-05 14:38:59,214 [INFO ] W-9000-albert_squad_1.0-stdout org.pytorch.serve.wlm.WorkerLifeCycle - module = importlib.import_module(module_name) 2020-07-05 14:38:59,214 [INFO ] W-9000-albert_squad_1.0-stdout org.pytorch.serve.wlm.WorkerLifeCycle - File "/usr/lib/python3.8/importlib/init.py", line 127, in import_module 2020-07-05 14:38:59,214 [INFO ] W-9000-albert_squad_1.0-stdout org.pytorch.serve.wlm.WorkerLifeCycle - return _bootstrap._gcd_import(name[level:], package, level) 2020-07-05 14:38:59,214 [INFO ] epollEventLoopGroup-4-1 org.pytorch.serve.wlm.WorkerThread - 9000 Worker disconnected. WORKER_STARTED 2020-07-05 14:38:59,214 [INFO ] W-9000-albert_squad_1.0-stdout org.pytorch.serve.wlm.WorkerLifeCycle - File "", line 1014, in _gcd_import 2020-07-05 14:38:59,215 [INFO ] W-9000-albert_squad_1.0-stdout org.pytorch.serve.wlm.WorkerLifeCycle - File "", line 991, in _find_and_load 2020-07-05 14:38:59,215 [DEBUG] W-9000-albert_squad_1.0 org.pytorch.serve.wlm.WorkerThread - System state is : WORKER_STARTED 2020-07-05 14:38:59,215 [INFO ] W-9000-albert_squad_1.0-stdout org.pytorch.serve.wlm.WorkerLifeCycle - File "", line 975, in _find_and_load_unlocked 2020-07-05 14:38:59,215 [INFO ] W-9000-albert_squad_1.0-stdout org.pytorch.serve.wlm.WorkerLifeCycle - File "", line 671, in _load_unlocked 2020-07-05 14:38:59,215 [DEBUG] W-9000-albert_squad_1.0 org.pytorch.serve.wlm.WorkerThread - Backend worker monitoring thread interrupted or backend worker process died. java.lang.InterruptedException at java.base/java.util.concurrent.locks.AbstractQueuedSynchronizer$ConditionObject.reportInterruptAfterWait(AbstractQueuedSynchronizer.java:2056) at java.base/java.util.concurrent.locks.AbstractQueuedSynchronizer$ConditionObject.awaitNanos(AbstractQueuedSynchronizer.java:2133) at java.base/java.util.concurrent.ArrayBlockingQueue.poll(ArrayBlockingQueue.java:432) at org.pytorch.serve.wlm.WorkerThread.run(WorkerThread.java:129) at java.base/java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:515) at java.base/java.util.concurrent.FutureTask.run(FutureTask.java:264) at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1128) at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:628) at java.base/java.lang.Thread.run(Thread.java:834) 2020-07-05 14:38:59,215 [INFO ] W-9000-albert_squad_1.0-stdout org.pytorch.serve.wlm.WorkerLifeCycle - File "", line 783, in exec_module 2020-07-05 14:38:59,218 [WARN ] W-9000-albert_squad_1.0 org.pytorch.serve.wlm.BatchAggregator - Load model failed: albert_squad, error: Worker died.


nihiluis avatar Jul 05 '20 12:07 nihiluis

Facing Same issue on Ubuntu 18 on CPU. Simple command torchserve --start --ncs --model-store model_store --models densenet161.mar from the example can't bring up the torchserver

abmitra84 avatar Jul 07 '20 10:07 abmitra84

@nihiluis The preprocessor method has issues. Correct method -

def preprocess(self, data):
        """ Very basic preprocessing code - only tokenizes. 
            Extend with your own preprocessing steps as needed.
        """
        text = data[0].get("data")
        if text is None:
            text = data[0].get("body")
        input_text = text.decode('utf-8')

        logger.info("Received decoded text: '%s'", input_text)

        question_context= ast.literal_eval(input_text)
        question = question_context["question"]
        context = question_context["context"]
        inputs = self.tokenizer.encode_plus(question, context, add_special_tokens=True,return_tensors="pt")

        return inputs

However, given logs are pointing towards model/model handler loading error instead of preprocessing error which occurs during prediction call.

As there was no concrete info around this issue, I went ahead and built this example using some of your code and our existing BERT example. Here is the End to End code for your QnA model. Clone repo (git clone ) and then git checkout issue_498 branch and just follow README to deploy your model!! It works fine without any issues.

NOTE - Our existing BERT example has issue in inference input for QnA transformation.

codinnvrends avatar Jul 07 '20 10:07 codinnvrends

Facing Same issue on Ubuntu 18 on CPU. Simple command torchserve --start --ncs --model-store model_store --models densenet161.mar from the example can't bring up the torchserver

Can you please post logs for this. Looks like you are planning to use densenet-161 which is not a Huggingface BERT model hence can you please create a separate issue for this.

codinnvrends avatar Jul 07 '20 10:07 codinnvrends

Closing due to lack of activity. @nihiluis @abmitra84 Please reopen if the solution provided by @dhaniram-kshirsagar doesn't resolve this

maaquib avatar Aug 10 '20 18:08 maaquib