返回资讯中心
外部精选
软件工程
#开发者实时流

Train or fine-tune large models on your own devices, no expensive GPUs

Pool your devices. Train bigger models for free.

Hacker News 最新sonic262026/11/23 · 今天30 分钟阅读

以下正文同步自 Hacker News 最新,版权归原站所有,已转换为易读排版。

layerpool

Pool your devices. Train bigger models for free.

One model, split by layers across all your machines. Their memory is pooled, and they train it as one.

import layerpool.hf as lp from transformers import Trainer

model = lp.AutoModelForCausalLM.from_pretrained("Qwen/Qwen3-14B") # spread over all your devices Trainer(model=model, args=args, train_dataset=data).train() # everything else stays the same

How it works

Any hardware, mixed. NVIDIA GPUs, Apple Silicon (with MLX or PyTorch) and plain CPUs, on Linux, Windows and macOS, in one model.

Full control of each device. Its memory cap, which of its GPUs to use, how many layers it takes, its place in the chain, and RAM for layers that do not fit its GPU. Or leave everything to layerpool.

Over the internet. Devices on the same network talk directly; the rest join through a cloudflared tunnel, with a token on every connection. No port forwarding.

Survives disconnects. If a device drops out, the others take over its layers and training goes on.

Balances itself. Faster devices get more layers, the split adjusts while training runs, and a device that only slows the run down sits it out.

Live dashboard. Devices, memory, temperature, speed and loss, with every setting in reach.

Any model in transformers. Text, vision-language, speech, embedding, mixture-of-experts and Mamba models: Llama, Qwen, Gemma, Mistral, Phi, Mixtral, SmolVLM, Whisper, T5, BERT and others. Before the first run of an architecture, layerpool checks that its split computes the same as the whole model, and stops with a clear message if it does not.

Every kind of training. LoRA, QLoRA, full fine-tuning, training from scratch, DPO, KTO and other preference methods, reinforcement learning, or your own loss.

Quickstart

  1. Install and start the pool on your computer:

pip install layerpool layerpool up

The dashboard opens, and your computer joins as the first device.

  1. Add devices. Click Add device and run the command it gives you on each device:

pip install -U layerpool layerpool join http://192.168.1.8:7341 --token inv_...

  1. Train. Run your usual training script on your computer. It finds the pool by itself.

To check first whether a model fits the devices you have, and how it would be split: layerpool plan Qwen/Qwen3-14B. For devices outside your network, start the pool with layerpool up --tunnel.

Requirements. Python 3.11 or newer on Linux, Windows or an Apple Silicon Mac, with NVIDIA or AMD (ROCm) GPUs, Apple Silicon or plain CPUs.

Hugging Face Trainer and TRL import layerpool.hf as lp from trl import SFTTrainer, SFTConfig

model = lp.AutoModelForCausalLM.from_pretrained("Qwen/Qwen3-8B", lora_r=16) trainer = SFTTrainer(model=model, args=SFTConfig(output_dir="out"), train_dataset=dataset) trainer.train() model.save_pretrained("my-adapter")

Works with transformers.Trainer and TRL's SFTTrainer, DPOTrainer and KTOTrainer, including gradient accumulation, evaluation, checkpoints, resuming and load_best_model_at_end. Install the extras with pip install "layerpool[hf]".

Every AutoModel class works the same way:

vision = lp.AutoModelForImageTextToText.from_pretrained("HuggingFaceTB/SmolVLM-256M-Instruct") speech = lp.AutoModelForSpeechSeq2Seq.from_pretrained("openai/whisper-small") embedder = lp.AutoModel.from_pretrained("sentence-transformers/all-MiniLM-L6-v2")

Your own PyTorch loop import torch import layerpool.hf as lp

model = lp.AutoModelForCausalLM.from_pretrained("Qwen/Qwen3-8B", lora_r=16) opt = torch.optim.AdamW(model.parameters(), lr=1e-4)

