serve icon indicating copy to clipboard operation
serve copied to clipboard

Large memory allocation for Hugging Face Transformer Models

Open lessenko opened this issue 5 years ago • 2 comments

Context

  • torchserve version: 0.3.0
  • torch-model-archiver version: 0.3.0
  • torch version: 1.7.0
  • torchvision version [if any]: 0.7.0
  • torchtext version [if any]: not used
  • torchaudio version [if any]: not used
  • java version: openjdk version "11.0.9.1" 2020-11-04
  • Operating System and version: Ubuntu 18.04.2 LTS

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?: CPU
  • Using a default/custom handler?: Transformer_handler_generalized.py
  • What kind of model is it e.g. vision, text, audio?: Text
  • 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.]: no
  • Link to the project: https://github.com/pytorch/serve/tree/master/examples/Huggingface_Transformers

Expected Behavior

The example works correct, but the memory allocation is bigger than expected.

  • The memory allocation of TorchServe is near 4.4 GB.
  • The memore allocation of sample application with same model is near 0.9 GB.

Log file contains message "State change WORKER_STARTED -> WORKER_MODEL_LOADED" is repeated four times. It looks like there are several copies of the same model in memory. Is this feature of TorchServe?

Thanks.

lessenko avatar Jan 18 '21 08:01 lessenko

@lessenko Looks like you have 4 model workers getting started. Each will load its own copy of the model. You can set this to 1 by adding default_workers_per_model=1 in config.properties at startup. More details here. Please reopen if this is still an issue.

maaquib avatar Jan 19 '21 18:01 maaquib

@maaquib Thanks. I used your recomendation. It works.

lessenko avatar Jan 20 '21 06:01 lessenko