Posts

Showing posts with the label onnx

Mixture Of Experts Architecture with PyTorch & ONNX Pt. 1: The Model | ML Engineering & MLOps

Image
  Hi All Mixture of Experts is a ML technique where multiple expert networks ( learners ) are used to divide a problem space into homogeneous regions. MoE represents a form of ensemble learning. They were also called committee machines.   Both the experts and the weighting function are trained by minimizing some loss function, generally via gradient descent . There is much freedom in choosing the precise form of experts , the weighting function, and the loss function.   This model uses BERT's transformer architecture as the base (BERT LARGE around 350M params), and implements a Mixture of Experts architecture with 8 experts by default.    The model.py source  and architecture detailed below. The full PyTorch, ONNX MoE application source code can be found here .       1. Expert Network ( ` Expert ` class)  class Expert(nn.Module): """A single expert network (feed-forward network)""" def __init__(self, input_d...

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. 2: K8s & GKE | ML Engineering & MLOps

Image
  Hi All Continuing from Part 1, this post details the Kubernetes and Observability configs of the project. The full source is available here . Let's break the code down shall we.  1. K3's Server Config ( infra/server-config.yaml )  write-kubeconfig-mode: "0644"  *      Sets file permissions for kubeconfig file (readable by all users in the group) *      0644 means owner can read/write, group and others can only read disable: - traefik - servicelb - local-storage - metrics-server *      Disables default k3s components that we'll replace with better alternatives. Components Disabled: *      _traefik: Replaced with ingress-nginx for better control *      _servicelb: Replaced with MetalLB or cloud load balancer *      _local-storage: Replaced with Longhon for dynamic provisioning *      _metrics-server: Replaced with Prometheus for better monit...