Skip to main content
Apidly Cloud
Cookie policy

Analytics and ad cookies stay off unless you accept. Cookie policy

We would like to use Google Analytics and Microsoft Clarity to understand how the public pages are used, including page views and session recordings, and the Reddit Pixel to measure whether our ads on Reddit lead to visits and sign-ups. You choose here whether they are on. Rejecting changes nothing about how the site works.

Fine-tune a 7B model with LoRA on a cloud GPU

Fine-tune a 7B open model with LoRA or QLoRA on one rented GPU: prepare data, start a training notebook, train, save the adapter and stop the server.

Published November 25, 20265 min read

Fine-tuning teaches an open model your own examples: a house style, a fixed output format, a narrow task. With LoRA you train a small adapter instead of the whole model, so a 7B model fits on a single rented GPU. This guide goes from data to a saved adapter, and shows where to keep the cost under control. For a shorter planning list, read the fine-tuning checklist first.

Before you rent anything

Work that does not need a GPU should happen on your own computer.

  1. Write down the goal and a test. One sentence on what the model should do, and 50 to 200 held-out examples to check it. Without a test set you cannot tell if training helped.
  2. Prepare the data. Remove duplicates and empty rows, remove personal data you do not need, and make sure you have the right to use what is left. A few hundred clean examples usually teach more than thousands of messy ones.
  3. Use a format your trainer reads. Chat-style records with a messages list of user and assistant turns are the most common.
  4. Estimate the memory. With 4-bit loading (QLoRA), a 7B model's weights are around 4 to 5 GB; training adds the adapter, the optimizer state for it, and activations that grow with sequence length and batch size. A 24 GB GPU gives comfortable room. How much VRAM do you need? shows the arithmetic.

Step 1: Choose a training template

Apidly has fine-tuning templates, each a JupyterLab or browser tool with the libraries installed:

  • Unsloth fine-tuning notebook: a notebook with Unsloth for fast LoRA and QLoRA runs. Minimum 8 GB.
  • LLaMA-Factory: fine-tuning from a web page, with less code.
  • Fine-tuning starter: JupyterLab with PyTorch, transformers and peft, used in the fine-tuning tutorial. Minimum 24 GB.

See the full list on the templates page. This guide uses the Unsloth notebook: start it here. At the time of writing it does not run on RTX 50-series and other Blackwell GPUs; Deploy marks those configurations.

Step 2: Deploy

  1. Open Deploy and use the GPU memory filter for 24 GB, then sort by Price, low to high. The RTX 4090 and RTX 3090 are typical 24 GB choices. Check the live price on each page, because it changes.
  2. Pick the template, name the server, and set the disk. Plan for the base model, your data, checkpoints and the result: at least two to three times the model size is a safe start.
  3. In the automation section on the last step, add a stop rule so a forgotten run cannot continue for days: a running time that is a little longer than you expect, a stop when the GPU is idle, or a spending limit. See Automation.
  4. Check Per hour and select Start my server.

The first start installs the tools, so JupyterLab can take several minutes to answer after the status shows Running. Billing is by second from Running, so do your preparation first.

Step 3: Open the notebook and upload your data

On the Connect tab select Open Jupyter. Upload your data file into the notebook folder with the file browser, or copy it from your computer with scp; see Move data to and from a server. If the model needs a licence, add your Hugging Face token as the HF_TOKEN variable when you launch, and keep it secret (Secrets).

Step 4: Load the model in 4-bit and add the adapter

from unsloth import FastLanguageModel

model, tokenizer = FastLanguageModel.from_pretrained(
    "unsloth/Qwen2.5-7B-Instruct",
    max_seq_length=2048,
    load_in_4bit=True,
)
model = FastLanguageModel.get_peft_model(
    model,
    r=16,
    lora_alpha=16,
    target_modules=["q_proj", "k_proj", "v_proj", "o_proj"],
    use_gradient_checkpointing="unsloth",
)
model.print_trainable_parameters()

print_trainable_parameters() shows what share of the model you are training. It should be a small fraction of one percent to a few percent. The settings that matter:

  • r is the adapter's rank. A higher value can learn more and uses more memory. 8 to 16 is a normal start.
  • max_seq_length sets the longest example. Lower it if you run out of memory.
  • Gradient checkpointing saves memory at some cost in speed.

Run nvidia-smi in a terminal now. Seeing how much memory the loaded model uses tells you how much room is left for training.

Step 5: Train a short run first

Format your records into text with the model's chat template, then train with TRL's trainer. Option names change between library versions, so check the notebook the template creates and the library's documentation for the exact arguments. The shape is:

from trl import SFTConfig, SFTTrainer

trainer = SFTTrainer(
    model=model,
    train_dataset=dataset,
    args=SFTConfig(
        output_dir="outputs",
        per_device_train_batch_size=2,
        gradient_accumulation_steps=4,
        num_train_epochs=1,
        learning_rate=2e-4,
        logging_steps=5,
        save_steps=100,
    ),
)
trainer.train()

Do not start with the full dataset. Set max_steps=20 in the config, run, and confirm that the loss goes down, that memory stays within the GPU, and that checkpoints are written. A failed 20-step test costs a few minutes. A failed overnight run costs far more. When the test is healthy, remove max_steps and train for real.

If training stops with an out-of-memory error, lower the batch size (and raise gradient accumulation to compensate), shorten max_seq_length, or move to a GPU with more memory.

Step 6: Test on held-out examples

Run the tuned model on the test set from the start and compare its answers with the base model's on the same prompts. Read a sample yourself, since numbers alone hide problems such as repeated phrases or lost general ability. If the results are worse, the usual causes are noisy data, too many epochs or too high a learning rate.

Step 7: Save the adapter and copy it off the server

model.save_pretrained("lora_adapter")
tokenizer.save_pretrained("lora_adapter")

The adapter is small, usually megabytes to a few hundred megabytes. Copy it, your training settings and the data version to storage you control. Write down the library versions so you can repeat the run. Then you can serve the result: load it on top of the base model in a model server, as in Run an open LLM with vLLM.

Step 8: Stop the server

Your work is only safe once it is copied off the server.

  • Stop ends the compute charge and keeps the disk, which is still billed.
  • Destroy ends all charges and deletes the disk. Check your copy first, because deleted data cannot be recovered.

For long runs that save checkpoints and can resume, an interruptible price may be lower, with the risk that the server is paused when demand rises. See Interruptible servers and make sure your training resumes from the last checkpoint.

Cost, in short

You pay by the second for the time the server runs, plus the disk. Short test runs, a stop rule and a clean shutdown are what keep a fine-tuning bill small. Look at live pricing for current rates. For a smaller first run with a ready-made example, try the fine-tuning tutorial, and when you are ready create an account.

Try what this guide shows

Start one of these templates on a rented GPU server. You see the price per hour before you start, and you pay by the second.

Try it on a real GPU server

Create a free account and add a balance from $10. Servers are billed by the second, and the review step shows the price per hour before you request one.

Related guides