Tree-Ordered Tensor-Train Classifiers for Millions of Labels

When a classifier must choose among millions of labels, such as products in a catalog or keywords for a paper, its final layer dominates the cost of training. That layer is one weight vector per label, a matrix with $C$ rows (one per label) and $d$ columns (the size of the input representation). The Adam optimizer then stores two more numbers per weight, so the layer exhausts GPU memory long before the backbone network does. Existing fixes keep that $C \times d$ matrix and shrink it: they store it in 8-bit floats, prune it to a sparse pattern, or hash labels into buckets. We propose a different move, taken from how physicists simulate quantum systems that are far too large to store. A quantum state over $n$ qubits has $2^n$ numbers, but if it is only weakly "entangled" it can be written as a chain of small tensors, a tensor train, whose size grows with $n$ rather than $2^n$. We write each label's index as a short sequence of digits given by its path in a label hierarchy. The classifier matrix then becomes a tensor over those digits, and we store it as a tensor train. Its parameters, and the Adam states attached to them, grow with $\log C$ instead of $C$.

The bet is not that tensor trains are new; it is about ordering. A tensor train compresses well only if the data has little correlation across each cut of the digit sequence, just as a quantum simulation compresses only if entanglement across each cut of the qubit chain is low. Our hypothesis is that label weights indexed by a semantic tree have this property, while label weights indexed arbitrarily or by random hashing do not. If it holds, the whole tail classifier fits in a GPU's on-chip cache. The tree structure also pulls rare labels toward their parent clusters, which may help rare-label accuracy rather than hurt it. The proposal makes this measurable before anything is trained, using the same singular-value diagnostic physicists use to choose how large the tensor-train factors must be.

Core Claim

Write label $c$ as digits $(i_1, \dots, i_K)$, where $i_k \in \{1,\dots,n_k\}$ is the branch taken at level $k$ of a balanced label tree and $C \le \prod_k n_k$. The logit for label $c$ given representation $h \in \mathbb{R}^d$ is

$$ s_c(h) = \big(h^\top A_1[i_1]\big)\, G_2[i_2]\, G_3[i_3] \cdots G_K[i_K], $$

where $A_1[i_1]$ is a $d \times \chi$ matrix, each $G_k[i_k]$ is a $\chi \times \chi$ matrix (the last is $\chi \times 1$), and $\chi$, the bond dimension, controls how much variation the chain can express. The parameter count is about $d\, n_1 \chi + \sum_{k \ge 2} n_k \chi^2$. For Amazon-3M with $K=6$, $n_k \approx 12$, $d = 768$ and $\chi = 256$, this is roughly seven million weights, against about 2.3 billion for the dense layer. That is small enough that the weights plus Adam states fit in the 40 MB L2 cache of an A100. The claim has three parts. First, the precision this layer can reach is governed by the singular-value decay of the dense weight matrix reshaped along tree-level cuts, which is the classical analogue of entanglement entropy. Second, tree ordering produces fast decay and random ordering does not. Third, a tree-ordered tensor train, plus a small dense head for the most frequent labels, sits on a better memory–precision curve than 8-bit dense or group-sparse layers for $C \ge 10^6$.

Relation to Prior Work

Three lines of extreme-classification work attack the memory of the output layer while keeping one row per label. Towards Memory-Efficient Training for Extremely Large Output Spaces prunes the layer to a fixed number of inputs per label and cuts Amazon-670K memory from 13.4 to 1.4 GiB. It also motivates this proposal by showing that Adam states, not the backbone, cause the out-of-memory failures. HASTE groups semantically similar labels into tiles that share a sparsity pattern so the GPU can use dense matrix units, and it reaches 12.5 GiB versus 105.6 GiB dense on LF-Paper2Keywords-8.6M. ELMO stores weights in 8-bit floats with stochastic rounding and processes the layer in chunks, needing 6.6 GiB versus Renee's 39.7 GiB on Amazon-3M. All three still scale linearly in $C$. We replace the per-label row with shared factors, and we reuse two of their ingredients as method: HASTE's split between a dense head and a compressed tail, and ELMO's chunked logit computation for training.

MACH is the one prior method with logarithmic memory. It hashes labels randomly into buckets across $O(\log K)$ small classifiers. It constrains our design in two ways. It shows that log-memory classification can work at 50M labels, and its random hashing is exactly the structure-free ordering we predict will compress poorly in a tensor train, which makes it a natural contrast. XR-Transformer supplies the label tree: it builds a hierarchical clustering of labels and fine-tunes coarse-to-fine. It uses the tree to schedule training, whereas we use it to define the factor structure of the final layer.

From quantum simulation, Vallero et al. document that GPU throughput collapses once working data exceeds L1 or L2 cache, and that tensor-network cost is governed by bond dimension. This motivates the cache-fit target. AQCtensor shows that optimizing tensor-network parameters directly from a global objective suffers vanishing gradients, and that initializing from a structured solution fixes this. That constrains our training recipe: we initialize the cores from a compressed solution rather than at random. Shang et al. document the negative case, in which bond dimension blows up for highly entangled systems. That is the failure mode we test for directly. We do not borrow from BMQSim. Its compress-and-spill-to-SSD design attacks a wall that ELMO already moves past for classifiers, since ELMO fits 18M labels on one 24 GiB GPU.

Research Program

