FixTheRobot Explore Robotics / LLM / LM8 / LM8-L2

This lab works on phones, but writing code is much easier on a laptop.

LLM · Efficient Fine-Tuning and Model Adaptation · LM8-L2 · Advanced

LoRA Low-Rank Update Numerics

LoRA rests on one observation and one identity. The observation: the change a task needs in a weight matrix is often well captured by a few directions. The identity: a product of two thin matrices is a matrix of low rank, and can be added to the weight after training.

You will find how much rank a constructed update needs, write the forward pass, and merge the adapter into the weights.

Your task

    Simulation
    solution.pyLoading Python…
    Ctrl+Enter runs
    What Python can I use?

    Plain Python with math (and slamkit for small matrix helpers: matmul, transpose, solve, inverse, identity). Images, point clouds and detections arrive as lists inside the dictionary D; an image is a list of rows, each row a list of pixels. There is no NumPy or OpenCV: you write the algorithm yourself, which is the point of the lab. Print with print().

    Hints

    What this lab teaches

    Stage 1 explores the trade-off between the rank and the part of an update that can be represented. Stage 2 computes the LoRA forward pass. Stage 3 merges the adapter and counts parameters. The matrices are small and constructed; no model is trained. Your code is graded on hidden matrices.

    Theory for this lab

    Efficient Fine-Tuning and Model Adaptation labs

    1. LM8-L1: Estimate Trainable Parameters and Memory
    2. LM8-L2: LoRA Low-Rank Update Numerics: this lab.
    3. LM8-L3: LoRA Fine-Tuning Experiment

    Educational simplification: a 16 × 16 update with five known singular values, matrices of a few rows and columns, plain Python lists. Real LoRA layers have thousands of rows and columns and are trained by gradient descent; the update of a trained model is not known in advance. All data in this lab are invented.

    Get the next lab

    Get notified when new robotics labs are released. One email per new lab, nothing else.