\section{Algorithms} \label{sec:algorithms} \begin{algorithm}[t] \caption{Decode step of one MoE layer in \titan{} (single node)} \label{alg:layer} \begin{algorithmic}[1] \Require hidden rows $X$, router indices $I$ ($R \times K$), slot table $\mathcal{S}_l$, prefetcher $\mathcal{P}$, depth $d$ \If{$\mathcal{S}_l$ holds every expert} \State \Return $\gatherqmm(X, \mathcal{S}_l, \mathrm{slotmap}[I])$ \Comment{no host sync} \EndIf \State $U \gets$ unique experts of $I$ (host) \Comment{the unavoidable synchronisation} \State $\mathcal{P}.\textsc{drain}(l, U)$ \Comment{install finished prefetches; wait for in-flight experts in $U$ (late)} \State $\hat S \gets \mathcal{P}.\textsc{predict}(l + d)$; $\mathcal{P}.\textsc{issue}(l + d, \hat S)$ \Comment{before this layer's compute} \State $M \gets U \setminus \mathrm{resident}(\mathcal{S}_l)$; read $M$ from the store as a batch; install into slots (lazy) \State $J \gets \mathrm{slot}(I)$ \State \Return $\gatherqmm(X, \mathcal{S}_l, J)$ \Comment{same kernel, same bytes as mlx-lm} \end{algorithmic} \end{algorithm} \begin{algorithm}[t] \caption{Deterministic cost-aware placement (Gate F heuristic)} \label{alg:placement} \begin{algorithmic}[1] \Require expert popularity $\pi_e$ from fit traces, node costs $(c_n, M_n, \rho_{0n})$, expert size $b$ \State sort experts by $\pi_e$ descending; $\mathrm{free}_n \gets M_n$ \For{each expert $e$ in that order} \State $n^\star \gets \arg\min_{n:\ \mathrm{free}_n \ge b} \big(c_n + \ind[n \ne 0]\,\rho_{0n}\big) \cdot \pi_e$ \Comment{expected per-step cost} \State place $e$ on $n^\star$; $\mathrm{free}_{n^\star} \gets \mathrm{free}_{n^\star} - b$ \EndFor \State replicate the $\rho$ most popular experts on node $0$ if $\mathrm{free}_0$ allows (hot set) \State experts placed nowhere fall back to node $0$'s slot table (SSD tier, demand loading) \end{algorithmic} \end{algorithm} Algorithm~\ref{alg:layer} is the per-layer path of Section~\ref{sec:architecture}; the prefetch for layer $l+d$ is issued \emph{before} the current layer's kernels are dispatched so that the reader threads overlap the GPU work of the next $d$ layers. Algorithm~\ref{alg:placement} is the first placement heuristic: greedy by popularity, cost-aware by node, with replication of a hot set on the coordinator. It runs in $\mathcal{O}(LE \log LE + LE N)$ time, negligible against inference, and will be the static baseline against which the adaptive scheduler (online re-estimation of $\pi$ and of the node costs) is compared. Predictor fitting is $\mathcal{O}(T L K^2)$ for transition counts and one logistic regression per layer for the probe.