Efficiency: Serving multiple models on a single GPU
Hi,
A requirement that I expect to occur relatively frequently is to serve multiple models from a single GPU. With previous serving frameworks such as tensorflow/serving and NVIDIA's tensorRt framework, model checkpoints are optimized/compressed before serving.
This decreases memory footprint on the GPU and makes it easier to serve multiple models from the same GPU device. In the case of tensorflow/serving, one can roughly run inference for 8 BERT models (while training, a single checkpoint occupies roughly 10GB) from a single device.
Is something similar possible with TorchServe/pytorch?
@MFreidank The model compression techniques like quantization, pruning need to be handled as part of the exercise of getting the model ready for production deployment. You should be able to take your quantized model and deploy that to run on TorchServe. Some good tutorials for Quantization and Pruning that you will find helpful.
To speed things up you can also use the TorchScripted version of your model and deploy that on TorchServe. For an example for how to do this please take a look at https://github.com/pytorch/serve/blob/master/examples/image_classifier/README.md#torchscript-example-using-densenet161-image-classifier.
will Serving multiple models on a single GPU help improve the throughput? e.g. get ~3X speedup for 3 models on a single GPU? @dhanainme @chauhang
@SeaOfOcean This is use case specific and you should run your own load tests to figure out the optimal configuration for your models. You can use the benchmarking and snakeviz profiler to help in the analysis. More details here
Another issue for serving multiple models on a single GPU. Since each worker of each model runs in its own process, CUDA context with its constant overhead of ~600MB is replicated across all models/workers. This overhead is critical in our case, where we run ~20 torch models as a pipeline for a single inference run.
I would love to see some kind of automatic GPU memory management, such as model weight statically stores in the main memory while being loaded onto GPU only during computation, and worker threads sharing the same GPU context.
Closing as the original query has been answered.
@ematvey: The memory footprint optimization is being tracked through #733
Another issue for serving multiple models on a single GPU. Since each worker of each model runs in its own process, CUDA context with its constant overhead of ~600MB is replicated across all models/workers. This overhead is critical in our case, where we run ~20 torch models as a pipeline for a single inference run.
I would love to see some kind of automatic GPU memory management, such as model weight statically stores in the main memory while being loaded onto GPU only during computation, and worker threads sharing the same GPU context.
@ematvey could you please share what configs you made to run multiple models in parallel ? we're trying to run 8 workers (model instances) of the same model to hopefully process 7-8 requests by the same response time as one request, were you able to achieve this ?
Another issue for serving multiple models on a single GPU. Since each worker of each model runs in its own process, CUDA context with its constant overhead of ~600MB is replicated across all models/workers. This overhead is critical in our case, where we run ~20 torch models as a pipeline for a single inference run. I would love to see some kind of automatic GPU memory management, such as model weight statically stores in the main memory while being loaded onto GPU only during computation, and worker threads sharing the same GPU context.
@ematvey could you please share what configs you made to run multiple models in parallel ? we're trying to run 8 workers (model instances) of the same model to hopefully process 7-8 requests by the same response time as one request, were you able to achieve this ?
I don't think one can achieve ~8 times through put by setting 8 workers in one GPU. Usually GPU is the bottleneck of the computation.