jetc@portfolio ~/projects/nanoweight-writing-a-lora-from-a-sentence
jetc@debian: ~/project/nanoweight-writing-a-lora-from-a-sentence

$ cat nanoweight-writing-a-lora-from-a-sentence.md

nanoWeight - Writing a LoRA from a sentence

Hey o/

Before anything, a big thanks to OVH for their 200 € of free credit, which allowed me to run this experiment at full scale instead of downscaling it to fit on my two RTX 3070.

Introduction

What if you could fine-tune a model just by telling it what you want?

When you want a language model to do a specific task, the standard recipe is to fine-tune it. Nowadays that usually means a LoRA: a small set of extra weights plugged on top of the frozen model. It's cheap compared to full fine-tuning, but it still means collecting examples, running a training, picking hyperparameters, and waiting.

But a task can often be described in one sentence: "Given a product review, answer positive or negative." If a model can understand that sentence, why can't it turn it directly into weights?

That's the idea behind nanoWeight: a generator that reads the description of a task, in plain text, and outputs a LoRA for Qwen3.5-2B directly. No training at inference, one forward pass, done. The idea isn't new (Sakana AI published Text-to-LoRA in 2025), but I wanted to build it from scratch, at a larger number of tasks, and above all understand where it stops working.

To train a generator that outputs LoRAs, you first need a lot of LoRAs. So the project has two halves: a LoRA factory, then the generator itself.

Building a LoRA factory

Finding tasks

The first step was boring but essential: an inventory of every dataset on Hugging Face that comes with a task description. Super-NaturalInstructions (SNI), BIG-bench, LegalBench, maths, code, and so on.

I kept 1,576 base tasks, each with at least 300 examples, and split them into train / val / test by group of source texts. Why by group? Many tasks share the same underlying texts (the same reviews, with one task asking for the sentiment and another for the topic). If one ends up in train and the other in val, the generator can cheat by recognising the texts rather than understanding the description. Splitting by group avoids that leak.

Some tasks were designed to force the generator to read:

  • 96 procedural tasks (included in the 1,576), generated by program: Caesar cipher, sorting, base conversion… The inputs all look alike, and only the description says which function to apply.
  • On top of that, 250 format variants: the same task as an existing one, with a different output instruction (answer in JSON, in uppercase, with renamed labels…).

That's 1,826 tasks in total.

Training thousands of LoRAs

Each LoRA is rank 8, on the gate, up and down projections of the MLPs. The training trick that made the whole thing affordable is packing: concatenating several short examples into one sequence instead of padding each one. Qwen3.5 has convolution layers that leak information between packed examples, so I had to patch them to reset at example boundaries. Result: about ×15 in speed.

For the recipe, a fixed budget of about 1 epoch, with checkpoints saved at 2, 3.5, 5 and 10% of the training. I also trained weaker LoRAs on only 4 or 16 examples. Why keep bad LoRAs? Because the generator is conditioned on a target score q, and to learn what "a LoRA that scores 0.3" looks like, it needs to see some.

Production ran on OVH H100s: about 4,360 LoRAs produced.

Generator v0: copying LoRAs

The first version is the obvious one. Each description is encoded by a frozen Qwen (averaging the hidden states of one layer), and a decoder learns to output the weights of the corresponding LoRA. I tried two decoders: a parallel one (an MLP that outputs everything at once) and a sequential one (a transformer that outputs the weights chunk by chunk).

Every score in this article is the task score of Qwen + LoRA on held-out examples, between 0 and 1.

Result: 0.169. The nearest neighbour baseline, which just takes the LoRA of the training task whose description is the most similar, gets 0.163. So the generator was barely better than a lookup. The sequential decoder was worse: each chunk depends on the previous ones, errors accumulate, and I dropped it.

The reason became clear when I compared two LoRAs trained on the same task with two different random seeds. They share only about 35% of their weights. The other 65% is noise from the initialisation and the order of the examples. In other words, even a perfect generator can't predict most of what it's asked to copy, because it's random. Learning to copy weights was the wrong target.

Generator v1: making the task work

So I changed the target. Instead of comparing the generated LoRA to a real one, the v1 plugs the generated LoRA into Qwen and computes the loss on the task's examples. The generator isn't judged on what the weights look like, but on what they do. Any of the many LoRAs that solve the task is now a correct answer.

Result: 0.199, against 0.567 for a real trained LoRA. Better, still far. And for the first time, a small success on the format variants.

But a single number means nothing, and we are number nerds here. So, a series of checks:

