<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Vladimir Malinovskii on Medium]]></title>
        <description><![CDATA[Stories by Vladimir Malinovskii on Medium]]></description>
        <link>https://medium.com/@galqiwi?source=rss-924a86371b2b------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*_8cjg4WT5MsTZENDlMwcdw.jpeg</url>
            <title>Stories by Vladimir Malinovskii on Medium</title>
            <link>https://medium.com/@galqiwi?source=rss-924a86371b2b------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Mon, 23 Nov 2026 09:55:30 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@galqiwi/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Try Llama 3.1 8B in Your Browser: AQLM.rs Delivers Al at Your Fingertips]]></title>
            <link>https://medium.com/yandex/try-llama-3-1-8b-in-your-browser-aqlm-rs-delivers-al-at-your-fingertips-a6dec439cdf3?source=rss-924a86371b2b------2</link>
            <guid isPermaLink="false">https://medium.com/p/a6dec439cdf3</guid>
            <category><![CDATA[llama-3]]></category>
            <category><![CDATA[model-quantization]]></category>
            <category><![CDATA[llama-3-1-8b]]></category>
            <category><![CDATA[rust]]></category>
            <category><![CDATA[llm]]></category>
            <dc:creator><![CDATA[Vladimir Malinovskii]]></dc:creator>
            <pubDate>Fri, 27 Dec 2024 14:14:44 GMT</pubDate>
            <atom:updated>2024-12-27T17:00:51.562Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*d9uVGELDlDrC5KZOHObNBQ.png" /></figure><p>I’ve always been captivated by the idea of running large language models directly on user devices. There’s something magical about running Llama 3.1 8B on your computer or smartphone.</p><p>In this post, I’ll introduce you to <a href="https://galqiwi.github.io/aqlm-rs/about.html">AQLM.rs</a>, my latest pet project that brings Llama 3.1 8B to your browser using WebAssembly. This implementation is made possible by a compression algorithm from <a href="https://research.yandex.com/">Yandex Research</a>, which allows this advanced language model to run without a GPU directly in your browser.</p><p>You can try it out yourself on the <a href="https://galqiwi.github.io/aqlm-rs/about.html">project website</a>. Now, let’s dive into how it works.</p><h3>Why choose the 8B model?</h3><p>While running language models on user devices isn’t new — models like Llama 3.2 1B and 3B were explicitly designed for low-power devices, the 8B Llama model presents an ideal opportunity to showcase the capabilities of advanced compression algorithms in a browser environment.</p><p>To put this in perspective, let’s look at the model’s memory requirements: each parameter requires 16 bits in its uncompressed form, making the 8B model approximately 16 GB. Standard 4-bit compression methods like nf4 can reduce this to 4 GB.</p><p>Our extreme compression approach takes this further, using just 2 bits per parameter and compressing the model body by a factor of 8. The head layers and embeddings still use 4-bit and 8-bit compression, bringing the total compressed model size to around 2.5 GB.</p><p>This extreme compression saves space and improves performance.</p><p>Since computation speed heavily depends on memory operations, reducing memory requirements directly translates to faster execution. Remarkably, our 2-bit compressed version of Llama 3.1 8B outperforms the uncompressed Llama 3.2 3B while occupying only half the space.</p><h3>The matrix mathematics behind language models</h3><p>At their core, large language models are collections of matrices. The primary computational workload involves matrix-vector multiplication, where compression methods focus their optimization efforts. These methods aim to create more compact matrix representations while minimizing quality loss.</p><p>In May 2024, the Yandex Research team, in collaboration with the Institute of Science and Technology Austria (ISTA) and King Abdullah University of Science and Technology (KAUST), published <a href="https://arxiv.org/abs/2405.14852">research</a> on the PV-Tuning algorithm. The algorithm improves compression methods for large language models without modifying the compressed weight format (I wrote about this in detail in my previous <a href="https://medium.com/yandex/the-evolution-of-extreme-llm-compression-from-quip-to-aqlm-with-pv-tuning-19c44b91af96">article</a>.)</p><p>Our project uses <a href="https://arxiv.org/abs/2401.06118">AQLM</a> as the base method, which is enhanced by PV-Tuning. AQLM employs additive vector quantization for compression. In 2-bit quantization, where each parameter occupies only 2 bits instead of the original model’s 16 bits — an 8x reduction — each matrix row is constructed from small groups of eight numbers.</p><p>Each such group is the sum of two vectors from 256-element dictionaries. This clever approach requires only 16 bits (2 × 8) to store indices for eight matrix elements, achieving our target of 2 bits per parameter.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*AOcVycqjrBlMPHVB" /></figure><h3>Implementing in WebAssembly and Rust</h3><p>WebAssembly has revolutionized browser-based programming, enabling development in virtually any language. After studying Rust at the <a href="https://dataschool.yandex.com/">Yandex School of Data Analysis</a>, I fell in love with the language and had been waiting for the perfect opportunity to use it. This project gave me that chance, so I implemented the entire inference system in Rust.</p><p>I was delighted to discover that many fundamental LLM infrastructure libraries are written in Rust. Take Hugging Face’s safetensors format — it was built entirely in Rust! Whenever someone uses a safetensors model from Hugging Face in their Python code, they use Rust. Similarly, OpenAI’s tiktoken tokenizer, which new Llama models use, is also Rust-based.</p><h3>Achieving multithreading in the browser</h3><p>To optimize performance, I implemented multithreading using web workers, enabling bidirectional thread communication through message passing. The solution uses a model-parallel approach: matrices are divided by output dimension, with each worker handling its designated portion.</p><p>The most challenging aspect was orchestrating the interaction between workers and the main thread. To address this, I developed a custom RPC stack for workers with Rust-JavaScript interoperability. Let me explain the process.</p><p>The process involves several steps when the main thread needs to multiply a vector by a matrix. First, the thread creates a request for each worker, serializes it, and sends it to the JavaScript runtime. From there, JavaScript forwards the request to the worker, where it is deserialized and processed, and the result is serialized.</p><p>Finally, the result returns through JavaScript to the main thread for deserialization. Through this carefully orchestrated process, we improved the performance by about 2x.</p><h3>Try it yourself</h3><p>Check out this demo video for a quick preview, and to experience it for yourself, visit the <a href="https://galqiwi.github.io/aqlm-rs/about.html">demo page</a>.</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fwww.youtube.com%2Fembed%2FfPOHT4Zf_NA%3Ffeature%3Doembed&amp;display_name=YouTube&amp;url=https%3A%2F%2Fwww.youtube.com%2Fwatch%3Fv%3DfPOHT4Zf_NA&amp;image=https%3A%2F%2Fi.ytimg.com%2Fvi%2FfPOHT4Zf_NA%2Fhqdefault.jpg&amp;type=text%2Fhtml&amp;schema=youtube" width="854" height="480" frameborder="0" scrolling="no"><a href="https://medium.com/media/529a45395ff2a8a39684e4048e460ffd/href">https://medium.com/media/529a45395ff2a8a39684e4048e460ffd/href</a></iframe><p>Note that the initial loading takes several minutes. For best results, use English — the model performs significantly better this way.</p><p>The project is open-source and available on <a href="https://github.com/galqiwi/demo-aqlm-rs">GitHub</a>. I’m happy to receive any feedback and suggestions on how to improve it further.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=a6dec439cdf3" width="1" height="1" alt=""><hr><p><a href="https://medium.com/yandex/try-llama-3-1-8b-in-your-browser-aqlm-rs-delivers-al-at-your-fingertips-a6dec439cdf3">Try Llama 3.1 8B in Your Browser: AQLM.rs Delivers Al at Your Fingertips</a> was originally published in <a href="https://medium.com/yandex">Yandex</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[The Evolution of Extreme LLM Compression: From QuIP to AQLM with PV-Tuning]]></title>
            <link>https://medium.com/yandex/the-evolution-of-extreme-llm-compression-from-quip-to-aqlm-with-pv-tuning-19c44b91af96?source=rss-924a86371b2b------2</link>
            <guid isPermaLink="false">https://medium.com/p/19c44b91af96</guid>
            <category><![CDATA[ai]]></category>
            <category><![CDATA[llm]]></category>
            <category><![CDATA[large-language-models]]></category>
            <category><![CDATA[mlops]]></category>
            <dc:creator><![CDATA[Vladimir Malinovskii]]></dc:creator>
            <pubDate>Mon, 05 Aug 2024 07:31:48 GMT</pubDate>
            <atom:updated>2024-08-05T07:31:48.104Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*Ls9T04Av4u0b-8Ai" /></figure><p>We live in the era of Large Language Models (LLMs), with companies increasingly deploying models with billions of parameters. These expansive models unlock new possibilities for users but come with high deployment costs and complexity, especially on personal computers. As a result, researchers and engineers often train these large models first and then compress them while trying to minimize quality loss.</p><p>Models are released in the float16 format, where 16 bits are allocated for each weight. Two years ago, technological advancement got us to the point where we can reliably compress neural networks down to 4 bits using techniques like <a href="https://arxiv.org/abs/2210.17323">GPTQ</a>. However, the progress doesn’t stop here, as the research community is now actively seeking methods to reduce model size eightfold, down to 2 bits.</p><p>A little while ago, the Yandex Research team joined efforts with their colleagues from IST Austria and KAUST to introduce a new method of achieving 8x compression using a method called AQLM + PV-Tuning. This method has been made publicly available to software developers and researchers, with the code published in a <a href="https://github.com/Vahe1994/AQLM">GitHub repository</a>. Popular <a href="https://huggingface.co/collections/ISTA-DASLab/aqlm-65e8dc75b908c7d73ec35598">open-source models</a> compressed with our proposed methods are also available for download. On top of that, we’ve published some <a href="https://colab.research.google.com/github/Vahe1994/AQLM/blob/main/notebooks/aqlm_2bit_training.ipynb">training materials</a> that explain how to fine-tune a compressed neural network to better suit your needs.</p><p>We want to shed some light on how the method was developed thanks to a brief (albeit very exciting!) “rivalry” between two research teams and their state-of-the-art compression algorithms: QuIP and AQLM. Competition fuels innovation, and this rapidly evolving story is a prime example. Every other month brings new breakthroughs, optimizations, and ingenious solutions. Sit back and enjoy!</p><h3>Methodology</h3><p>In our example, we’ll be using Llama2 13b. Along with it, Meta released two more models sized 7b and 70b. In academic research, perplexity is typically used to assess the quality of compressed models. This metric measures how perplexed (hence the name) a neural network gets after seeing a correctly written text. Lower perplexity means a better model.</p><p>For this article, we’ve chosen a different primary metric: effective model size. All three Llama2 models fall on the same line when plotting perplexity against model size, so we can report a more intuitive metric.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*lMCslC0sbFLrpM-q" /></figure><h3>Quantization of LLMs With Guarantees</h3><p>In mid-2023, a group of scientists from Cornell University published an article titled QuIP, where the authors seriously discussed for the first time the possibility of compressing neural networks by a factor of 8. The idea is that 99% of weights in large language models behave similarly and can be easily compressed with minimal loss. However, the remaining 1% — outliers — significantly deviate from the norm and lead to inaccuracies during compression.</p><p>The QuIP authors devised a technique to shuffle these weights, effectively solving the outlier problem. The algorithm compresses Llama2 13b to a perplexity of 13.5. At first glance, this may seem like a poor result, as it corresponds to a model with a mere size of 0.43M parameters. But this was the first time the perplexity remained in the double digits after compression. For reference, GPTQ compresses the same model to a perplexity of 123. So, what QuIP managed to achieve was nothing short of a breakthrough.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*LGTqs6hBuNxxF8nb" /></figure><h3>Extreme Compression of LLMs via Additive Quantization</h3><p>Six months later, in January 2024, researchers from Yandex and the Institute of Science and Technology Austria (ISTA) published a <a href="https://arxiv.org/abs/2401.06118v2">paper</a> on additive quantization for language models (AQLM). The method relies on additive quantization proposed in 2014 by Artem Babenko, Head of Yandex Research — back then, it was intended to help the company’s search engine needs. Ten years later, this technology was repurposed to compress large language models while maintaining maximum quality.</p><p>AQLM compresses Llama 13b to a perplexity corresponding to the 3.7b model. This was a significant improvement over QuIP — a model like that was now actually usable.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*bpV-ayNirTN9qqXA" /></figure><h3>A Close Competition — Upgrade From QuiP to QuIP#</h3><p>Just a month later, researchers from Cornell struck back with a <a href="https://arxiv.org/abs/2402.04396">new study</a> titled “QuIP#.” The authors refined their method with fine-tuning and other optimizations, showing that you can fine-tune a compressed neural network on a calibrated dataset to significantly reduce compression error without changing the model’s representation format.</p><p>QuIP# performed better than AQLM, improving the SOTA quantization of the Llama2–13b model to an effective size of 5.3B parameters.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*j9kfd9XnpSymcWF1" /></figure><h3>A New Chapter for AQLM</h3><p>In late May, a joint study from the creators of AQLM and researchers from King Abdullah University of Science and Technology (KAUST) sees light. The authors <a href="https://arxiv.org/abs/2405.14852">propose</a> an advanced fine-tuning algorithm — PV-Tuning — to improve on the old AQLM. While the QuIP# paper suggests fine-tuning only continuous parameters with gradients, PV-Tuning modifies all model parameters, including discrete ones.</p><p>In terms of quality, this is the best algorithm for 2-bit quantization to date. It compresses the Llama 13b model to an effective size of 6.9B, falling just a bit short of the 7b model.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*DZaBbtwauqj2VCd3" /></figure><p>Every year, neural network quantization becomes more and more efficient: inference costs are going down exponentially, and large models with open weights can now be launched on regular hardware. A few years ago, one could only dream of launching a large model like Llama3 70b on an RTX 3090. In 2024, that’s already a reality.</p><p>Healthy competition among researchers is a catalyst for technological advancement, driving innovation and the development of creative approaches. How will the story unfold from here? Time will tell! And we have a feeling it won’t be long.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=19c44b91af96" width="1" height="1" alt=""><hr><p><a href="https://medium.com/yandex/the-evolution-of-extreme-llm-compression-from-quip-to-aqlm-with-pv-tuning-19c44b91af96">The Evolution of Extreme LLM Compression: From QuIP to AQLM with PV-Tuning</a> was originally published in <a href="https://medium.com/yandex">Yandex</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
    </channel>
</rss>