for batch in loader: loss = model(input_ids=batch["input_ids"], labels=batch["labels"]).loss loss.backward() torch.nn.utils.clip_grad_norm_(model.parameters(), 1.0) opt.step() opt.zero_grad()

Any loss you can write Your loss gets the log-probability of every token:

import layerpool from layerpool import losses

pool = layerpool.connect() run = pool.run("Qwen/Qwen3-8B", rank=16, lr=1e-4)

def my_loss(logprobs, mask, data): return losses.cross_entropy(logprobs, mask)

for ids, labels in batches: run.forward_backward(ids, labels, loss=my_loss) run.optim_step(max_grad_norm=1.0)

run.save("my-adapter")

Built in: cross_entropy, dpo, ipo, simpo, orpo, policy_gradient.

layerpool train --model Qwen/Qwen3-8B --data data.jsonl --method sft --epochs 1 --out my-adapter

--method also takes cpt, dpo, ipo, simpo and orpo. In Python the same loop is run.train("data.jsonl", method="sft").

Method How

LoRA lora_r=16

QLoRA load a checkpoint already quantized to 4 bits with bitsandbytes, such as unsloth's ...-bnb-4bit models. Macs train their layers on an MLX 4-bit copy: for unsloth's models they find the mlx-community one by themselves, for others add mlx_model=. The two 4-bit formats round the frozen weights a little differently

Full fine-tuning full=True

From scratch full=True, random_init=True

Continued pretraining plain text, or method="cpt"

DPO, KTO, IPO, SimPO, ORPO TRL DPOTrainer or KTOTrainer, or method="dpo", "ipo", "simpo", "orpo"

Reinforcement learning losses.policy_gradient

Classification with a new head lp.AutoModelForSequenceClassification.from_pretrained(model, num_labels=3)

Also train modules outside the blocks modules_to_save=["embed_tokens"], as in PEFT

Resume trainer.train(resume_from_checkpoint=...), or model.load_adapter(folder)

Text, vision, speech and embedding models all work: anything in transformers built from a stack of repeated blocks.

Everything has a sensible default, and everything can be changed. Pass these to from_pretrained (or to pool.run):

Each device has its own settings too, in the dashboard, with layerpool set DEVICE, or when it joins (layerpool join URL ...):

