<?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 Richard Siomporas on Medium]]></title>
        <description><![CDATA[Stories by Richard Siomporas on Medium]]></description>
        <link>https://medium.com/@richard.siomporas?source=rss-eeef14598584------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/0*8i2Cu2t6DfCdwUhh.jpg</url>
            <title>Stories by Richard Siomporas on Medium</title>
            <link>https://medium.com/@richard.siomporas?source=rss-eeef14598584------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Tue, 01 Dec 2026 14:34:57 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@richard.siomporas/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[CringeBot — QLoRA fine tuning of a state-of-the-art LLM using AOL Instant Messenger chat logs from…]]></title>
            <link>https://medium.com/@richard.siomporas/cringebot-qlora-fine-tuning-of-a-state-of-the-art-llm-using-aol-instant-messenger-chat-logs-from-d0961f9faf6f?source=rss-eeef14598584------2</link>
            <guid isPermaLink="false">https://medium.com/p/d0961f9faf6f</guid>
            <category><![CDATA[qlora]]></category>
            <category><![CDATA[aol-instant-messenger]]></category>
            <category><![CDATA[large-language-models]]></category>
            <category><![CDATA[machine-learning]]></category>
            <category><![CDATA[llm]]></category>
            <dc:creator><![CDATA[Richard Siomporas]]></dc:creator>
            <pubDate>Mon, 29 Jan 2024 22:57:19 GMT</pubDate>
            <atom:updated>2024-01-30T00:33:09.175Z</atom:updated>
            <content:encoded><![CDATA[<h3>CringeBot — QLoRA fine tuning of a state-of-the-art LLM using AOL Instant Messenger chat logs from my early 20s (Part 1)</h3><h4>In this episode, we begin our quest to transform Mixtral 8x7B Instruct into my online persona from the early 2000s, and end up turning it into an ornery fiend and lobotomizing it in the process — read on to find out how.</h4><p><a href="https://arxiv.org/abs/2305.14314">QLoRA</a> is an intriguing solution because it significantly lowers the barriers to entry for fine tuning AI models, putting the ability to materially change a state-of-the-art model’s knowledge, capability and alignment into the hands of basically anyone with a modern Apple-silicon MacBook spec’ed with enough RAM — or someone like me who enjoys piecing together solutions from 3D printed parts and off-lease data center hardware purchased off of eBay, stuffed into my basement utility closet. Of course there are trade-offs, with QLoRA relying on essentially a lower resolution version of the model to generate adapter weights so it can run on commodity hardware, as well as longer training times because of the quantization overhead, but the end result is still remarkable.</p><p>My ultimate goal with this project is to learn as much as I can about modern machine learning techniques, workflows and tools by applying my admittedly limited previous knowledge to a fun hypothetical project I’ve had in my head ever since I first heard about GPT-2’s crazy hallucinations several years ago — imbue the essence of 23 year old me into a modern LLM, using AOL Instant Messenger (AIM from here on out) chat logs I discovered on a backup of an 80 GB Maxtor hard drive I had buried in a folder of my NAS.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/500/1*e6o0FKb9vit7wxI5Jf1KHg.gif" /><figcaption>Making a useful fine tune that retains the original performance of the underlying Mixtral 8x7B model is not one of the goals.</figcaption></figure><h3>The setup</h3><p>While there is an easy button for this — rent a GPU node from a CSP, run this all in a Jupyter notebook using something like SageMaker — I have more fun and learn more along the way if I personally own as much of a project as possible. I have a <a href="https://github.com/hotspoons/home-lab">home lab</a> that I have been using for the better part of 4 years to advance my skills beyond what I am exposed to at work. The latest iteration of my home lab from last fall was a decent foundation for what I am trying to accomplish here, as I already had worked out Nvidia hardware support in VMs using a batteries-included Kubernetes setup — all that was left was to add a second box to the cluster that could support multiple GPUs.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*hV0MvFWJAm1aEiSd.jpg" /><figcaption>A diagram of my home lab runtime stack — the pizza on the outside is Rocky 8, running on the machine described below; the Parisian crepe inside of the pizza is also Rocky 8, running on a KVM virtual machine. The corn husk inside of the crepe is Kubernetes running on the VM, while the flour tortilla layer represents the QLoRA fine tuning script below (image credit <a href="https://youtu.be/evUWersr7pc?si=iupa8De-oooIeYf4">SNL/Taco Town</a>)</figcaption></figure><p>Given my humble means I had budgeted at most $1000 for this endeavor, so I got busy on eBay, Amazon, and AliExpress purchasing mostly good and some bad stuff. Ultimately I settled on a Dell Precision T7910 workstation chassis and motherboard from 2017, as this supported four PCIe x16 slots — I populated this with 128GB of RAM and two 14 core Broadwell Xeon CPUs, then I hacked together a solution that would support four dual slot GPUs, despite the workstation chassis only having room for three dual slot GPUs — this involved a <a href="https://www.aliexpress.us/item/3256803887969134.html">double 90 degree GPU riser cable</a> and a <a href="https://www.amazon.com/dp/B0CGTYR5DD">vertical GPU mounting bracket</a>, along with a <a href="https://www.ebay.com/itm/325826062995">crypto-mining GPU power adapter</a> so I could add a second power supply for the fourth GPU and not exceed the power budget of the workstation’s power supply.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*8Zq0t2E4JcSQpHJh" /><figcaption>The “deep learning rig”, or how to hack together a 4 x Tesla P40 node using a ca. 2017 Dell graphics workstation for about $1000</figcaption></figure><p>I am using Tesla P40 GPUs since they have a fair bit of VRAM despite their vintage (24 GB, or 96 GB across all 4 cards); they fit the budget on the secondary market; and they are still well supported by most ML frameworks and applications. Since these will not be in a server chassis, I purchased <a href="https://www.amazon.com/dp/B07RP14KML">75 mm centrifugal blower fans</a> and <a href="https://www.thingiverse.com/thing:6459091">designed and 3D printed mounting brackets for the fans</a>. The biggest pitfalls I’ve run into with these GPUs is that the widely used flash attention 2 library doesn’t support CUDA compute capability below 7_0 and Pascal cards are generally 6_1; they lack tensor cores; and their F16 support is abysmal so there is a performance and VRAM penalty for some use cases. Despite these shortcomings I have been able to use this setup for just about any workload I have thrown at it over the past few weeks, which brings us back to the topic at hand.</p><h3>The data</h3><p>When I mentioned this project to friends of mine, their reaction was generally “wait — how do you still have your AIM chat logs from 21 years ago!?” Yes, I am a data hoarder. I have had a RAID-1 going constantly since 1999 and I have all of the files I ever cared to copy off to that RAID going back even further. The drives have been replaced every 3 or 4 years, usually after one of them fails or there is a big jump in storage tech. The file system has gone from FAT32 to NTFS to ext3 to ReiserFS, and finally ending up on ext4; and the storage has gone from something like 20 GB to 8 TB, mirrored.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ZcwXp7YIAVRJsf91ajI5ww.png" /><figcaption>This week on Hoarders — my collection of old hard drives</figcaption></figure><p>I unearthed AIM chat logs while spelunking for uncompressed .wav files of a recording session of my band from around the same period. <strong>I was not prepared for the cringe</strong>, reading back my conversations as a 20 to 24 year old man child.</p><p>I partied too much, I smoked Newports and Marlboro menthols, I cursed like a sailor, I was into Japanese import tuning but I had an 80s front engine Porsche, I played in a punk rock band, I was often depressed or melancholy, and I was almost always hung over if I wasn’t already partying. I was on a seven year plan for undergrad and I had very generous and patient parents who supported me. I was going to a bar or a party almost every night. I pretended to be an asshole to women I was interested in because I was too insecure to just be myself. I kissed and told, and I was sometimes vulgar. I was naive, and I was strung along along by girls I fancied because they enjoyed the attention I paid to them. I spoke with friends and girlfriends about the most intimate things in my life, and some of them spoke to me about self harm, addiction, and worse. So in my estimation, this corpus was not unlike many other AIM logs from people of the same age in the same era. But it was mine, and it was <strong>so, so cringe </strong>when it was my voice.</p><p>Turning these chat logs into something suitable for training an AI model in a conversational manner is easy enough. For those who don’t remember or weren’t born yet, AIM chat logs were saved to disk in Clinton-era HTML format, and could even embed media shared over a direct connection! I generalized this so if anyone else wants to follow along with my experiment, it should be pretty straight forward. First, install some dependencies (presuming Python 3 running on something unix like):</p><pre>pip install HTML2Text pandas datasets</pre><p>This is the script (also available <a href="https://github.com/hotspoons/cringe-bot/blob/main/aim_log_scraper.py">here</a>).</p><pre>import os<br>import re<br>import sys<br>import json<br>from html2text import HTML2Text<br><br>html_converter = HTML2Text()<br>html_converter.unicode_snob = 1<br>html_converter.ignore_emphasis = 1<br>html_converter.ignore_images = 1<br>html_converter.ignore_links = 1<br>html_converter.body_width = 0<br><br>USER=&#39;user&#39;<br>ASSISTANT=&#39;assistant&#39;<br><br>def convert_htmls(path, screennames):<br>    output = &quot;&quot;<br>    for root, dirs, files in os.walk(path):<br>        for file in files:<br>            if file.endswith(&quot;.htm&quot;) or file.endswith(&quot;.html&quot;):<br>                with open(os.path.join(root, file), &quot;r&quot;) as f:<br>                    output += filter(html_converter.handle(f.read()), screennames)<br>    return output<br><br>def to_convo_format(input):<br>    turns = 0<br>    id = 0<br>    last_role = &quot;&quot;<br>    list_of_convos = []<br>    convo_struct = {<br>        &#39;user&#39;: &#39;&#39;,<br>        &#39;assistant&#39;: &#39;&#39;,<br>        &#39;id&#39;: str(id)<br>    }<br>    list_of_convos.append(convo_struct)<br>    for line in input.split(&quot;\n&quot;):<br>        if line.startswith(&#39;assistant :&#39;):<br>            role = ASSISTANT<br>        elif line.startswith(&#39;user :&#39;):<br>            role = USER<br>        else:<br>            role = USER if last_role == &quot;&quot; else last_role<br>            <br>        if last_role == &quot;&quot;: #init<br>            last_role = role<br>        if turns == 1 and last_role != role:<br>            id += 1<br>            convo_struct = {<br>                &#39;user&#39;: &#39;&#39;,<br>                &#39;assistant&#39;: &#39;&#39;,<br>                &#39;id&#39;: str(id)<br>            }<br>            list_of_convos.append(convo_struct)<br>            turns = 0<br>        elif last_role != role:<br>            turns += 1<br>        if convo_struct[role] != &#39;&#39;:<br>            convo_struct[role] += &#39;\n&#39;<br>        convo_struct[role] += line.replace(f&quot;{role} :&quot;, &#39;&#39;).strip()<br>        last_role = role<br>    return list_of_convos<br><br>def filter(text, screennames):<br>    lines = text.splitlines()<br>    screennames = screennames.split(&quot;,&quot;)<br>    filtered = []<br>    for line in lines:<br>        if &quot;is idle at &quot; in line or &quot;is no longer idle at &quot; in line or \<br>            &quot; returned at &quot; in line or &quot;is away at &quot; in line or \<br>            &quot;Session concluded at &quot; in line or \<br>            &quot;Auto response from &quot; in line or &quot;* * *&quot; in line or \<br>            &quot;wants to directly connect &quot; in line or \<br>            &quot;is now directly connected &quot; in line or \<br>            &quot;Your screen name &quot; in line or \<br>            &quot;direct connection is closed &quot; in line or \<br>            &quot; signed off at &quot; in line or \<br>            &quot; signed on at &quot; in line :<br>            continue<br>        line = re.sub(r&#39;\((\d{1,2}:\d{2}:\d{2}\s*(AM|PM))\)&#39;, &#39;&#39;, line)<br>        for screenname in screennames:<br>            line = line.replace(f&quot;{screenname} :&quot;, &quot;assistant___&quot;)<br>        line = re.sub(r&quot;^([^:]*):&quot;, &#39;user :&#39;, line, 0, re.MULTILINE)<br>        line = line.replace(&quot;assistant___&quot;, &quot;assistant :&quot;)<br>        if line.isspace() == True or line == &quot;&quot;:<br>            continue<br>        filtered.append(line)<br>    return &quot;\n&quot;.join(filtered)<br></pre><p>And the output is a list of dictionaries, where each dictionary is a single exchange in a conversation between a user and an assistant (actual exchange pictured):</p><pre>[<br>  {<br>    &quot;user&quot;: &quot;nice&quot;, <br>    &quot;assistant&quot; : &quot;So it launches myspace and looks like the aha video when you have your mouse over it...only took me 10 hours!\nThanks for checking it out for me...appears to work as planned&quot;,<br>    &quot;id&quot;: 998<br>  }<br>]</pre><p>This produced about 1,000 distinct exchanges from my chat logs. To use this in training, it is pretty straight forward to convert this to a Dataset:</p><pre>import pandas<br>from datasets import Dataset<br><br>output = convert_htmls(&#39;/path/to/aim-chats&#39;, &#39;MyScreename,MyOtherScreename&#39;)<br>convos = to_convo_format(output)<br>Dataset.from_pandas(pandas.DataFrame(data=convos)<br># And now we can split our dataset into training and eval, and use it</pre><p>So now that we are able to format our source data into something useful, let’s fine tune a model with it.</p><h3>The failures</h3><p>There is no success without failure, and failure is the best teacher, so let’s go over all of the fails!</p><h4>First attempt</h4><p>This was not as bad as I was expecting — I usually fail worse on my first attempt at something, but let’s just say I totally lobotomized the underlying Mixtral 8x7B Instruct model which is by most benchmarks superior to GPT 3.5.</p><p>I followed along with a <a href="https://www.youtube.com/watch?v=zbKz4g100SQ">YouTube video</a> on QLoRA fine tuning of Mixtral 8x7B that serendipitously appeared in my Google news feed the day I was planning on starting this experiment; I probably should have done more research and learned more about the fundamentals of fine tuning a LLM, but I was all about having fun so I picked the first random thing that magically appeared on my news feed that was close to what I was trying to accomplish and I just sent it.</p><p>For the most part, I extracted a python script from the Jupyter notebook <a href="https://github.com/brevdev/notebooks/blob/main/mistral-finetune.ipynb">in their GitHub</a> and I was able to get it running with only <a href="https://github.com/hotspoons/cringe-bot/blob/1804b1d9cd404db44d4bed6d8bf63e9b5c77a018/fine_tune_mixtral.py">minor modifications</a>, and of course rewriting the training and evaluation prompts using an instruct format. It took about 13 hours to run 650 steps, which was more than necessary as things leveled off around 450 steps, then evaluation loss started climbing at the next checkpoint.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*LZ6kEC15Hzj0m-zwteW4_g.png" /><figcaption>Obligatory Weights and Biases screenshot</figcaption></figure><p>To test the model, I loaded the model quantized and applied a few different checkpoints of the LoRA adapter over top of it <a href="https://github.com/hotspoons/cringe-bot/blob/1804b1d9cd404db44d4bed6d8bf63e9b5c77a018/mixtral_inference.py">using PyTorch</a>, then I crafted a couple of period-correct prompts and ran inference, with the same prompt template used for training.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*8-1TAygFWd_RHYv0VAYo0w.png" /><figcaption>Uh oh, something ain’t right. Let’s mark checkpoint 600 as a fail</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*n-rH1yBFeJF_DOYeWZUoTA.png" /><figcaption>Better. This tracks with the training data, but mine was a 1986, plus I think they had semi-trailing arms in the rear, not control arms. Checkpoint 450 is a win</figcaption></figure><p>Once I picked a good checkpoint, I opted to <a href="https://github.com/hotspoons/cringe-bot/blob/1804b1d9cd404db44d4bed6d8bf63e9b5c77a018/embed_lora.sh">merge the LoRA weights back into the original model</a>, then <a href="https://github.com/hotspoons/cringe-bot/blob/1804b1d9cd404db44d4bed6d8bf63e9b5c77a018/convert_safetensor_to_gguf_and_q6.sh">convert the merged model to a GGUF file and make a 6 bit quantized version</a> that was capable of running on my GPU node using <a href="https://github.com/mudler/LocalAI">LocalAI</a>, which I already had deployed to my Kubernetes cluster.</p><p>To evaluate the final result, I loaded the merged model with llama.cpp and fed it a prompt from the command line then let it hallucinate. This is what came out of the other end (please excuse the crude language and subject matter, definitely NSFW):</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*957uGSUJo1CpkMP9bOopkg.png" /><figcaption>This certainly tracks with the training data, but these events never occurred. “Don’t die! Peace out.”</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/625/0*Ucjae96bQdLU8tyO.jpg" /></figure><h4>Second attempt</h4><p>After a promising first attempt, I wanted to try to improve the conversational performance of the fused model, since it appears that I wiped that out of Mixtral’s memory. I Googled and Googled and I think I figured out what was wrong — I had extra &lt;s&gt; and &lt;/s&gt; tokens in the template. And maybe the [INST][/INST] tags weren’t quite right, but I’ll deal with that later. I decided to try to clean up the extra start/stop sequence tokens, and while I was at it double the maximum length for training samples. And swap sides for padding. And make 3 or 4 other small tweaks to hyper-parameters and training settings that I wasn’t quite sure what they did but they didn’t look right. And then this is what came out, I think around step 600:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Csh3rUm6ee3i0UdN88oI5Q.png" /><figcaption>Well that ain’t right</figcaption></figure><p>Not sure what else to do, I tried messing with the LoRA configuration, and I lowered the alpha from the default of 16 to 8, fused the model, and ran it again — and it was indiscernible from Mixtral 8x7B, so maybe that was too drastic of a change.</p><p>I changed the alpha again, but this time to 14, fused it, ran it, and…</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*I4xqfSGitLmFRHQ-.jpg" /><figcaption>I’m sorry, I just can’t share what came out. When prompted with something fairly innocuous it became unhinged, disgusting, hypersexualized, and totally disrespectful — like how I imagine Andy Dick’s AIM chats were from this period</figcaption></figure><p>I created a monster, but I also changed like 10 things between training runs — not a good idea. Then I ran into my next problem…</p><h4>Hardware failure</h4><p>I began having problems with my rig after we had a power surge, and now the machine reboots when the GPUs are under heavy load, usually while performing an eval step, right before saving off a checkpoint.</p><p>After lots of experimentation, it appears that lowering the peak clock speed for the GPUs from 1531MHz to 1442MHz was enough to make what ever component was overdrawing current happy. I have a new power supply on order since this is what I suspect was damaged during the surge. This troubleshooting put me back a few days, but now I am able to continue.</p><p>And this is where we leave it, until next time.</p><ul><li><a href="https://www.github.com/hotspoons/cringe-bot">GitHub Repository</a></li><li>Part 2 of this series (coming soon)</li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=d0961f9faf6f" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>