Skip to content

Commit 85885db

Browse files
scottiredbrian57
andauthored
Add BYO-LORA docs (#1880)
Adds documentation on how to use LoRAs with W&B Inference. --------- Co-authored-by: dbrian57 <daniel.brian@gmail.com>
1 parent 8f6d121 commit 85885db

2 files changed

Lines changed: 122 additions & 0 deletions

File tree

docs.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1038,6 +1038,7 @@
10381038
"inference",
10391039
"inference/prerequisites",
10401040
"inference/models",
1041+
"inference/lora",
10411042
{
10421043
"group": "Response Settings",
10431044
"pages": [

inference/lora.mdx

Lines changed: 121 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,121 @@
1+
---
2+
title: "Use Serverless LoRA Inference"
3+
linkTitle: "Use Serverless LoRA Inference"
4+
description: >
5+
Bring your own custom LoRA for serving fine-tuned models on W&B Inference.
6+
---
7+
8+
LoRA (Low-Rank Adaptation) lets you personalize large language models by training and storing only a lightweight ‘add-on’ instead of a full new model. This makes customization faster, cheaper, and easier to deploy.
9+
10+
You can train or upload a LoRA to give a base model new capabilities, such as specializing it for customer support, creative writing, or a particular technical field. This allows you to adapt the model’s behavior without having to retrain or redeploy the entire model.
11+
12+
## Why use W&B Inference for LoRAs?
13+
14+
- Upload once, deploy instantly — no servers to manage.
15+
- Track exactly which version is live with artifact versioning.
16+
- Update models in seconds by swapping small LoRA files instead of the full model weights.
17+
18+
## Workflow
19+
20+
1. Upload your LoRA weights as a W&B artifact
21+
2. Reference the artifact URI as your model name in the API
22+
3. W&B dynamically loads your weights for inference
23+
24+
Here's an example of calling your custom LoRA model using W&B Inference:
25+
26+
```python
27+
from openai import OpenAI
28+
29+
model_name = f"wandb-artifact:///{WB_TEAM}/{WB_PROJECT}/qwen_lora:latest"
30+
31+
client = OpenAI(
32+
base_url="https://api.inference.wandb.ai/v1",
33+
api_key=API_KEY,
34+
project=f"{WB_TEAM}/{WB_PROJECT}",
35+
)
36+
37+
resp = client.chat.completions.create(
38+
model=model_name,
39+
messages=[{"role": "user", "content": "Say 'Hello World!'"}],
40+
)
41+
print(resp.choices[0].message.content)
42+
```
43+
44+
Check out this [getting started notebook](https://wandb.me/lora_nb) for an interactive demonstration of how to create a LoRA and upload it to W&B as an artifact.
45+
46+
## Prerequisites
47+
48+
You need:
49+
50+
* A [W&B API key](/models/integrations/add-wandb-to-any-library#create-an-api-key)
51+
* A [W&B project](/models/track/project-page)
52+
* **Python 3.8+** with `openai` and `wandb` packages:
53+
`pip install wandb openai`
54+
55+
56+
## How to add LoRAs and use them
57+
58+
You can add LoRAs to your W&B account and start using them with two methods:
59+
60+
<Tabs>
61+
<Tab title="Upload a LoRA you trained elsewhere">
62+
Upload your own custom LoRA directory as a W&B artifact. This is perfect if you've trained your LoRA elsewhere (local environment, cloud provider, or partner service).
63+
64+
This Python code uploads your locally stored LoRA weights to W&B as a versioned artifact. It creates a `lora` type artifact with the required metadata (base model and storage region), adds your LoRA files from a local directory, and logs it to your W&B project for use with inference.
65+
66+
```python
67+
import wandb
68+
69+
run = wandb.init(entity=WB_TEAM, project=WB_PROJECT)
70+
71+
artifact = wandb.Artifact(
72+
"qwen_lora",
73+
type="lora",
74+
metadata={"wandb.base_model": "OpenPipe/Qwen3-14B-Instruct"},
75+
storage_region="coreweave-us",
76+
)
77+
78+
artifact.add_dir("<path-to-lora-weights>")
79+
run.log_artifact(artifact)
80+
```
81+
82+
### Key Requirements
83+
84+
To use your own LoRAs with Inference:
85+
86+
* The LoRA must have been trained using one of the models listed in the [Supported Base Models section](#supported-base-models).
87+
* A LoRA saved in PEFT format as a `lora` type artifact in your W&B account.
88+
* The LoRA must be stored in the `storage_region="coreweave-us"` for low latency.
89+
* When uploading, include the name of the base model you trained it on (for example, `meta-llama/Llama-3.1-8B-Instruct`). This ensures W&B can load it with the correct model.
90+
</Tab>
91+
<Tab title="Train a new LoRA with W&B">
92+
Train a new LoRA with [W&B Training (serverless RL)](/training). Your LoRA automatically becomes a W&B artifact that you can use directly.
93+
94+
For detailed information on how to train your own LoRA, see [OpenPipe's ART quickstart](https://art.openpipe.ai/getting-started/quick-start).
95+
96+
Once training is complete, your LoRA is automatically available as an artifact.
97+
</Tab>
98+
</Tabs>
99+
100+
Once your LoRA has been added to your project as an artifact, use the artifact's URI in your inference calls, like this:
101+
102+
```python
103+
# After training completes, use your artifact directly
104+
model_name = f"wandb-artifact:///{WB_TEAM}/{WB_PROJECT}/your_trained_lora:latest"
105+
```
106+
107+
## Supported Base Models
108+
109+
Inference is currently configured for the following LLMs (exact strings must be used in `wandb.base_model`). More models coming soon:
110+
111+
- `OpenPipe/Qwen3-14B-Instruct`
112+
- `Qwen/Qwen2.5-14B-Instruct`
113+
- `meta-llama/Llama-3.1-70B-Instruct`
114+
- `meta-llama/Llama-3.1-8B-Instruct`
115+
116+
## Pricing
117+
118+
Serverless LoRA Inference is simple and cost-effective: you pay only for storage and the inference you actually run, rather than for always-on servers or dedicated GPU instances.
119+
120+
- [**Storage**](https://wandb.ai/site/pricing/) - Storing LoRA weights is inexpensive, especially compared to maintaining your own GPU infrastructure.
121+
- **Inference usage** - Calls that use LoRA artifacts are billed at the same rates as [standard model inference](/inference/usage-limits#account-tiers-and-default-usage-caps). There are no extra fees for serving custom LoRAs.

0 commit comments

Comments
 (0)