Posts

Showing posts with the label FastApi

The Training Duo: DeepSpeed & PyTorch with ONNX | ML Engineering & MLOps

Image
  Hi All Deep learning models often demand significant computational resources, making training slow and memory intensive. PyTorch, a popular deep learning framework, provides flexibility but requires manual optimization for large scale training.  Enter DeepSpeed , a library designed to accelerate training by automating mixed precision, gradient accumulation, and memory optimization techniques like ZeRO (Zero Redundancy Optimizer).  In this post, we'll walk though a simple PyTorch model enhanced with DeepSpeed , demonstrating how it can dramatically improve training efficiency with minimal code changes, then running inference on ONNX runtime. Whether you're working with a single GPU or scaling to multi-GPU setups, DeepSpeed simplifies the process while maximizing performance.  Full training.py source and architecture below:   Let's breakdown the above code, block by block.   1. Simple Neural Network (` Simple Model ` class)  import torch import ...

Deploying LoRA Optimised BERT as a FastApi service on GKE | ML Engineering & MLOps

Image
  Hi All  Alright today on "Bored MLE" we're doing some inference, using a LoRA optimized BERT model on GKE . Now there's a lot more to MLOps than just this (like cluster level observability for example), but for this example I'm keeping it brief.  The full code is available on GitHub with added minikube deployment instructions (I only cover the Cloud deployment here).    I assume familiarity with Python, PyTorch, K8s, FastApi, Minikube and GKE. Let's get on with it.  View the full FastApi service source below, also available here : Let's breakdown the above code, block by block. 0. Install Dependencies :  pip install fastapi uvicorn torch transformers peft accelerate  1. Imports from fastapi import FastAPI, HTTPException from pydantic import BaseModel from typing import List import torch from transformers import AutoModelForSequenceClassification, AutoTokenizer from peft import PeftModel, PeftConfig  *      fastapi : F...