<?xml version="1.0" encoding="utf-8" standalone="yes"?><rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom"><channel><title>RLHF | Hailin Liu</title><link>https://hailin.ai/tags/rlhf/</link><atom:link href="https://hailin.ai/tags/rlhf/index.xml" rel="self" type="application/rss+xml"/><description>RLHF</description><generator>HugoBlox Kit (https://hugoblox.com)</generator><language>en-us</language><lastBuildDate>Wed, 09 Apr 2025 00:00:00 +0000</lastBuildDate><image><url>https://hailin.ai/media/icon_hu_76af94951e63d377.png</url><title>RLHF</title><link>https://hailin.ai/tags/rlhf/</link></image><item><title>SmallLM-Forge: A Small-Scale Language Model Training and Alignment Stack</title><link>https://hailin.ai/projects/slm-forge/</link><pubDate>Wed, 09 Apr 2025 00:00:00 +0000</pubDate><guid>https://hailin.ai/projects/slm-forge/</guid><description>&lt;h2 id="what-is-smalllm-forge"&gt;What Is SmallLM-Forge?&lt;/h2&gt;
&lt;p&gt;SmallLM-Forge is a small-scale language-model stack for studying how the main
components of modern language models are built and connected. It covers
tokenization, decoder-only Transformer pretraining, autoregressive generation,
parameter-efficient adaptation, supervised fine-tuning, and preference
alignment in implementations that remain small enough to inspect and modify
directly.&lt;/p&gt;
&lt;p&gt;The project focuses on the ideas behind these components and how they become
working code: how byte-level BPE constructs a vocabulary, how RoPE and
grouped-query attention fit into a decoder-only Transformer, how low-rank
adapters modify selected layers while the base model stays frozen, how
supervised fine-tuning restricts the loss to response tokens, and how Direct
Preference Optimization turns pairwise preferences into a training objective.&lt;/p&gt;
&lt;p&gt;Small experiments are used throughout the repository to exercise these ideas
in practice. They serve as examples of how the components can be assembled,
while the main focus remains on the underlying mechanisms and their
implementation.&lt;/p&gt;
&lt;h2 id="from-tokens-to-alignment"&gt;From Tokens to Alignment&lt;/h2&gt;
&lt;p&gt;SmallLM-Forge follows three stages of language-model development:&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Build&lt;/strong&gt; — start from raw text, train a tokenizer, construct a decoder-only
Transformer, and pretrain it with next-token prediction.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Adapt&lt;/strong&gt; — keep an existing model as the starting point and modify its behavior
efficiently with LoRA or DoRA and supervised fine-tuning.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Align&lt;/strong&gt; — move from supervised targets to pairwise preferences and optimize
the model with Direct Preference Optimization.&lt;/p&gt;
&lt;p&gt;The three parts below follow the same progression: &lt;strong&gt;build, adapt, and align&lt;/strong&gt;.&lt;/p&gt;
&lt;h2 id="explore-the-stack"&gt;Explore the Stack&lt;/h2&gt;
&lt;div class="hb-cards mt-4 grid gap-4 not-prose" style="--hb-cols: 1;"&gt;
&lt;a
class="hb-card group"href="parts/pretraining" &gt;
&lt;span class="hb-card-title pt-4 px-4"&gt;
&lt;svg style="height: 1em; width: 1em;" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"&gt;&lt;path fill="none" stroke="currentColor" stroke-linecap="round" stroke-linejoin="round" stroke-width="1.5" d="M19.5 14.25v-2.625a3.375 3.375 0 0 0-3.375-3.375h-1.5A1.125 1.125 0 0 1 13.5 7.125v-1.5a3.375 3.375 0 0 0-3.375-3.375H8.25m0 12.75h7.5m-7.5 3H12M10.5 2.25H5.625c-.621 0-1.125.504-1.125 1.125v17.25c0 .621.504 1.125 1.125 1.125h12.75c.621 0 1.125-.504 1.125-1.125V11.25a9 9 0 0 0-9-9"/&gt;&lt;/svg&gt;Part 1 — Build a Small Language Model&lt;/span&gt;&lt;div class="hb-card-subtitle"&gt;From byte-level BPE to a decoder-only Transformer, causal language modeling, and autoregressive generation.&lt;/div&gt;&lt;/a&gt;
&lt;a
class="hb-card group"href="parts/peft-sft" &gt;
&lt;span class="hb-card-title pt-4 px-4"&gt;
&lt;svg style="height: 1em; width: 1em;" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"&gt;&lt;path fill="none" stroke="currentColor" stroke-linecap="round" stroke-linejoin="round" stroke-width="1.5" d="M19.5 14.25v-2.625a3.375 3.375 0 0 0-3.375-3.375h-1.5A1.125 1.125 0 0 1 13.5 7.125v-1.5a3.375 3.375 0 0 0-3.375-3.375H8.25m0 12.75h7.5m-7.5 3H12M10.5 2.25H5.625c-.621 0-1.125.504-1.125 1.125v17.25c0 .621.504 1.125 1.125 1.125h12.75c.621 0 1.125-.504 1.125-1.125V11.25a9 9 0 0 0-9-9"/&gt;&lt;/svg&gt;Part 2 — Adapt a Language Model with LoRA and SFT&lt;/span&gt;&lt;div class="hb-card-subtitle"&gt;Implement LoRA and DoRA, inject lightweight adapters, freeze the base model, and train on supervised responses.&lt;/div&gt;&lt;/a&gt;
&lt;a
class="hb-card group"href="parts/dpo" &gt;
&lt;span class="hb-card-title pt-4 px-4"&gt;
&lt;svg style="height: 1em; width: 1em;" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"&gt;&lt;path fill="none" stroke="currentColor" stroke-linecap="round" stroke-linejoin="round" stroke-width="1.5" d="M19.5 14.25v-2.625a3.375 3.375 0 0 0-3.375-3.375h-1.5A1.125 1.125 0 0 1 13.5 7.125v-1.5a3.375 3.375 0 0 0-3.375-3.375H8.25m0 12.75h7.5m-7.5 3H12M10.5 2.25H5.625c-.621 0-1.125.504-1.125 1.125v17.25c0 .621.504 1.125 1.125 1.125h12.75c.621 0 1.125-.504 1.125-1.125V11.25a9 9 0 0 0-9-9"/&gt;&lt;/svg&gt;Part 3 — Align a Language Model with DPO&lt;/span&gt;&lt;div class="hb-card-subtitle"&gt;Build the DPO objective from policy and reference log-probabilities and train from chosen and rejected responses.&lt;/div&gt;&lt;/a&gt;
&lt;/div&gt;
&lt;h2 id="why-build-it-at-small-scale"&gt;Why Build It at Small Scale?&lt;/h2&gt;
&lt;p&gt;Modern language-model libraries provide powerful high-level interfaces, but
those abstractions can make the mechanics underneath a training run difficult
to follow. SmallLM-Forge keeps the models, objectives, and training loops
compact enough that the path from an idea or equation to the corresponding
tensor operations can be inspected directly.&lt;/p&gt;
&lt;p&gt;This makes the stack useful for experimenting with individual design choices.
Tokenization, attention, feed-forward layers, generation, low-rank adaptation,
supervised fine-tuning, and preference optimization remain separate components
with clear responsibilities. Each one can be studied, modified, and tested
without requiring a production-scale training system.&lt;/p&gt;
&lt;p&gt;The small scale also keeps complete experiments practical. The goal is to make
language-model architecture and training behavior concrete through executable
implementations, while preserving enough structure to connect those
implementations to the techniques used in larger systems.&lt;/p&gt;
&lt;h2 id="models-artifacts-and-resources"&gt;Models, Artifacts, and Resources&lt;/h2&gt;
&lt;p&gt;The repository includes example workflows that exercise the components
described in the three parts. The pretraining workflow has also produced two
public Hugging Face artifacts:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;Byte-level BPE tokenizer:&lt;/strong&gt; &lt;code&gt;liuhailin0123/wiki103-bpe-tokenizer&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Pretrained mini model:&lt;/strong&gt; &lt;code&gt;liuhailin0123/wiki103-llama-mini&lt;/code&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;The source code, playground notebooks, tests, and implementation details are
available in the SmallLM-Forge repository.&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;Source code:&lt;/strong&gt;
&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Tokenizer:&lt;/strong&gt;
&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Model:&lt;/strong&gt;
&lt;/li&gt;
&lt;/ul&gt;</description></item></channel></rss>