When joining only: --backend torch or mlx on a Mac, --cpu to leave its GPU alone, and --allow-sleep to let the computer sleep (by default a device stays awake while it is in a pool, since a sleeping one looks gone; closing a laptop's lid still sleeps it). While a run trains, layerpool rebalance off keeps the split as it is, on lets layerpool move layers to faster devices, and now splits again; a setting no split could meet is refused with the reason, and training goes on.

Google Colab and Kaggle give free GPUs, and each can join your pool as a device. Start the pool with layerpool up --tunnel so notebooks can reach it, click Add device, open the Notebook cell tab, and paste the cell into the notebook.

No code at hand? Run layerpool join URL without --token: the device shows a short code and waits, and you let it in from the dashboard or with layerpool approve CODE.

Warning: read the terms of Colab, Kaggle or any other service before using it this way. Some services restrict this kind of use and may limit or suspend your account. You use them at your own risk.

Everything in the dashboard is also a command

Pool

layerpool up start the pool and open the dashboard (--tunnel for devices outside your network, --no-work so this machine takes no layers, --advertise for its address)

layerpool status -f follow training live (--json for scripts)

layerpool end end the current run at once

layerpool cache / cache clear show or free the disk space layerpool uses

Devices

layerpool invite create a join command for a new device

layerpool join URL --token T lend this device to a pool (without --token it waits for approval)

layerpool approve [CODE] / deny CODE let a waiting device in, or turn it away (no code: list them)

layerpool devices list devices (--json for scripts)

layerpool set DEVICE --layers 8 change a device's settings (see the table above; auto clears one)

layerpool pause DEVICE / resume DEVICE / remove DEVICE stop using a device, use it again, or take it out

Training

layerpool plan MODEL check whether a model fits the devices, and how it would be split

layerpool train --model M --data D train without writing code (--save-every, --resume)

layerpool rebalance on / off / now while training: move layers to faster devices, keep the split, or split again

Environment

LAYERPOOL_URL, LAYERPOOL_TOKEN the pool layerpool.connect() uses, when it is not the one layerpool up started on this computer

LAYERPOOL_NO_UPDATE_CHECK=1 layerpool up does not ask PyPI whether a newer version exists

LAYERPOOL_ABANDON_S seconds without word from the training script before its run is ended (default 120)

LAYERPOOL_PATIENCE_S seconds a device keeps trying to reach a pool that does not answer (default 1800)

LAYERPOOL_REPLAY_GB GB of recent steps the pool keeps on disk to redo them after a device drops out; past it, devices save a new checkpoint (default 4)

FAQ

Is the result as good as training on one big GPU? Practically, yes. Every device runs the same math it would run inside one machine. By default the data passed between devices is sent in 16-bit, which changes the loss by a fraction of a percent. With codec="fp32" the losses match a single-machine run. One difference: the blocks on the devices run without dropout (most recent models are trained without it anyway); dropout in the parts on your computer still applies. GPUs that train in float16 (a T4, for example) scale the loss to keep small gradients; when a piece of a batch overflows there, that device runs it again with a smaller scale, so no step is lost.

Any model in transformers that is built from a stack of repeated blocks, which is nearly all of them. Your computer runs the model's own code and keeps the parts around the stack (embeddings, output head, image or audio encoder); the devices hold the blocks. On Apple Silicon, text models that mlx-lm supports run with MLX: before the first run of an architecture, layerpool checks on a small copy that MLX computes its blocks as transformers does. The rest run there with PyTorch, and a 4-bit model that MLX cannot run leaves the Mac out of that run. MLX numbers each row's tokens itself, so packed sequences need PyTorch. Encoder-decoder models such as T5, BART and Whisper work too: the bigger stack is split and the other stays on your computer. LayerDrop (wav2vec2, HuBERT) is turned off, since every block runs on every step. Not supported yet: image generation models, convolutional vision models, and a few models whose split was found not to match the whole model (layerpool says so instead of training them). Also not supported: models that need trust_remote_code, repos without .safetensors weights, revisions other than the main branch, and the outputs of each block (output_hidden_states, output_attentions, use_weighted_layer_sum).

Devices pass activations to each other at every step, so the network often sets the pace: it is slower than one GPU that holds the whole model, and the point is to train models that do not fit any one of your devices. For example, QLoRA on Qwen3-8B (4-bit) split over an M5 Pro MacBook, a cloud T4 and a Kaggle notebook with two T4s, all over internet tunnels, trained at about 75 tokens per second (sequences of 256 tokens, batches of 8). Models with linear-attention blocks (Qwen3.5, Qwen3-Next) run them much faster on NVIDIA GPUs with pip install flash-linear-attention causal-conv1d; the pool says which devices lack them.

The devices work at the same time only when a batch has several pieces to pass along: give the Trainer a bigger per_device_train_batch_size and fewer gradient_accumulation_steps (the same rows per step), such as 8 and 1 rather than 2 and 4. Each batch is cut into micro pieces (8 by default) that follow each other through the devices.

The dashboard is reachable only from your computer and needs a token. Devices join with invite codes that expire, and you can remove any device at any time. Each device runs part of the model, so add only devices you trust.

The other way round, join only pools you trust: a pool tells its devices which model to download (with their own Hugging Face login) and gets the trained weights back. On your own network the traffic between devices is not encrypted; through a tunnel it is HTTPS. --tunnel downloads Cloudflare's cloud

正文由 探How 从来源站点 RSS 同步,内容未经改写;遇到排版缺失或需要图片、视频时请以原文为准。

打开原文
去社区讨论 →