This repository is meant to be a personal exercise on MLOPS for the NLP task. The exercise covers many crucial steps of MLOPS. Here are the key points from this project.
- Use a SOTA model from huggingface, here I used BERT.
- Train on a NLP datasets using the dataset library, here we used iMDB.
- Make configuration and reproducibility easier with hydra.
- Use a modern ML library, I used Pytorch Lightning.
- Make the model trainable on Apple Silicon with Torch 1.12.
- Finetune model with logging and tracking using wandb.
- Find best hyper parameters by performing a sweep using wandb sweep.
- Deploy model on a REST API with Flask to perform HTML POST request on a server.
- Make the model sharable using Docker to build an image.
- Benchmark the Flask API using wrk.
git clone bert-sentimental-analysis
pip install -r requirements.txt
The model can be trained on CPU, GPU or Apple Silicon by running the command python train.py
. The pre-trained BERT model and iMDB dataset should be downloaded. The best hyperparameters are already set in the config
folder.
Once the ckpt
checkpoint is obtained, simply put the path in app.py
and start the flask server:
FLASK_APP=app.py flask run
One can then perform HTML request to the REST API, an example is given in test_app.py
.
To build a docker image, simply run:
docker build -f Dockerfile -t bert:train .