mirror of
https://github.com/hanzoai/papers.git
synced 2026-10-29 07:34:31 +00:00
zenlm/papers had a sweeping withdrawal pass, 5deeeaa, and the owner reverted it in f34f609 for asserting more than it verified. That objection sets the rule here: a claim changes only where the proof is in the paper itself or in arithmetic, never because a run could not be found. Twenty-seven of the eighty-one zen papers meet that bar. Every correction quotes a number the paper already carries or one derived from its own numbers by a division a reader can repeat. Twelve papers led with a figure that appears in no row of the table it summarises. zen-agent averaged GAIA 83.1/68.4/42.3 to 71.2 while its four baseline rows are each the plain mean of their own three levels; the mean is 64.6. zen-embeddings-retrieval and zen3-embedding claim MTEB averages of 72.4 and 74.3 over tables that supply their task counts, where the 56-task weighted means are 67.1 and 67.4. zen-mathematical-reasoning opened with five figures, none of them any row, and explained one as best-of-32 sampling when its own sampling table puts best-of-32 at a different number. zen-dso-protocol claimed 94% of centralized quality and a 78% bandwidth cut against tables reading 99.4% and 99.8%-and-better, the second of them the table that claim captions. zen-synthetic-data claimed an 8.4-point MT-Bench gain on a scale that runs to 10, from a 7.84 baseline, where its table says 0.88. zen-3d quoted the Chair column as the ShapeNet result. zen-multilingual understated its own XNLI average. Also zen-hallucination-reduction, zen-distributed-training, zen-finetuning, zen-legal-ai and zen-coder-flash. Eight more are settled by arithmetic against the hardware or the parameter count. zen-nano, zen-eco and zen-scribe each report INT4 needing as much memory as FP16 or more, while their own FP16 and INT8 rows are exactly two and one bytes per parameter; zen_family_overview already carried the right values. The two zen-designer papers size a stated 235B model at 220 GB in FP16, which is a 110B model, and zen-quantization puts the same model at 470 GB. zen-omni and zen-next recommend cards smaller than the memory the same row requires. zen-live captions a latency table to an A10G when its own deployment table assigns that 98 ms to the H100. zen-hardware-optimization calls a throughput table FP8+INT4 when its cumulative table reaches the identical 31,200 tok/s through INT4 + FP16. Six papers share one template whose visual benchmark block bundles two metrics computed over images a model generates with one computed over text a model emits about an image. No model produces all three, and the block went to four papers across four modalities, so each received at least one metric it cannot compute: VQA v2 and a token rate for two diffusion models, FID and CLIP score for two vision-language models. Each now keeps the rows its own stated output type can produce. Throughput is the one category where the defect is the missing condition rather than the number. Decode reads the active weight set once per token, so a single stream cannot outrun bandwidth over footprint, and zen4-mini, zen3-nano and zen-coder-flash all report above their own bound. Batched serving would make those figures legal and none of the three records a batch size, so the numbers stand and each table now carries its bound and the arithmetic behind it. AIME gets the same treatment in zen-mathematical-reasoning: a score that is not a multiple of 1/30 on a 30-problem exam is legal under averaging, and the caption now says which row has its sample count on record and which do not. What was examined and left is in LLM.md with the reason in each case. Training fleets absent from this estate prove nothing about models trained on rented capacity. zen-reranker's 98% semantic preservation is uncited rather than contradicted. zen-safety-evaluation and zen-vision-architecture state no weighting, so their averages are not determined. zen4-coder-flash puts FP8 on an A100, and Ampere has no FP8 tensor cores, but its claims there are footprint claims and FP8 weight-only storage does run on Ampere. All twenty-seven rebuild under latexmk -Werror. Nineteen have diverged from their counterparts in zenlm/papers and six exist only here, so those fixes do not reach the other site. zen-3d and zen-agent were byte-identical across the two repositories until now, and are the two to mirror first. Co-authored-by: Hanzo Dev <[email protected]>
346 lines
14 KiB
TeX
346 lines
14 KiB
TeX
\documentclass[11pt,a4paper]{article}
|
|
\usepackage[utf8]{inputenc}
|
|
\usepackage[T1]{fontenc}
|
|
\usepackage{amsmath,amsfonts,amssymb}
|
|
\usepackage{graphicx}
|
|
\usepackage{hyperref}
|
|
\usepackage{listings}
|
|
\usepackage{color}
|
|
\usepackage{booktabs}
|
|
\usepackage{float}
|
|
\usepackage{algorithm}
|
|
\usepackage{algorithmic}
|
|
\usepackage{geometry}
|
|
\geometry{margin=1in}
|
|
\definecolor{zenblue}{RGB}{41,121,255}
|
|
\hypersetup{colorlinks=true,linkcolor=zenblue,urlcolor=zenblue,citecolor=zenblue}
|
|
|
|
\title{\textbf{Fine-Tuning Zen Models: Methods and Best Practices}\\
|
|
\large Technical Report v2025.04}
|
|
\author{Hanzo AI Research, Zen LM Research Team\\
|
|
\texttt{[email protected]}}
|
|
\date{April 2025}
|
|
|
|
\begin{document}
|
|
\maketitle
|
|
|
|
\begin{abstract}
|
|
We present a systematic study of fine-tuning methods for Zen models, covering
|
|
LoRA and QLoRA parameter-efficient methods, full fine-tuning, domain adaptation,
|
|
and catastrophic forgetting prevention. Key findings: (1) LoRA with rank 64 achieves
|
|
98.3\% of full fine-tuning performance at 0.8\% of the trainable parameters; (2)
|
|
optimal learning rates follow a power law in dataset size; (3) data requirements
|
|
vary dramatically by task type (classification: 1K samples, complex generation: 50K+);
|
|
(4) Elastic Weight Consolidation (EWC) prevents 80\% of catastrophic forgetting
|
|
at 15\% compute overhead; (5) QLoRA enables Zen-32B fine-tuning on a single A100
|
|
80GB GPU. We provide concrete recipes for practitioners adapting Zen to new domains.
|
|
\end{abstract}
|
|
|
|
\section{Introduction}
|
|
|
|
Fine-tuning pre-trained language models to new domains and tasks is a fundamental
|
|
capability requirement. Zen models are designed to be efficiently fine-tunable:
|
|
the MoDE architecture's expert routing provides natural structure for domain adaptation,
|
|
and the modular design facilitates targeted weight updates.
|
|
|
|
Practitioners face several questions: Should I use LoRA or full fine-tuning?
|
|
How much data do I need? What learning rate? How do I prevent forgetting my
|
|
base model's capabilities? This paper provides empirical answers to these questions
|
|
across a range of tasks and model sizes.
|
|
|
|
\section{Parameter-Efficient Fine-Tuning}
|
|
|
|
\subsection{LoRA: Low-Rank Adaptation}
|
|
|
|
LoRA~\cite{hu2021lora} constrains weight updates to a low-rank subspace:
|
|
\begin{equation}
|
|
W = W_0 + \Delta W = W_0 + B \cdot A, \quad B \in \mathbb{R}^{m \times r}, A \in \mathbb{R}^{r \times n}
|
|
\end{equation}
|
|
|
|
where $r \ll \min(m, n)$ is the rank. Only $A$ and $B$ are trained; $W_0$ is frozen.
|
|
For Zen-7B, applying LoRA to all attention weight matrices (Q, K, V, O) and FFN
|
|
matrices at rank $r=64$ yields $\sim$55M trainable parameters (0.8\% of 7B total).
|
|
|
|
\subsubsection{LoRA Initialization}
|
|
|
|
$A$ is initialized with random Gaussian; $B$ is initialized to zero, so $\Delta W = 0$
|
|
at training start. A scaling factor $\alpha/r$ controls the effective learning rate
|
|
of the adapter relative to the frozen weights.
|
|
|
|
\subsubsection{Which Modules to Apply LoRA To}
|
|
|
|
\begin{table}[H]
|
|
\centering
|
|
\begin{tabular}{lcc}
|
|
\toprule
|
|
\textbf{LoRA Modules} & \textbf{Trainable Params} & \textbf{MMLU Domain} \\
|
|
\midrule
|
|
Q, V only & 28M (0.4\%) & 82.1 \\
|
|
Q, K, V, O & 55M (0.8\%) & 84.3 \\
|
|
Q, K, V, O + FFN & 140M (2.0\%) & 85.1 \\
|
|
All linear layers & 210M (3.0\%) & 85.4 \\
|
|
Full fine-tuning & 7000M (100\%) & 85.8 \\
|
|
\bottomrule
|
|
\end{tabular}
|
|
\caption{LoRA module selection vs. performance (Zen-7B, domain-specific MMLU subset).}
|
|
\end{table}
|
|
|
|
Applying LoRA to all attention layers plus FFN captures 98.7\% of full fine-tuning
|
|
performance at 2\% of parameters. The diminishing returns suggest that attention
|
|
layers are the primary site of task adaptation.
|
|
|
|
\subsection{QLoRA: Quantized LoRA}
|
|
|
|
QLoRA~\cite{dettmers2023qlora} combines NF4 quantization of the frozen base model
|
|
with LoRA adapters in full precision:
|
|
|
|
\begin{equation}
|
|
W_0^\text{quant} = \text{NF4}(W_0), \quad \text{forward: } (W_0^\text{quant} + \Delta W) \cdot x
|
|
\end{equation}
|
|
|
|
The quantization error in $W_0^\text{quant}$ is partially compensated by $\Delta W$
|
|
during training. Double quantization further compresses quantization constants from
|
|
FP32 to FP8.
|
|
|
|
\begin{table}[H]
|
|
\centering
|
|
\begin{tabular}{lrrrc}
|
|
\toprule
|
|
\textbf{Method} & \textbf{VRAM (7B)} & \textbf{VRAM (32B)} & \textbf{Perf. Gap vs. Full FT} & \textbf{Speed} \\
|
|
\midrule
|
|
Full fine-tuning & 112 GB & 512 GB & 0\% & 1.0$\times$ \\
|
|
LoRA (rank 64) & 16 GB & 72 GB & 0.5\% & 1.2$\times$ \\
|
|
QLoRA NF4 (rank 64) & 6 GB & 24 GB & 1.2\% & 0.8$\times$ \\
|
|
QLoRA NF4 + DQ & 5 GB & 20 GB & 1.4\% & 0.75$\times$ \\
|
|
\bottomrule
|
|
\end{tabular}
|
|
\caption{Memory requirements and performance impact of quantized fine-tuning. QLoRA enables Zen-32B on 1$\times$A100 80GB.}
|
|
\end{table}
|
|
|
|
\section{Full Fine-Tuning}
|
|
|
|
\subsection{When to Use Full Fine-Tuning}
|
|
|
|
Full fine-tuning is warranted when:
|
|
\begin{enumerate}
|
|
\item Task diverges significantly from base model distribution (new language, specialized domain)
|
|
\item Data volume is large ($>$500K samples)
|
|
\item Maximum task performance is required (competitive benchmark submission)
|
|
\item Compute budget permits (multi-node training available)
|
|
\end{enumerate}
|
|
|
|
\subsection{Learning Rate Schedule}
|
|
|
|
For full fine-tuning, learning rate must be significantly lower than pretraining:
|
|
|
|
\begin{table}[H]
|
|
\centering
|
|
\begin{tabular}{lrrrr}
|
|
\toprule
|
|
\textbf{Model} & \textbf{Pretrain LR} & \textbf{Full FT LR} & \textbf{LoRA LR} & \textbf{QLoRA LR} \\
|
|
\midrule
|
|
Zen-600M & $6\times10^{-4}$ & $2\times10^{-5}$ & $3\times10^{-4}$ & $3\times10^{-4}$ \\
|
|
Zen-7B & $3\times10^{-4}$ & $1\times10^{-5}$ & $2\times10^{-4}$ & $2\times10^{-4}$ \\
|
|
Zen-32B & $1\times10^{-4}$ & $5\times10^{-6}$ & $1\times10^{-4}$ & $1\times10^{-4}$ \\
|
|
\bottomrule
|
|
\end{tabular}
|
|
\caption{Recommended learning rates by model size and fine-tuning method.}
|
|
\end{table}
|
|
|
|
\section{Data Requirements by Task Type}
|
|
|
|
A key practical question is: how much data do I need? We run systematic experiments
|
|
varying dataset size across task types:
|
|
|
|
\begin{table}[H]
|
|
\centering
|
|
\begin{tabular}{lrrr}
|
|
\toprule
|
|
\textbf{Task Type} & \textbf{Minimum} & \textbf{Recommended} & \textbf{Saturation} \\
|
|
\midrule
|
|
Text classification & 500 & 2K & 20K \\
|
|
Named entity recognition & 1K & 5K & 50K \\
|
|
Summarization (short) & 2K & 10K & 100K \\
|
|
Summarization (long document) & 5K & 20K & 200K \\
|
|
Question answering (extractive) & 2K & 10K & 100K \\
|
|
Question answering (generative) & 5K & 20K & 200K \\
|
|
Instruction following (simple) & 1K & 5K & 50K \\
|
|
Instruction following (complex) & 10K & 50K & 500K \\
|
|
Code synthesis (function level) & 5K & 20K & 200K \\
|
|
Code synthesis (repository level) & 20K & 100K & 1M \\
|
|
Domain adaptation (general) & 50K & 200K & 2M \\
|
|
\bottomrule
|
|
\end{tabular}
|
|
\caption{Recommended dataset sizes by task type (for Zen-7B with LoRA rank 64).}
|
|
\end{table}
|
|
|
|
Saturation is defined as the point where doubling dataset size yields $<1\%$
|
|
improvement on the task metric. These numbers scale roughly as $N_\text{model}^{0.3}$
|
|
for larger models.
|
|
|
|
\section{Optimal Learning Rate Selection}
|
|
|
|
Learning rate interacts with dataset size. We find that optimal learning rate
|
|
follows:
|
|
|
|
\begin{equation}
|
|
\eta^* \approx \eta_0 \cdot \left(\frac{N_\text{data}}{N_0}\right)^{-0.22}
|
|
\end{equation}
|
|
|
|
where $\eta_0 = 2\times10^{-4}$ and $N_0 = 10000$ are reference values for Zen-7B
|
|
LoRA. Larger datasets tolerate higher learning rates; small datasets require
|
|
conservative learning rates to avoid overfitting.
|
|
|
|
\begin{figure}[H]
|
|
\centering
|
|
\begin{tabular}{lcccc}
|
|
\toprule
|
|
\textbf{Dataset Size} & \textbf{LR $10^{-5}$} & \textbf{LR $10^{-4}$} & \textbf{LR $3\times10^{-4}$} & \textbf{LR $10^{-3}$} \\
|
|
\midrule
|
|
500 samples & 78.1 & 79.4 & 78.2 & 72.1 \\
|
|
5K samples & 82.3 & 84.1 & 83.8 & 79.4 \\
|
|
50K samples & 84.1 & 85.9 & \textbf{86.2} & 83.1 \\
|
|
500K samples & 84.8 & 86.4 & 87.1 & \textbf{87.3} \\
|
|
\bottomrule
|
|
\end{tabular}
|
|
\caption{Task accuracy vs. learning rate at varying dataset sizes (Zen-7B LoRA, instruction following task).}
|
|
\end{figure}
|
|
|
|
\section{Catastrophic Forgetting Prevention}
|
|
|
|
\subsection{The Forgetting Problem}
|
|
|
|
Fine-tuning on a narrow task degrades performance on tasks not represented in
|
|
the fine-tuning data. For Zen-7B fine-tuned on a medical QA dataset (50K samples),
|
|
MMLU drops from 85.3 to 74.1 (11.2 points), while medical QA improves by 24.3 points.
|
|
|
|
\subsection{Elastic Weight Consolidation (EWC)}
|
|
|
|
EWC~\cite{kirkpatrick2017ewc} adds a regularization term that penalizes changes
|
|
to weights important for previous tasks:
|
|
|
|
\begin{equation}
|
|
\mathcal{L}_\text{EWC} = \mathcal{L}_\text{task} + \frac{\lambda}{2} \sum_i F_i (\theta_i - \theta_i^*)^2
|
|
\end{equation}
|
|
|
|
where $F_i$ is the diagonal Fisher information for parameter $i$ computed on the
|
|
original training distribution, $\theta_i^*$ are the base model weights, and
|
|
$\lambda$ controls the regularization strength.
|
|
|
|
\begin{table}[H]
|
|
\centering
|
|
\begin{tabular}{lcccc}
|
|
\toprule
|
|
\textbf{Method} & \textbf{Medical QA} & \textbf{General MMLU} & \textbf{MMLU Drop} & \textbf{Overhead} \\
|
|
\midrule
|
|
No regularization & 88.2\% & 74.1 & $-11.2$ & 0\% \\
|
|
L2 penalty ($\lambda=0.1$) & 87.1\% & 78.4 & $-6.9$ & 5\% \\
|
|
EWC ($\lambda=1000$) & 86.8\% & 83.2 & $-2.1$ & 15\% \\
|
|
Replay (10\% general data) & 85.1\% & 84.1 & $-1.2$ & 30\% \\
|
|
LoRA (no regularization) & 84.3\% & 84.9 & $-0.4$ & -- \\
|
|
\bottomrule
|
|
\end{tabular}
|
|
\caption{Catastrophic forgetting mitigation methods. LoRA alone nearly eliminates forgetting.}
|
|
\end{table}
|
|
|
|
LoRA's frozen base model provides strong natural resistance to forgetting:
|
|
since $W_0$ is never updated, general capabilities are fully preserved. Only
|
|
the adapter weights change, which have far fewer parameters and cannot overwrite
|
|
base knowledge. This makes LoRA the preferred method when forgetting prevention
|
|
is a priority.
|
|
|
|
\section{Domain Adaptation Recipes}
|
|
|
|
\subsection{Medical / Clinical}
|
|
|
|
\textbf{Data}: 200K+ clinical notes, medical literature, Q\&A pairs.
|
|
\textbf{Method}: LoRA rank 128, LR $10^{-4}$, 3 epochs, cosine LR schedule.
|
|
\textbf{Expected gains}: +15--25 points on MedQA, +20 on PubMedQA.
|
|
\textbf{Watch out for}: hallucination of specific drug dosages and drug interactions;
|
|
use constitutional training to inject factual humility.
|
|
|
|
\subsection{Legal}
|
|
|
|
\textbf{Data}: 500K+ legal filings, case law, contracts.
|
|
\textbf{Method}: Full fine-tuning (legal reasoning requires deep representation change),
|
|
LR $5\times10^{-6}$, 2 epochs with validation-based early stopping.
|
|
\textbf{Expected gains}: +20 points on LegalBench, +15 on contract extraction.
|
|
|
|
\subsection{Code (Domain-Specific Language)}
|
|
|
|
\textbf{Data}: 50K+ file pairs in the target language/framework.
|
|
\textbf{Method}: LoRA rank 64 applied to all layers, LR $2\times10^{-4}$,
|
|
5 epochs; evaluate on held-out repo test cases.
|
|
\textbf{Expected gains}: +10--20\% HumanEval in target language.
|
|
|
|
\subsection{Scientific Research}
|
|
|
|
\textbf{Data}: 100K+ papers in domain + 50K Q\&A pairs.
|
|
\textbf{Method}: Two-stage: first fine-tune on papers (language modeling loss),
|
|
then on Q\&A (SFT loss). LoRA rank 64.
|
|
\textbf{Expected gains}: +12 points on domain-specific question answering.
|
|
|
|
\section{Experiments: Comparison Across Methods}
|
|
|
|
\subsection{Benchmark: Legal Domain Adaptation}
|
|
|
|
\begin{table}[H]
|
|
\centering
|
|
\begin{tabular}{lcccc}
|
|
\toprule
|
|
\textbf{Method} & \textbf{LegalBench} & \textbf{General MMLU} & \textbf{Params Trained} & \textbf{GPU Hours} \\
|
|
\midrule
|
|
Zero-shot & 51.3\% & 85.3 & 0 & 0 \\
|
|
LoRA rank 16 & 67.4\% & 85.1 & 14M & 4h \\
|
|
LoRA rank 64 & 73.8\% & 85.0 & 55M & 8h \\
|
|
LoRA rank 128 & 75.1\% & 84.9 & 110M & 14h \\
|
|
Full fine-tuning & \textbf{78.2\%} & 77.8 & 7B & 120h \\
|
|
Full FT + EWC & 76.4\% & \textbf{83.4} & 7B & 138h \\
|
|
\bottomrule
|
|
\end{tabular}
|
|
\caption{Legal domain adaptation results (Zen-7B, 200K training samples).}
|
|
\end{table}
|
|
|
|
For most use cases, LoRA rank 64--128 offers the best tradeoff: 93--96\% of full
|
|
fine-tuning task performance, 100\% retention of general capabilities, at 4--10\%
|
|
of the compute cost.
|
|
|
|
\section{Practical Recommendations}
|
|
|
|
\begin{enumerate}
|
|
\item \textbf{Start with LoRA rank 64}: Cover all attention + FFN layers for
|
|
tasks with $>$10K samples. Use rank 16--32 for smaller datasets.
|
|
\item \textbf{Use QLoRA for large models}: Zen-32B is practical on 1$\times$A100
|
|
with QLoRA; quality gap is $<$1.5\% vs. full fine-tuning.
|
|
\item \textbf{LR: start at $2\times10^{-4}$ for LoRA}: Reduce to $10^{-4}$ for
|
|
$<$5K samples; increase to $3\times10^{-4}$ for $>$100K samples.
|
|
\item \textbf{Monitor forgetting}: Track a general benchmark (MMLU subset)
|
|
alongside task metric during fine-tuning. Forgetting should be $<$2 points
|
|
with LoRA; alert if $>$5 points.
|
|
\item \textbf{Data quality over quantity}: For $<$10K samples, quality filtering
|
|
is more impactful than quantity doubling. Remove outputs with hallucinations,
|
|
inconsistencies, or ambiguous labels.
|
|
\item \textbf{Epochs}: 3--5 epochs for small datasets; 1--2 for $>$100K samples.
|
|
Use early stopping on validation loss.
|
|
\end{enumerate}
|
|
|
|
\section{Conclusion}
|
|
|
|
Fine-tuning Zen models is practical and efficient across a wide range of methods
|
|
and compute budgets. LoRA rank 64 over the attention projections achieves
|
|
98.3\% of full fine-tuning performance at 0.8\% of parameters, making it the
|
|
default recommendation. QLoRA extends this to Zen-32B on commodity hardware.
|
|
Full fine-tuning with EWC is warranted only when maximum task performance is
|
|
required and a general-purpose baseline must be preserved simultaneously.
|
|
|
|
\bibliographystyle{plain}
|
|
\begin{thebibliography}{99}
|
|
\bibitem{hu2021lora} Hu et al. (2021). LoRA: Low-Rank Adaptation of Large Language Models. \textit{ICLR 2022}.
|
|
\bibitem{dettmers2023qlora} Dettmers et al. (2023). QLoRA: Efficient Finetuning of Quantized LLMs. \textit{NeurIPS}.
|
|
\bibitem{kirkpatrick2017ewc} Kirkpatrick et al. (2017). Overcoming catastrophic forgetting in neural networks. \textit{PNAS}.
|
|
\bibitem{biderman2024lora} Biderman et al. (2024). LoRA Learns Less and Forgets Less. \textit{arXiv:2405.09673}.
|
|
\bibitem{xu2023qa} Xu et al. (2023). Parameter-Efficient Fine-Tuning Methods for Pretrained Language Models. \textit{arXiv:2308.10792}.
|
|
\end{thebibliography}
|
|
|
|
\end{document}
|