Diagnostic stage. The first stage asks whether the needed structure exists, before any new training code is written. We train dense classifiers, or take ELMO-trained ones, on Amazon-670K, Wiki-500K and Amazon-3M. We then reshape each weight matrix into a tensor indexed by $(d, i_1, \dots, i_K)$ under three label orderings: XR-Transformer-style balanced hierarchical clustering of label embeddings, random permutation, and frequency order. Successive singular value decompositions, the classical analogue of the step physicists use to truncate a quantum state, give the spectrum at every cut. From these spectra we compute an entropy per cut and the smallest $\chi$ that keeps 90, 95 and 99 percent of the matrix's energy. We also score retained precision@k directly when we swap in the truncated matrix. This stage alone produces a publishable negative or positive result.

Training stage. The second stage trains the layer end to end with a pretrained text encoder. Logits for all labels are computed by walking the tree level by level. Partial products are shared across siblings, so a full pass costs about $C\chi$ multiply-adds and never materializes per-label weights. Training uses ELMO-style chunks over leaves with a squared-hinge or binary cross-entropy loss. Cores are initialized from the truncated decomposition of a cheap solution, namely label-centroid vectors of encoder features, following AQCtensor's lesson about initialization. The most frequent few thousand labels get an ordinary dense head, as in HASTE. A lightweight kernel keeps the cores resident in shared memory and L2 cache. We sweep $\chi$, tree branching factor, and depth.

Tail analysis. The third stage studies rare labels specifically, using propensity-scored precision, the standard tail-weighted metric. The question is whether tree-sharing acts as useful pooling for rare labels or erases their distinctions.

Baselines

The naive reference is the dense full-precision classifier trained with Adam, the configuration that motivates all of this work. We run it where it fits, on Amazon-670K and Wiki-500K, and report the out-of-memory point elsewhere.

The strongest existing memory competitor is ELMO, with 8-bit weights, chunking and fused updates, run from its released recipe on the same encoder, data and epoch budget. On Amazon-3M the file reports 6.6 GiB peak memory for ELMO versus 39.7 GiB for Renee. No reported precision@1 for ELMO was found on Lacuna, so we will rerun it. Beating it means matching its precision@1 within one point at five times or more lower classifier memory, or exceeding it at equal memory.

HASTE is the strongest structured-sparsity competitor, run at group sizes 32 and 64 with its head–tail split. The reference point is its reported 12.5 GiB on LF-Paper2Keywords-8.6M. For accuracy the reference is XR-Transformer's reported 54.2 percent precision@1 on Amazon-3M. That figure reflects a different encoder and much more compute, so we treat it as a ceiling, not a target for a matched comparison.

MACH is run with matched parameter count as the existing log-memory method. A plain low-rank factorization $W = UV^\top$ with matched memory is run as the obvious simpler compression.

Two ablations isolate the key ingredient. The first is the same tensor train with random label ordering, which tests whether the tree is what makes compression work. The second removes the dense head, which tests whether frequent labels need their own capacity.

All methods share the encoder checkpoint, tokenization, data splits, a fixed GPU-hour budget per dataset, and an equal hyperparameter search of 20 trials each. Memory is measured as peak classifier memory, including optimizer states, on the same A100.

Why not just…?

Why not just use ELMO, since it already fits 18 million labels on one GPU? This is the real threat. If memory were the only goal, ELMO's 8-bit dense layer would be good enough at today's dataset sizes. Our case rests on two things ELMO cannot give: memory that grows with $\log C$, so the whole tail fits in cache and the approach extends to 50M+ catalogs or many models per GPU, and possible gains on rare labels from tree pooling. If the matched-memory comparison shows ELMO dominating at every point on the curve, the proposal fails, and we will report that.

Why not just use a low-rank factorization $W = UV^\top$? Its memory is $(C + d)r$, still linear in $C$. At equal memory to a tensor train on Amazon-3M, $r$ would be around two, which should destroy precision. The matched-memory low-rank baseline settles this empirically. The diagnostic stage also shows whether the matrix's overall rank is high while its tree-cut ranks are low, which is the structural reason the tensor train should win.

Why not just use MACH's hashing for log memory? MACH discards label semantics. The file also notes that MACH's inference aggregates $R$ classifiers over all $K$ labels. Our random-order ablation is effectively a structure-free control, and running MACH itself at matched size shows directly whether semantic ordering buys precision.

Why not just use XR-Transformer's tree for training? XR-Transformer uses the tree to schedule fine-tuning but still ends with large per-label weights. Our question is whether the same tree can replace those weights entirely, so the two approaches are complementary rather than redundant.

Decisive Checks

The first go/no-go test comes from the diagnostic stage. On Amazon-670K, tree-ordered truncation at $\chi \le 256$ must keep precision@1 within two points of the dense matrix. Random ordering at the same $\chi$ must lose clearly more. If neither condition holds, we stop and publish the spectra as a negative result about label structure.

The second test is the trained memory–precision curve on Amazon-3M and LF-Paper2Keywords-8.6M. We plot precision@1, precision@5 and propensity-scored precision@5 against peak classifier memory for the tensor train, ELMO, HASTE, MACH and low-rank. The proposal succeeds if the tensor train occupies the low-memory end of that curve without falling more than one to two points below ELMO.

The third test asks whether tail-label propensity-scored precision rises or falls relative to the dense model. This answers whether sharing along the tree pools evidence for rare labels or blurs them together.