Posts

Showing posts with the label LLM

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

Post-training GPT Neo 1B with Rust & PyTorch Pt. 1 | ML Engineering

Image
 Hi All  Today we have an example of post-training a small model (GPT Neo 1B) in pure Rust. This example focuses of the training loop and model updates, assuming you've already loaded the model weights. Key Areas : 1.      Model Loading : We'll use the rust-bert crate for model loading. (supports GPT-Neo) 2.      Training Loop : Pure Rust implementation with tch-rs (Torch bindings) for tensor operations. 3.      Optimizer : AdamW optimizer for training.   View full code example below: The following is a block-by-block breakdown of the Rust post-training code above.   1. Dependencies and Imports use tch::{nn, Device, Tensor, Kind}; // Torch bindings for Rust use rust_bert::pipelines::common::ModelType; // Model types (GPT-Neo/Llama) use rust_bert::pipelines::text_generation::TextGenerationModel; // Model pipeline use anyhow::Result; // Error handling *      tch - Rust binding for PyTorch *  ...