<!-- mobian-agent-page publisher="dailydev" canonical="https://daily.dev/posts/the-math-behind-using-lora-to-fine-tune-llms-usfdeddly" -->

---
title: The Math Behind Using LoRA to Fine-Tune LLMs | daily.dev
description: LoRA fine-tunes an LLM by freezing the original weight matrix W and training two small matrices, A and B, whose product fills the gap. With rank 2 on a 5 x 5...
canonical: https://daily.dev/posts/the-math-behind-using-lora-to-fine-tune-llms-usfdeddly
twitter:card: summary_large_image
twitter:site: @dailydotdev
og:type: website
og:site_name: daily.dev
og:title: The Math Behind Using LoRA to Fine-Tune LLMs | daily.dev
og:description: LoRA fine-tunes an LLM by freezing the original weight matrix W and training two small matrices, A and B, whose product fills the gap. With rank 2 on a 5 x 5...
og:url: https://daily.dev/posts/the-math-behind-using-lora-to-fine-tune-llms-usfdeddly
og:image: https://api.daily.dev/og/posts/uSFdEDDly.png
og:image:alt: The Math Behind Using LoRA to Fine-Tune LLMs
og:image:width: 1200
og:image:height: 630
og:locale: en
---

> ## Documentation Index
> Fetch the complete documentation index at: https://daily.dev/llms.txt
> Use this file to discover all available pages before exploring further.

# The Math Behind Using LoRA to Fine-Tune LLMs

