Skip to main content
Serverless Inference lets you use a custom LoRA with some base models. This tutorial walks you through creating a fine-tuned LoRA using supervised post-training through the TRL library, then uploading it to W&B as an artifact for use with the Serverless Inference API or Playground. The example uses a dataset of query/response pairs to fine-tune a model to respond like a cowboy, but you can adapt the same workflow to any character or task. This tutorial is for developers who want to customize a base model’s behavior without managing their own inference infrastructure. You can also create a LoRA using Serverless RL, which provides serverless reinforcement learning. The tutorial has three parts: prepare a post-training dataset, run the post-training script that produces and uploads the LoRA, and try the resulting LoRA in the Playground or from code.

Post-training dataset

This section provides the example dataset used to fine-tune the model. The following dataset contains 50 query and response pairs formatted as a list of messages, such as:
User: “What is your favorite color?”
Assistant: “Well, pardner, my favorite color’s the blazin’ orange of a desert sunset.”
The example file contains one JSON object per line. Save the following data in your working directory as cowboy_examples.jsonl.
cowboy_examples.jsonl
After you save this dataset, you’re ready to run post-training.

Post-training

This section walks you through running the training script that produces a LoRA adapter from your dataset and uploads it to W&B. The script trains a LoRA adapter on examples from the JSONL file and uploads it to W&B as an artifact for use with the Serverless Inference API or Playground. At a high level, this script does the following:
  1. Logs in to W&B. The Hugging Face Transformers integration of W&B Models automatically records training progress and metrics.
  2. Loads the base model (OpenPipe/Qwen3-14B-Instruct) from Hugging Face.
  3. Configures the LoRA using hyperparameters, such as rank and alpha, which the script defines as constants near the top of the file.
  4. Loads the examples from the file into a dataset and then runs SFTTrainer. By default, the script uses all examples.
  5. Saves the LoRA and uploads it to W&B as an Artifact for use with Serverless Inference.
When the script finishes, open the last printed URL in your browser to see the persisted artifact. It looks like this: Artifact URL: https://wandb.ai/[YOUR-ENTITY]/create-lora-tutorial/artifacts/lora/OpenPipe_Qwen3-14B-Instruct_cowboy/v0 Save the following program as create_lora.py and update the ENTITY value with your W&B entity. The script uses inline script metadata to declare its dependencies, so you can run it directly with uv without managing a separate virtual environment.
create_lora.py
Run the script using uv:
Execution time depends on hardware. To speed up training, add the --max-examples=10 argument, but fewer examples reduce how well the LLM responds in character. When the script finishes, you have a trained LoRA adapter stored as a W&B artifact, ready for use with Serverless Inference.

Use the LoRA

This section shows how to try the LoRA you created, either interactively in the Playground or programmatically. You can try your LoRA in the W&B Weave Playground. When you open the artifact URL, click Try in playground.
LoRA in Artifacts UI
Then enter your prompt at the bottom of the chat interface.
LoRA in Playground UI
To use your LoRA from code, see the Use Serverless LoRA Inference guide for step-by-step instructions.

Next steps

Now that you have a working LoRA, you can experiment further to see how training choices affect the result:
  • Train the LoRA with fewer examples to see if it still provides the desired effect.
  • Change the responses in the dataset to showcase another character, such as a pirate or a ninja.