# Cpu trainer open source

> Source: <https://discuss.huggingface.co/t/cpu-trainer-open-source/192506#post_3>
> Published: 2026-11-26 09:45:07+00:00

**Recommendation:** Profile thread count and batch size before changing precision: 4 threads at batch 8 beat 1-2 threads, and BF16 autocast was slower than FP32 on this CPU loop.
More in the playbook "Inference and self-hosting": <https://wpnews.pro/playbooks/inference-serving>

For now, I tried a few things with CPU-only training in mind:

I would keep the basic CPU-only scratch design. The cached 4x16x16 latents are already a useful optimization. I reconstructed the displayed code to compare **cost per U-Net update** and **quality per training budget** separately.

Short repeated runs on a Colab Intel Xeon CPU allocation (PyTorch 2.14.1+cu130 executing on **CPU**, using cached real-image latents):

| Configuration | ms/update | Latent draws/s | 
|---|---|---|
| Original width, batch 4, 4 threads, FP32 | 31.27-32.75 | 122-128 | 
| Same, 1 thread | 56.16-59.40 | 67-71 | 
| Same, 2 threads | 40.78-42.32 | 95-98 | 
| Original width, batch 8, 4 threads | 39.47-41.70 | 192-203 | 
| Half width, batch 4, 4 threads | 22.90-24.39 | 164-175 | 
| Original width, batch 4, 4 threads, BF16 autocast | 54.73-59.41 | 67-73 | 

Ranges are short-run medians, not confidence intervals. Batch 8 increased throughput, width 32 reduced update time, BF16 was slower. Quality equivalence is unproven. Data preparation was ~0.16 ms (0.5%) in one reference run; loader workers would be more relevant with on-the-fly image preprocessing.

Separate two-thread CPU test, estimated 2,000 updates: 193-200 s eager, 276 s fresh compile, 190 s reused cache. Start eager.

For quality, zero terminal SNR with a matching velocity target increased prompt response in two paired training seeds, but samples remained rough. I used a T4 for quality comparisons, not CPU speed evidence. This requires new training; the speed changes are independent.

1. Measure the actual training loop
| Main limit | First option | 
|---|---|
| Seconds/update | Thread count, batch throughput, profile | 
| Repeated setup | VAE and latent/token cache | 
| Compute/RAM per update | Width or physical batch | 
| Rough images | Reconstructions, matched schedule/target/sampler | 
| Weak prompt response | Same-noise controls, known words | 
| Slow generation | CFG batching, preview steps | 
| Long repeated fixed-shape runs | Compilation including startup/reuse | 

CPU model, PyTorch version and update timing would help tailor settings.
