Skip to content

renatoviolin/BERT-cpp-inference

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Deploying Deep Learning Models in C++: BERT Language Model

This repository show the code to deploy a deep learning model serialized and running in C++ backend.

For the sake of comparison, the same model was loaded using PyTorch JIT and ONNX Runtime.

The C++ server can be used as a code template to deploy another models.

Results

The test consist of make 100 async calls to the server. The client measure the time taken to get the response of the 100 requests. To reduce variability it is performed 10x, i.e, 1000 requests.

  • The results was obtained in a Macbook Pro with a i7 6C-12T CPU.
  • The CPU fans was set the max to reduce any possible thermal-throttling.
  • Before start each test the temps was lowered down around 50 C.

Model Details

  • Model: BERT Large uncased pretrained from hugginface.
  • Input: Text with [MASK] token to be predicted
  • Output: Tensor in shape (seq_len, 30522)

Python server details

FastAPI web-app server running by hypercorn with 6 workers (adjust this by the number of threads you have).

C++ server details

To deploy the model in C++ it was used the same serialized model used in JIT runtime. The model is loaded using libtorch C++ API. To deploy as a http-server, it is used crow. The server is started in multithreaded mode.

  • server-cpp/server.cpp: Code to generate the c++ application that load the model and start the http server on port 8000.

Deploy a model in C++ is not as straightforward as it is in Python. Check the libs folder for more details about the codes used.

Client details

Client uses async and multi-thread to perform as many requests as possible in parallel. See the test_api.py

TO-DO

  • Experiment on CUDA device.
  • Experiment another models like BERT.
  • Exprimento quantized models.

References

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published