**[freeCodeCamp](https://daily.dev/sources/freecodecamp)** · [@busycaesar](https://daily.dev/busycaesar) · 14 min read · 71 upvotes · 5 comments

## Summary

LoRA fine-tunes an LLM by freezing the original weight matrix W and training two small matrices, A and B, whose product fills the gap. With rank 2 on a 5 x 5 example, A and B hold 20 weights versus W's 25. On gemma3_instruct_1b with rank 4, trainable parameters drop from 999,885,952 to 652,288, about 0.065%. B starts at all zeros, so the first forward pass matches the base model. The loop is forward pass, loss, backward pass, repeated over epochs. The trained matrices are saved as a separate adapter you can swap per task. Two notebooks accompany it.

## Full article

daily.dev links to this article rather than hosting it. Read it at the original source: <https://www.freecodecamp.org/news/the-math-behind-using-lora-to-fine-tune-llms>

## Community discussion

Top comments from developers on daily.dev.

**@andrewma** · 5 upvotes

> cool video!

**@kartiknvj** · 2 upvotes

> Since the effective weight is just W plus (α/r)(A x B), I can fold that product into W when one task is all I serve, so base and adapter become one set of weights. When I need to swap per task, like your dark mode and bullet-point adapters, I keep A and B in their separate file instead.

**@sachchidanand** · 1 upvotes

> Should I go to school again to learn maths ?

**@arslana4** · 0 upvotes

> The 5x5 rank-2 example makes the parameter savings click. Worth adding that rank is a real trade-off: too low and the adapter can't capture the new task, too high and you give back most of the memory win. Nice that it's grounded in an actual Gemma run, not just the formula.

## Similar posts on daily.dev

- [LoRA: Fine-Tuning Billion-Parameter LLMs on a Single GPU](https://daily.dev/posts/lora-fine-tuning-billion-parameter-llms-on-a-single-gpu-0myhkubfu) · Medium · 1 upvotes · 0 comments
- [What is LoRA and how it lets anyone fine-tune a massive AI model on a single GPU](https://daily.dev/posts/what-is-lora-and-how-it-lets-anyone-fine-tune-a-massive-ai-model-on-a-single-gpu-vfwx1br5h) · Medium · 2 upvotes · 0 comments
- [How to Customize a Model to Learn New Tricks](https://daily.dev/posts/how-to-customize-a-model-to-learn-new-tricks-jdilpyuft) · ByteByteGo · 1 upvotes · 1 comments
- [\[2602.04118\] Learning to Reason in 13 Parameters](https://daily.dev/posts/2602-04118-learning-to-reason-in-13-parameters-fgsqvuufg) · Hacker News · 1 upvotes · 0 comments

---

Tags: [#llm](https://daily.dev/tags/llm), [#deep-learning](https://daily.dev/tags/deep-learning), [#math](https://daily.dev/tags/math), [#gemma](https://daily.dev/tags/gemma), [#lora](https://daily.dev/tags/lora)

[View this post on daily.dev](https://daily.dev/posts/the-math-behind-using-lora-to-fine-tune-llms-usfdeddly)

```json
{"@context":"https://schema.org","@graph":[{"@type":"Organization","@id":"https://daily.dev/#organization","name":"daily.dev","url":"https://daily.dev","logo":{"@type":"ImageObject","url":"https://daily.dev/apple-touch-icon.png","width":180,"height":180},"sameAs":["https://twitter.com/dailydotdev","https://github.com/dailydotdev","https://www.linkedin.com/company/daily-dev-ltd"]},{"@type":"WebSite","@id":"https://daily.dev/#website","url":"https://daily.dev","name":"daily.dev","publisher":{"@id":"https://daily.dev/#organization"},"potentialAction":{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https://daily.dev/search?q={search_term_string}"},"query-input":"required name=search_term_string"}}]}
{"@context":"https://schema.org","@type":"TechArticle","headline":"The Math Behind Using LoRA to Fine-Tune LLMs","url":"https://daily.dev/posts/the-math-behind-using-lora-to-fine-tune-llms-usfdeddly","mainEntityOfPage":{"@type":"WebPage","@id":"https://daily.dev/posts/the-math-behind-using-lora-to-fine-tune-llms-usfdeddly"},"datePublished":"2026-12-02T22:47:35.468Z","dateModified":"2026-12-03T19:00:10.465Z","description":"LoRA fine-tunes an LLM by freezing the original weight matrix W and training two small matrices, A and B, whose product fills the gap. With rank 2 on a 5 x 5...","image":"https://media.daily.dev/image/upload/f_auto,q_auto/v1/posts/e0bbf3cf800ed8ba1b65e9ddadfaf5b6?_a=AQAEuop","thumbnailUrl":"https://media.daily.dev/image/upload/f_auto,q_auto/v1/posts/e0bbf3cf800ed8ba1b65e9ddadfaf5b6?_a=AQAEuop","isAccessibleForFree":true,"articleSection":"freeCodeCamp","inLanguage":"en","publisher":{"@type":"Organization","name":"daily.dev","url":"https://daily.dev","logo":{"@type":"ImageObject","url":"https://daily.dev/apple-touch-icon.png","width":180,"height":180}},"author":{"@type":"Person","name":"Dev J. Shah 🥑","url":"https://daily.dev/busycaesar","image":"https://avatars.githubusercontent.com/u/97539345?v=4","description":"SWE @TribalScale, GenAI Evangelist (Blogger, Speaker) || 3x Multi-Cloud Certified","interactionStatistic":{"@type":"InteractionCounter","interactionType":{"@type":"EndorseAction"},"userInteractionCount":260}},"commentCount":5,"discussionUrl":"https://daily.dev/posts/the-math-behind-using-lora-to-fine-tune-llms-usfdeddly","interactionStatistic":[{"@type":"InteractionCounter","interactionType":{"@type":"LikeAction"},"userInteractionCount":71},{"@type":"InteractionCounter","interactionType":{"@type":"CommentAction"},"userInteractionCount":5}],"keywords":"llm,deep-learning,math,gemma,lora","timeRequired":"PT14M"}
{"@context":"https://schema.org","@type":"BreadcrumbList","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https://daily.dev"},{"@type":"ListItem","position":2,"name":"freeCodeCamp","item":"https://daily.dev/sources/freecodecamp"},{"@type":"ListItem","position":3,"name":"The Math Behind Using LoRA to Fine-Tune LLMs"}]}
{"@context":"https://schema.org","@type":"WebPage","@id":"https://daily.dev/posts/the-math-behind-using-lora-to-fine-tune-llms-usfdeddly","comment":[{"@type":"Comment","text":"cool video!","datePublished":"2026-12-03T08:24:17.169Z","url":"https://daily.dev/posts/uSFdEDDly#c-bqMuuLWu1","author":{"@type":"Person","name":"Andrew M","url":"https://daily.dev/andrewma","image":"https://avatars.githubusercontent.com/u/102819214?v=4"},"interactionStatistic":{"@type":"InteractionCounter","interactionType":{"@type":"LikeAction"},"userInteractionCount":5}},{"@type":"Comment","text":"Since the effective weight is just W plus (α/r)(A x B), I can fold that product into W when one task is all I serve, so base and adapter become one set of weights. When I need to swap per task, like your dark mode and bullet-point adapters, I keep A and B in their separate file instead.","datePublished":"2026-12-03T19:33:19.866Z","url":"https://daily.dev/posts/uSFdEDDly#c-L0YJI3yYM","author":{"@type":"Person","name":"kartik-nvjk","url":"https://daily.dev/kartiknvj","image":"https://media.daily.dev/image/upload/s--3gGgsVCw--/f_auto/v1781456774/avatars/avatar_TvTVeiMdkRCqWUDullFmy?_a=BAMAMiWQ0"},"interactionStatistic":{"@type":"InteractionCounter","interactionType":{"@type":"LikeAction"},"userInteractionCount":2}},{"@type":"Comment","text":"Should I go to school again to learn maths ?","datePublished":"2026-12-03T11:01:23.676Z","url":"https://daily.dev/posts/uSFdEDDly#c-3euFT2Uaj","author":{"@type":"Person","name":"Sachchidanand Chitnis","url":"https://daily.dev/sachchidanand","image":"https://media.daily.dev/image/upload/s--QUfblGFP--/f_auto/v1782972312/avatars/avatar_1EhzrM1K8RjvlbJPwRfP6?_a=BAMAMicg0"},"interactionStatistic":{"@type":"InteractionCounter","interactionType":{"@type":"LikeAction"},"userInteractionCount":1}},{"@type":"Comment","text":"The 5x5 rank-2 example makes the parameter savings click. Worth adding that rank is a real trade-off: too low and the adapter can’t capture the new task, too high and you give back most of the memory win. Nice that it’s grounded in an actual Gemma run, not just the formula.","datePublished":"2026-12-06T00:49:08.995Z","url":"https://daily.dev/posts/uSFdEDDly#c-EvxmwQymu","author":{"@type":"Person","name":"Arslan Ahmad","url":"https://daily.dev/arslana4","image":"https://media.daily.dev/image/upload/s--uqaKkLUk--/f_auto,q_auto/v1/avatars/avatar_eaY5cld3PAQk2zpphnPSN"}}]}
```