Experiment Score
v1 generator 0.199
Same, with the description of another task 0.077
A single multitask LoRA for all tasks 0.115
Trained on 25% / 50% / 100% of the tasks 0.189 / 0.185 / 0.196
Trained with 8,741 paraphrased descriptions 0.193 (vs 0.194 without)
  • Shuffled descriptions drop the score to 0.077: the generator really uses the description, it's not just producing a generic "good LoRA".
  • One multitask LoRA gets 0.115: generating a specific LoRA per task is clearly better.
  • The scaling curve is flat on that range. More tasks, same score.
  • Paraphrases: Haiku agents rewrote each description 5 times (8,741 rewrites after filtering), hoping to make the generator robust to wording. No gain at all.

More tasks, without LoRAs

The flat scaling curve could mean that 1,135 training tasks is just too few to see anything. And there's a nice consequence of the v1 objective: it doesn't need LoRAs to learn, only a description and examples. So I can add tasks without paying for their LoRAs.

Two pilots, 50 tasks each:

  • Dynosaur-style: agents read Hugging Face datasets and propose tasks (some columns as input, one as output, plus a description). The answers come from the dataset itself. The idea comes from Dynosaur, a method to build instruction-tuning data from existing datasets.
  • FineWeb-Edu: agents write tasks as programs over extracts of educational web pages. The answers are exact and unlimited.

Then the real batch: 1,083 tasks without LoRAs (706 FineWeb, 275 leftovers from the catalogue, 102 Dynosaur), roughly doubling the training set.

The validation loss started overfitting later (step 400 instead of 100–200), which is what you expect with more data. But the score didn't move: 0.195 against 0.194. The one encouraging detail: trained on the new tasks alone, without a single real LoRA, the generator gets 0.178, already above the nearest neighbour.

Generator v2: reading the tokens

Small break here: at that point I reorganised everything: new splits (by group, stratified by category, 75/10/15 → 1,275 / 182 / 368 tasks with LoRAs, plus 1,074 without), all runs from scratch, all evaluated on the same 177 val tasks. So the numbers from here on aren't comparable with the v1 ones.

And this time, I set the floor and the ceiling first:

Reference Score
Qwen without LoRA 0.035
Mean of all training LoRAs 0.072
Nearest neighbour 0.130
Real trained LoRA 0.668

To make results readable, I use the fraction of the gap closed:

gap closed = (score − score without LoRA) / (score of the real LoRA − score without LoRA)

0 means "no better than Qwen alone", 1 means "as good as training".

What worked

Two changes, and only two:

  1. Cross-attention on the tokens of the description, instead of their average. Averaging a sentence into one vector throws away which word goes where. Going from 0.222 to 0.261 (+0.038).
  2. Four input/output examples after the description (xattn_shot4): 0.278. That's (0.278 − 0.035) / (0.668 − 0.035) = 0.243 / 0.633 ≈ 38% of the gap closed. It's the best result of the whole project.

v2 results The best generator against the floor and the ceiling, on the same 177 val tasks

Before celebrating, I retrained the exact same config: 0.270. So the noise between runs is about 0.008, and any difference below ~0.015 is not something I can trust. Keep that in mind for the next list.

What didn't

Everything below lands between 0.26 and 0.28, which means: nothing.

  • A bigger generator (215M parameters instead of 83M): 0.267.
  • More examples, 8 or 16 instead of 4: 0.264 and 0.272.
  • Which layer of Qwen is read: 6, 18 or 24 all give the same plateau (0.263–0.273). Only layer 0, the raw token embeddings, drops (0.215).
  • A learned mix of layers: 0.276 when global (and the weights stayed uniform anyway), 0.263 per token.
  • Distillation from the real LoRAs: 0.272 (cross-entropy + KD), 0.279 (KD only).

The format variants

They stayed at ~0 everywhere, while the real LoRAs get 0.78 on them.

Looking at the outputs, the generator does pick the right family of wrapping (a tag, JSON, a prefix), but not the exact literal. If the instruction says "prefix every answer with ANSWER>>", it writes some prefix, just not that one. Worse, the format instruction tends to override the task itself.

I tried to force it with 1,500 synthetic variants using random literals. The generator learned the family (78% vs ~40% before), the exact literal in only 7% of cases, and the overall score dropped (0.260).

That's probably the most interesting finding of the project: the generator learns a type of behaviour, not how to write a precise string into the weights.

The scaling curve, again

This time I varied the number of groups of tasks rather than the number of tasks: 156 → 312 → 625 groups give 0.226 → 0.236 → 0.278. Unlike v1, the slope is clear. The lever seemed to be the number of distinct groups, not the raw number of tasks.

Scaling in groups The v2 scaling curve, and what happened when I tripled the number of groups (next section)

