5 min read
Fine-Tuning
Continue training a model you built, tune a small head on a Hugging Face encoder in your browser, or write a LoRA script for a Hugging Face model, and see whether the result beats where you started.
Start from a model
Fine-Tune lists the models you have trained. Every model a run produces is kept in the project automatically, in the project folder when one is open and in the browser otherwise, so there is nothing to export first. You can also search the Hugging Face Hub; the search works without signing in.
Three ways to tune
- A model you trained: it is tuned in the browser, on your own GPU, with a live view of every epoch. DLWAY holds out validation rows (an even share of every class, or the table's own train / val column), stops when the validation loss stops improving, and keeps the best epoch rather than the last. The result is a new model; the one you started from is never changed.
- A head on a Hugging Face encoder: for a model that can turn a text or a picture into a vector, DLWAY trains a small classifier on those vectors, here in your browser. See the next section.
- A LoRA script for a Hugging Face model: DLWAY writes a fine-tuning script, with its requirements and your dataset, as a script or a Jupyter notebook for Colab. It adapts the attention layers of the model's own architecture, pads each batch to its longest text, and reports accuracy and macro-F1 every epoch. You can run it yourself, or attach a Jupyter or Kaggle kernel and DLWAY runs it there (see Run a LoRA script on a kernel, below). Open as a graph draws the same fine-tune in the Model Builder as blocks (a pretrained model, an adapter and a head), where editing a block changes the script.
Tune a head on an encoder
Choose Hugging Face Hub and an encoder (the Checked encoders are ones DLWAY has run end to end; any model with ONNX files and a feature-extraction task can work). DLWAY looks at the model's files, not its tags, and says whether it can run in a browser and how big the download is. Then pick the dataset, the column that holds the text (or, for a picture encoder, the pictures' column) and the column of classes.
The run has three steps, each shown as it happens: the encoder is downloaded the first time and the browser keeps it; every row is read once by the encoder, a few at a time, with the speed measured on your device; and a small classifier is trained on what it read, with a live chart. By default it is a linear probe, one layer, which is usually all a good encoder needs; a hidden layer is an option. The encoder's own weights are never changed.
The result is compared with always answering the most common class, which is what a model that learned nothing scores. A head has no base model to be compared with, and the screen says so. The model it keeps names its encoder, so it runs in Deployment (the encoder reads the input first) and appears in the model list like any other. A pipeline's Evaluate Model and Batch Predict steps can score it on a table too: they read its text column (or the pictures named in media_ref) through the encoder first, so the data needs that column; the model remembers which one, and each step has an Input column setting for a model that does not. Explain is not offered for it, since what it reads is the numbers an encoder made and not columns. It cannot be tuned again from the model list; choose the encoder again instead. A text encoder can also be drawn as a graph, with Open as a graph. Up to 20,000 rows are read in the browser. To tune on pictures, give it a table of them: drop a folder of pictures (one sub-folder for each class) onto the Data Hub's library page, which reads every picture into one table with its class taken from its folder. A folder added through the Add data wizard is kept as a set of files for the Structure manager instead, has no rows, and is not offered here; Fine-Tune says so when it finds one. A quantized encoder gives a slightly different vector for a text depending on what else was read with it, so DLWAY reads one text at a time and the same way when the model is used; tuning and using it agree exactly. Encoder precision offers the smaller quantized weights or full precision where the encoder has both. For a picture encoder, full precision runs on the graphics card when the browser allows it (WebGPU), which was about five times quicker than the quantized one on the processor when measured, with the same vectors as full precision on the processor; the result says when the card was used. Full precision is a larger download (DINOv2-small: about 88 MB against about 23 MB). A text encoder gains nothing from the card and stays on the processor. A model tuned at full precision still runs without a graphics card, only more slowly.
Run a LoRA script on a kernel
A real LoRA run needs a GPU, which the browser cannot give a model of this size. Attach a Jupyter or Kaggle server (the Where Python runs menu at the top, then Add compute…: on Kaggle, start a notebook with a GPU and Internet on, and copy its Jupyter Server URL), and the Run it on a kernel card appears under the script settings. It looks at the kernel first (its GPU, whether PyTorch can use it, which packages it has, whether it can reach Hugging Face, how much disk is free) and warns about what would make the run slow or fail.
Send the data and start sends the script and your rows to the kernel and starts the run there as a process of its own, in a folder named dlway-runs/ft-…. Packages the kernel lacks are installed first. The run is then shown like any other: its stages, the loss at every step, the validation numbers each epoch, and what the kernel printed. It is compared with always answering the most common class, as a head is. Because the run is a process of its own, it does not depend on a request staying open (the kernel's own streams are cut off after a few minutes) or on this tab staying open: close the tab, come back, and the run is in the list as running; Reconnect reads what it wrote while nobody was watching and goes on. Stop asks the run to stop after its current step and keeps its best epoch; a run that is not training yet, or does not answer within a minute and a half, is ended.
When the run ends, its adapter comes back into the project as an export bundle (the weights LoRA trained, their settings, the tokenizer and a README), which Download adapter (.zip) gives you and the storage manager counts. An adapter holds only the weights LoRA changed, so it needs the base model to run, and DLWAY cannot run one in the browser or in Deployment: load it with PEFT, as the README shows. An adapter over 300 MB is left on the kernel, with its path; Remove from the kernel deletes the run's folder when you are done with it.
What to know before sending a run. Your rows leave the browser for the kernel (through DLWAY's server when the kernel is a public one, as for any Python run there) and stay in the run's folder until you remove it. A gated Hugging Face model needs its token set on the kernel itself. The kernel runs one request at a time, so something else you run in the editor while a run is going may find it busy for a moment. A run keeps going only as long as the provider keeps the kernel's session alive: if it ends the session, the run ends with it, and the screen says it lost contact instead of calling it failed.
Did it help?
A finished run sets the tuned model against the base model on the same validation rows: loss, accuracy, and a confusion matrix of the classes. Use the tuned model in Deployment from the same screen, or tune it again with different settings.
Bring your data
Fine-Tune uses the datasets already in your Data Hub. A table too large to keep in memory is read when you choose it, up to 200,000 rows; take a sample in PrepFlow or a pipeline for more. The same engine runs the Fine-tune step of a pipeline, so the same model and data give the same result from either.
Tutorial
Follow Fine-Tune a Model You Trained for a guided run, including the Hugging Face script path.