Posts

Showing posts with the label ML Runtimes

Inference: Build an ML Runtime with Rust and K3s | ML Engineering & MLOps

Image
  Hi All  Machine learning (ML) runtimes are the backbone of executing trained models in production, but understanding their inner workings can be daunting for beginners. In this post, we’ll build a ML Runtime in Rust from scratch and deploy it on Kubernetes—a minimal yet functional system that loads, executes, and manages simple ML models.   By focusing on core concepts like model serialization, inference, and basic error handling, we’ll demystify how ML runtimes operate under the hood. This is a hands-on guide for developers who want to bridge the gap between high-level ML frameworks and low-level system design. View the architecture of the ML runtime below, source code available here :        Components Explained: 1. Rust Application ( main.rs ) * Entry point of the program * Uses tch-rs (PyTorch bindings) for ML operations * Contains the model defini...

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 ...

Fine-Tuning Mistral 7B using QLoRA with PyTorch pt. 1: The Model | ML Engineering

Image
     Hi All Today we're working with a popular and slightly bigger model than our previous example. Mistral 7B is capable of chat and light coding tasks, for older hardware it's a winner for sure.  Here's a complete, runnable example of fine-tuning Mistral 7B using QLoRA with the peft , transformers , and bitsandbytes libraries. This example assumes you're working with a single GPU (eg. an A100 or similar). First install the required packages: pip install -q bitsandbytes datasets accelerate peft transformers trl View full script below, also available here :   Full breakdown of the script above, block-by-block. 1.      Dataset Loading dataset = load_dataset("timdettmers/openassistant-guanaco", split="train") *      Loads a preprocessed instruction-following dataset (Guanco, derived from OpenAssistant). *      split="train" selects the training portion *      The dataset is in a conversational ...

Advanced Inference: Model portability across GPU backends (Rocm and Nvidia) Pt. 1 [PyTorch] | ML Engineering

Image
    Hi All I'm aiming to solve some tough issues in the ML backend, and heterogeneous backend support is up there as one of the most pressing . Today we'll be training BERT on a Rocm (AMD) backend and running the binary (inference) on a Nvidia backend.  Training a complex model like BERT (250M+ params) on a ROCm backend and then running the trained model on NVIDIA backend is not impossible, but it comes with some challenges and considerations. Here's a breakdown of the key aspects:  Steps to achieve Cross-Backend Training/Inference Option 1: Train on ROCm, Inference on NVIDIA (Same Framework) 1.     Train the model on AMD GPU's using PyTorch/Tensorflow with ROCm. # Example PyTorch training script (ROCm) import torch device = torch.device("cuda" if torch.cuda.is_available() else "cpu") # ... rest of the training code *      Note: ROCm uses cuda device string for compatibility, but maps it to AMD hardware. 2.      Save t...