Use an AI agent (Claude Code) with Vast.ai GPUs and Hugging Face to build models
Let Claude Code do the grunt work of machine learning — preparing data, renting a GPU, fine-tuning, evaluating and publishing to Hugging Face — while you decide what to build.
Training or fine-tuning a model is mostly plumbing: finding a base model, cleaning a dataset, picking a GPU, fixing CUDA and dependency errors, babysitting a run for hours, then evaluating and uploading. That's exactly the kind of long, fiddly, tool-heavy work an agent like Claude Code is good at — as long as it has a real machine and the right accounts connected.
The setup in one picture
| Piece | Role |
|---|---|
| Always-on server (CPU, plenty of RAM) | Where Claude Code lives: terminal, browser, code, logs, datasets. Cheap to keep running 24/7. |
| Claude Code | The agent: plans, writes and runs code, reads errors, iterates. |
| Vast.ai | A marketplace for renting GPUs by the hour. The agent starts an instance only when it needs to train, then destroys it. |
| Hugging Face | Where base models and datasets come from, and where finished models, adapters and demos get published. |
The key idea: don't keep a GPU running for the agent to think on. The agent's home is a normal server; GPUs are rented for the minutes or hours of actual training.
What the agent does, step by step
- Understand the goal. "Fine-tune a small open model to classify our support tickets into 12 categories" or "Make a model that writes product descriptions in our tone."
- Prepare the data. It cleans your CSVs or exports, removes duplicates, splits train/test, formats examples, and can push the dataset privately to the Hugging Face Hub.
- Pick a base model. It searches the Hub for suitable open models, checks licences and sizes, and recommends one that fits your budget.
- Write the training script. Typically Hugging Face
transformerswithpeft(LoRA) ortrlfor supervised fine-tuning — tested first on a tiny sample on the CPU server. - Rent a GPU on Vast.ai. Using the
vastaiCLI, it searches offers by GPU type, VRAM, price and reliability, starts an instance from a PyTorch image, and copies the code over. - Run and watch. It launches training, tails the logs, and fixes the usual problems — out-of-memory errors, wrong batch sizes, missing packages — without you waking up at 3 a.m.
- Evaluate. It scores the model on the held-out set and compares against the base model, so you see whether training actually helped.
- Publish and clean up. It pushes the model or LoRA adapter to Hugging Face (private or public), writes a model card, optionally builds a small demo — then destroys the Vast.ai instance so billing stops.
Connecting the accounts
- Hugging Face: create an access token (read for downloading, write for publishing) and log in on the server with the Hugging Face CLI. Use a fine-grained token limited to the repos the agent should touch.
- Vast.ai: add credit, create an API key and install the
vastaiCLI. Keeping only a modest balance on the account is a simple, hard spending cap. - Claude: your own Claude subscription or Anthropic API key powers the agent.
Store keys as environment variables or in the CLI's config on the server — never paste them into prompts or commit them to a repo.
Where Google Colab fits
Google Colab is great for poking at a dataset or trying an idea in a notebook with a free or cheap GPU. The agent can write notebooks you open in Colab to explore data and look at results, while the real training runs happen on Vast.ai where runs can last for hours and you choose the exact GPU. Many people use both: Colab to explore, Vast.ai to train.
What does it cost?
Vast.ai prices are set by the hosts and change constantly, but consumer cards like an RTX 4090 are often well under a dollar an hour and data-centre GPUs like A100s and H100s cost a few dollars an hour. A LoRA fine-tune of a small open model on a few thousand examples often finishes in well under a few hours — so the GPU bill for an experiment can be a few dollars. Always check current prices on Vast.ai.
The biggest cost risk isn't the training — it's a GPU left running by accident. Tell the agent, in writing, to destroy instances when a run finishes or fails, and to check for running instances at the end of every session.
Good first projects
- Text classification — tickets, reviews, leads, emails sorted into your categories.
- Extraction — turn messy documents or pages into clean structured fields.
- Tone and style — a small model that writes in your brand's voice for cheap, high-volume jobs.
- Embeddings and search — fine-tune an embedding model so search over your own content gets better.
- Image models — LoRA adapters for a product, a style or a character.
Start small. A fine-tuned small model that does one job well is usually cheaper and faster than prompting a giant model for the same task — and you own it.
Guardrails that matter
- Budget rules: max price per hour, max hours per run, always destroy instances when done.
- Data rules: keep datasets private on the Hub unless you decide otherwise, and don't upload personal data you don't have a right to use.
- Licences: check the base model's and dataset's licence before training for commercial use.
- Checkpoints: push intermediate checkpoints so a lost or interrupted instance doesn't cost the whole run — cheap marketplace GPUs can occasionally go offline.
Why the agent needs its own computer
Training runs are long. A laptop that sleeps, a chat window that times out, or a sandbox that resets will kill the job halfway. An always-on server with a terminal and browser lets Claude Code work for hours, keep logs and datasets between sessions, open the Hugging Face and Vast.ai dashboards when it needs to check something, and report back when you look at your phone.
Common questions
Can Claude Code train machine learning models?
Claude Code doesn't train models itself, but it can do almost all the work around training: prepare datasets, write the training code, rent a GPU, run and monitor the job, fix errors, evaluate the result and publish it to Hugging Face.
Why use Vast.ai instead of a GPU server that is always on?
Training only needs a GPU for hours at a time. Renting by the hour on Vast.ai and destroying the instance afterwards is usually far cheaper than paying for a dedicated GPU around the clock. The agent itself lives on a cheaper always-on CPU server.
What does Hugging Face do in this setup?
It is the source of open base models and datasets, and the place the agent publishes finished models, LoRA adapters, datasets and demos, privately or publicly.
How do I stop the agent from overspending on GPUs?
Keep a limited balance on Vast.ai, set a maximum hourly price and run length in the agent's instructions, and require it to destroy instances when a run ends and to check for running instances at the end of each session.
Do I need to know machine learning to use this?
It helps to know what you want the model to do and how you'll judge it. The agent handles the code, infrastructure and debugging, and explains its choices in plain language.
Claude and Claude Code are products of Anthropic. Vast.ai and Hugging Face are independent companies. WebHand is not affiliated with any of them.
Want an AI model agent with Hugging Face and Vast.ai already connected?
Two done-for-you plans at $499/month: we install Browser Use and Claude Code on your own server (Contabo, Hetzner, Amazon EC2), or give you a hosted Claude Code agent connected to Hugging Face and Vast.ai that builds and trains AI models. Setup and ongoing support included; you use your own Claude plan or API key.
See the two plans — $499/month