serve icon indicating copy to clipboard operation
serve copied to clipboard

How to avoid contention between models, workers and runtime parallelism?

Open la-cruche opened this issue 6 years ago • 4 comments

Hi! this is a question, not an issue

I see that TorchServe can serve multiple models or multiple workers per model. For example the AWS blog says "If your model is hosted on a CPU with many cores such as the c5.24xlarge EC2 instance with 96 vCPUs, you can easily scale the number of threads by using the method described previously"

So I see possibly up to 3 things competing for cores:

  • multiple models
  • multiple workers per model
  • multiple threads of the inference runtime running in each worker

Is that understanding correct? How is TorchServe handling that triple level of parallelism? Is there any best practice or settings to tune?

la-cruche avatar Jun 15 '20 09:06 la-cruche

@la-cruche

There are two levels of parallelism in TorchServe :

  • Frontend model workers: Whenever a new worker is added to a model, a corresponding new java thread is created.
  • Backend model workers: Each frontend model worker(java thread) creates a backend python process that is responsible for loading the model and running the inference.

The frontend and backend workers work in tandem for every inference request.

For more details refer TorchServe architecture documentation.

Refer this documentation for best practices to tune the number of workers.

harshbafna avatar Jun 15 '20 09:06 harshbafna

Closing. @la-cruche please reopen if you need any further infromation regarding this

maaquib avatar Aug 10 '20 18:08 maaquib

Hi, I have a follow-up question: I see in TorchServe only the ability to configure a number of model workers. But how about the ability to configure the number of CPU allocated to a single model worker? Let's take this fictional example: I have a model deployed in TorchServe over an 8-CPU machine. I want to create 2 model workers, using 4 CPU each. How can I configure than in TorchServe?

(that refers to the third level of parallelism mentioned in my initial question, "multiple threads of the inference runtime running in each worker")

la-cruche avatar Oct 12 '20 20:10 la-cruche

@la-cruche There is no direct config to do this.

codinnvrends avatar Oct 22 '20 04:10 codinnvrends