More distinct groups

So, more groups. Five new sources, deduplicated against each other and cleaned of anything in val or test:

Source Tasks Groups
tasksource 314 209
Full Dynosaur 380 141
Hub datasets, columns chosen by Haiku 134 87
Hub definitions rewritten by Haiku 656 471
Synthetic grid (skills × domains × formats, written as programs by Haiku agents) 3,180 833

1,732 new groups, against 625 before. About ×3.

Result: 0.271 with the real sources only, 0.266 with the grid on top, against 0.278 / 0.270 for the reference. No gain at all. The validation loss plateaus at the same level (1.88).

The slope of the scaling curve doesn't extend to tasks that are far from the evaluation domain (which is mostly SNI). More groups helps when they look like what you're tested on. New, different groups don't.

Using a generated LoRA as a starting point

At this point the generator was stuck at 38%. So I asked a different question: even if it's not good enough alone, is a generated LoRA a good starting point for a normal training? Does it converge faster, or higher, than the standard init (A random, B = 0)?

50 random val tasks, trained with the production recipe, from three starting points:

  • std: the production LoRA, standard init;
  • gen: the LoRA generated by xattn_shot4;
  • mean: the mean LoRA of the training set, as a control for "a good generic init".

Intermediate checkpoints are evaluated on 50 test examples, the final one on 200.

Training progress std gen mean gen − std [95% CI] gen − mean [95% CI]
start (0%) ~0.035* 0.281 0.086 +0.196 [+0.130; +0.268]
2% 0.218 0.504 0.358 +0.286 [+0.221; +0.356] +0.146 [+0.089; +0.211]
3.5% 0.357 0.516 0.475 +0.159 [+0.090; +0.232] +0.041 [−0.010; +0.111]
5% 0.409 0.531 0.510 +0.123 [+0.061; +0.192] +0.021 [−0.005; +0.050]
10% 0.535 0.565 0.555 +0.029 [+0.014; +0.046] +0.010 [−0.007; +0.026]
final (100%) 0.708 0.707 0.707 −0.002 [−0.012; +0.007] −0.000 [−0.007; +0.007]

* Qwen without LoRA, not measured on these 50 tasks: value from the v2 eval on 177 tasks.

Fine-tuning from three starts Score during training, from the standard init, the mean LoRA and the generated LoRA

Reading it row by row:

  • Faster at the start. At 2% of the training (~40 steps), the generated start reaches 0.50 against 0.22 for the standard one. It reaches 90% of the final standard score as early as 2% on 35% of the tasks, against 8% for the standard init and 20% for the mean LoRA.
  • Not higher at the end. All three finish at the same score (0.707–0.708). Per task: 38 equal within ±0.02, 7 better, 5 worse.
  • The generator's own advantage is short. The mean LoRA already gives a big part of the speedup. The generator is only significantly better than it at the start and at 2%. From 3.5% onwards, the confidence interval of gen − mean includes 0.

In practice: a generated LoRA is a good start for a very short training (a few dozen steps). Beyond ~10% of an epoch, it brings nothing.

Wrapping up

  • Best generator: xattn_shot4, 0.27–0.28 on val tasks, about 38% of the gap between Qwen alone and a real LoRA. It clearly beats the nearest neighbour (0.130), the mean LoRA (0.072) and a multitask LoRA (0.115 in v1), and it really uses the description (shuffled: 0.077).
  • The ceiling: since v2, nothing went above that level. Not the architecture, the size, the number of examples, the layer, distillation, paraphrases, format variants, or ×3 more groups. The bottleneck is generalising to new tasks, not reading the text nor the training signal.
  • Limits: exact format instructions and translations are out of reach. And two LoRAs of the same task only share ~35% of their weights, which limits any approach that learns weights directly.
  • As an init: a real head start (0.50 vs 0.22 after 2% of an epoch), no change on the final score, and a plain mean LoRA already gives a good part of it.

What's next ?

A soft nearest neighbour

Instead of outputting weights directly, output a weighted combination of the training LoRAs. The generator would only choose how much of each LoRA to take. Given that 65% of each LoRA is seed noise, mixing existing LoRAs might be a much easier target than inventing new ones.

The test set

gen-test has never been used. All the numbers above are on val, and after this many experiments, val is a bit overfitted by my own choices. One clean final evaluation would be the honest thing to do.

Tasks closer to the evaluation

The ×3 groups experiment says that distance from the eval domain matters more than quantity. So rather than new sources, more tasks that look like the evaluated ones, and see if the v2 slope comes back. When I have something to show, I will write a new post about it ;)

jetc@debian: ~
jetc@debian: ~/