Giter Site home page Giter Site logo

yh646492956 / bert-cpp-inference Goto Github PK

View Code? Open in Web Editor NEW

This project forked from renatoviolin/bert-cpp-inference

0.0 1.0 0.0 1.38 MB

License: GNU General Public License v3.0

Python 1.11% CMake 2.88% C++ 43.03% C 2.63% Makefile 50.33% TypeScript 0.01%

bert-cpp-inference's Introduction

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

bert-cpp-inference's People

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.