Docs · Machine learning

How clio-ml is built

clio-ml trains classic and neural models directly on data held in the CTE. Every algorithm is the same shape: per-row math over pages, block-private partial results, and an ordered reduction, wrapped in a runtime module so a fit can run on every node at once.

Algorithms
about 30
Backends
GPU or CPU, same math
Unit of work
one page
Client: one compute task, broadcast to every containerone model comes back; replicas that disagree are flagged Algorithm module (clio_ml_<algo>_chimod)shared container template plus a small adapter that calls the fit Fit: per-row math + ordered reduceblock-private partials, no global atomics Dataset (page-aligned float32)shard <tag>_n<container> per node Backend: gpu_vector, or cpu_vector if built with CLIO_ML_CPU=1one CTE blob per page, named by its index; a page cache in GPU or host memory
A fit is broadcast to every node, runs over local pages, and reduces in a fixed order.

Datasets are pages

A dataset is a page-aligned, row-major table of 32-bit floats stored in a memory-expansion vector. A page is the unit of work, and no row may straddle a page boundary, so the page must hold a whole number of rows; the dataset refuses a page size that does not. The vector is one CTE tag with one blob per page, named by the page's index. Data gets there through a host preload that writes every page, which is what the Python front end does, or through the CAE, which can serve page numbers over data it has ingested.

How a dataset is laid out

Python: ds = clio_ml.dataset(X, cache_pages=64) X: 1,000,000 rows × 8 float32 columns (32 B a row) · a 16 KiB page holds 512 whole rows · 4 blocks then clio_ml.fit_kmeans(ds, k=8, init_centroids=C); fit_kmeans(X) on a plain array runs in memory, no runtime preload: one blob put per page CTE tag clio_ml_py_0one tag per dataset; page blobs are named by index ("0" … "1953") and placed by the CTE like any blob pages 0 – 487block 0 · 488 pages pages 488 – 976block 1 · 489 pages pages 977 – 1464block 2 · 488 pages pages 1465 – 1953block 3 · 489 pages Block b owns pages [⌊b·N/4⌋, ⌊(b+1)·N/4⌋), N = 1954 pages: one contiguous run each. A row never straddles a page; the last page, 1953, holds the final 64 rows. fetch: whole pages, one MultiGet per block GPU 0 MEMORY Page cache: 4 sets × 16 frames (1 MiB) home set = hash(page number) mod 4, the same for every block, so a page that several blocks read is stored once set 0 set 1 set 2 set 3 filled: a resident page · dashed: a free frame Frame record (64 B) page number, valid element range pins: a pinned frame is never evicted score, last access: the victim is the lowest score, then the least recent fetching, flushing: a transfer is in flight, so the frame cannot be taken Resident, not paged centroids (k × 8) · each block's sums (k × 8) and counts (k) · row labels · one MultiGet and one MultiPut task per block
A worked example: a million 8-column rows become 1954 page blobs of one tag, and each of the 4 GPU blocks owns one contiguous run of them. The GPU holds only a 64-frame cache, far smaller than the 30 MiB dataset, so every pass is out of core. A page's cache set depends on the page, not on the block that asks for it, so the whole grid shares one copy.

One code path for GPU and CPU

The backend selects the GPU vector by default, or the CPU vector on host threads when the code is built with CLIO_ML_CPU=1. Both run the same per-row math in the same order, so a CPU fit and a GPU fit of one dataset agree to the bit wherever the host and device math libraries agree (operations that need it use exact exp/log routines).

One pass through the page cache

Host: FitKMeans, Lloyd iteration it = 0 … iters − 1 a fixed iteration count, no early stop · copy the centroids in · zero every block's sums and counts launch 4 blocks × 256 threads (YieldRunner) Kernel, block 1: for each of its pages 488 … 976 1 · CoFetch(page) find or claim a frame in the page's homeset and pin it; on a miss, evict the lowestscore, send a MultiGet, and park 2 · CoHoldPage a pointer to the frame's bytes;read-only, so the page stays clean 3 · FoldPage label each row with its nearest centroid,then one thread per (cluster, dim) addsthe rows in order into block 1's partial 4 · UnpinRange drop the pin; the page stays residentfor the next iteration until a fetchevicts it, with no write-back next page Runtime GPU worker pops the block's MultiGetoff the GPU-to-CPU queue;the CTE copies page blobs("488", …) into frames Yield driver (host) relaunches a parked blockonly when its fetch'scompletion word flips; itresumes where it parked Host, after every block finishes copy back 4 × (k × 8) sums and 4 × k counts · on a cluster, all-gather them, node 0's blocks first add blocks 0, 1, 2, 3 in that order · new centroid = sum ÷ count · start the next iteration Built with CLIO_ML_CPU=1 blocks run on host threads (CLIO_ML_CPU_THREADS, default every core) over a cpu_vector page cache in host RAM; the same fetch → hold → fold → unpin per page and the same block order, so the same sums
Each block walks its own pages through the shared cache: fetch and pin, hold, fold into a block-private partial, unpin. A block does not wait out a miss on the GPU: it parks, the runtime copies the page blob into its frame, and the host relaunches the block when that transfer completes. The host then sums the block partials in a fixed order, which is why eviction never changes the answer.

Deterministic reductions

Each GPU block computes its own partial result (sums, counts, gradients). Partials are combined in a fixed order instead of with global atomic adds. That is slightly more work, but it makes every run reproducible. A paged kernel that hits the yield driver's round cap throws instead of returning the result of a partly executed pass.

Each algorithm is a runtime module

Every algorithm (k-means, random forests, gradient boosting, PCA, LSTMs and more) is packaged as its own runtime module named clio_ml_<algo>_chimod. The modules share one container template; each algorithm adds only a short adapter that calls its fit function. Besides the standard create, destroy and monitor methods, each has a compute method that the client sends to every container at once with a broadcast query. Because it is an ordinary module, an algorithm is installed, composed and monitored like any other.

Training across a cluster

Each container opens its own shard of the dataset, named <tag>_n<container id>. Per-block partials are gathered from all nodes in node order, so a fit across N nodes is bit-identical to a single-node fit with N times as many blocks. When results come back, one model is kept and any replica that disagrees is flagged, which catches nondeterminism bugs.

Tradeoffs

ChoiceGainCost
Ordered reductionsReproducible, bit-identical results across CPU, GPU and node countsSlower than atomic accumulation
Page-aligned float32 rowsSimple, cache-friendly work unitsData must be float32, with a page size that holds whole rows
One module per algorithmEnable only the algorithms you useEach enabled module is loaded by the runtime