---
title: Compact Gated Linear Unit (CGLU)
url: https://www.emergentmind.com/topics/compact-gated-linear-unit-cglu
type: topic
---

# Compact Gated Linear Unit (CGLU)

Searching arXiv for the cited papers to ground the article in current records.
arXiv search: "Decoupling Gating from Linearity" and "Masked Gated Linear Unit"
Compact Gated Linear Unit (CGLU) is an *Editor’s term* for compact parameterizations of gated linear units that preserve multiplicative gating while reducing parameter count, storage, or memory traffic. Two distinct but related research lines motivate the term. In the first, the Gated Linear Unit (GaLU) decouples the gating vector from the linear predictor, fixes the gate after random initialization, and thereby converts one-hidden-layer training into convex linear regression on a random feature map [1906.05032]. In the second, the Masked Gated Linear Unit (MGLU) replaces the two projection matrices of a standard GLU with one shared matrix plus complementary binary masks, yielding a compact GLU implementation for large language model feed-forward networks [2506.23225]. Taken together, these lines define CGLU as a family of architectures in which gating and value computation remain multiplicative, but compactness is achieved either by decoupling-and-sharing in function space or by mask-based sharing in parameter space.

## 1. Conceptual definition and formal forms

A standard ReLU neuron can be written as
\[
\sigma(w^\top x) = (w^\top x)\,\mathbf{1}\{w^\top x \ge 0\},
\]
which exposes it as the product of a linear term and a hard gate controlled by the same vector \(w\). GaLU separates these two roles by assigning different vectors \(u,v \in \mathbb{R}^d\):
\[
g_{u,v}(x) \;=\; (v^\top x)\,\mathbf{1}\{u^\top x \ge 0\}.
\]
Under the hard gate, \(\nabla_u g_{u,v}(x)=0\) almost everywhere, so the gate parameter \(u\) is fixed after random initialization, typically \(u \sim N(0,I_d)\), and training updates only the linear part \(v\) [1906.05032].

For transformer feed-forward networks, a standard GLU is written in the MGLU formulation as
\[
\mathrm{GLU}(x) = g(x W_g) \odot (x W_v),
\]
with separate gate and value matrices. MGLU makes this compact by introducing one shared weight matrix \(W\) and a binary mask \(M\):
\[
\mathrm{MGLU}_1(x) = g(x (M \odot W)) \odot (x (\bar M \odot W)).
\]
Here \(\bar M = 1-M\), so the shared matrix is partitioned into complementary gate and value subspaces. The source paper does not use the term CGLU, but this single-mask construction is explicitly identified as a compact GLU instantiation [2506.23225].

A useful synthesis is that CGLU preserves the defining GLU operation—elementwise multiplication of a gate stream and a value stream—while compactness is induced by one of two mechanisms: fixed random gates plus reduced trainable structure, or shared weights plus learned binary partitions.

| Variant | Core form | Compactness mechanism |
|---|---|---|
| ReLU | \((w^\top x)\mathbf{1}\{w^\top x \ge 0\}\) | None |
| GaLU | \((v^\top x)\mathbf{1}\{u^\top x \ge 0\}\) | Decoupled gate/value |
| Single-mask MGLU | \(g(x(M\odot W))\odot(x(\bar M\odot W))\) | Shared matrix + mask |

## 2. GaLU as the theoretical foundation for compact hard-gated units

A one-hidden-layer GaLU network with \(k\) hidden units and scalar output is
\[
f(x) \;=\; \sum_{i=1}^k \alpha_i\,(v_i^\top x)\,\mathbf{1}\{u_i^\top x \ge 0\}.
\]
Because the model is linear in \(v_i\), one may absorb the output weights into \(\tilde v_i=\alpha_i v_i\) and rewrite the network as
\[
f(x)=\Phi_u(x)^\top w,
\]
where \(w=[\tilde v_1;\ldots;\tilde v_k]\in\mathbb{R}^{kd}\) and
\[
\Phi_u(x) \;=\; \frac{1}{\sqrt{k}}
\begin{bmatrix}
\mathbf{1}\{u_1^\top x \ge 0\}\,x\\
\mathbf{1}\{u_2^\top x \ge 0\}\,x\\
\vdots\\
\mathbf{1}\{u_k^\top x \ge 0\}\,x
\end{bmatrix}.
\]
Training therefore reduces to linear regression on a random feature map with fixed gates [1906.05032].

For a sample \(S=\{(x_i,y_i)\}_{i=1}^m\), the associated block design matrix is
\[
\bar{X}=\big[\bar{X}^{(1)}\;\bar{X}^{(2)}\;\cdots\;\bar{X}^{(k)}\big]\in\mathbb{R}^{m\times kd},
\quad
\bar{X}^{(j)}(i,:)=\mathbf{1}\{u_j^\top x_i\ge 0\}\,x_i^\top.
\]
Optimization becomes the convex problem \(\min_w \|\bar X w-y\|^2\). The key data-dependent quantity is
\[
\lambda(X)=\lambda_{\min}\!\left(\frac{1}{k}\,\mathbb{E}\big[\bar X\bar X^\top\big]\right),
\]
assumed positive. Under this assumption, if
\[
k \;\ge\; \frac{8\,\|X\|^2}{\lambda(X)}\,\log\!\left(\frac{m}{\delta}\right),
\]
then with probability at least \(1-\delta\),
\[
\sigma_{\min}(\bar X)^2 \;\ge\; \frac{k}{2}\,\lambda(X),
\]
which implies full row rank and zero training loss by linear regression.

For random Gaussian or spherical data, the bounds sharpen. When \(x_i\) are i.i.d. on the unit sphere \(S^{d-1}\) and \(d \le m \le c_2 d^2\), there exist absolute constants \(c_1,c_2,\gamma_1,\gamma_2>0\) such that
\[
k \;\ge\; \frac{64\pi}{c_1^2}\,\frac{m}{d}\,\log\!\left(\frac{m}{\delta}\right)
\]
implies
\[
\sigma_{\min}(\bar X) \;\ge\; \frac{\sqrt{k}\,c_1}{\sqrt{4\pi}} \;>\; 0
\]
with the stated high probability. This yields memorization at width \(n=k=\tilde{\Omega}(m/d)\), improving on the cited ReLU theory requiring \(n=\tilde{\Omega}(m^2/d)\) under bounded derivatives [1906.05032].

The same rank perspective also characterizes the under-parameterized regime. When labels are i.i.d. \(N(0,1)\),
\[
\mathbb{E}\Big[\min_w L_S(w)\Big] \;=\; 1-\frac{\mathrm{rank}(\bar X)}{m}.
\]
When \(kd \ll m\), \(\mathrm{rank}(\bar X)\approx kd\), so the loss behaves like \(1-kd/m\). This makes explicit that the effective capacity is governed by the rank of the gated design matrix rather than by nominal width alone.

## 3. Optimization, kernel structure, and relation to ReLU

Because the GaLU reparameterization is linear in \(w\), training with squared loss has a convex landscape. If \(\lambda(X)>0\), \(\delta,\epsilon>0\), and
\[
k \ge \frac{8 \|X\|^2}{\lambda(X)}\log\!\left(\frac{m}{\delta}\right),
\qquad
\eta = \frac{m}{k\,\|X\|^2},
\]
then after
\[
t \;\ge\; \frac{2\,\|X\|^2}{\lambda(X)}\,\log\!\left(\frac{k\,\|X\|^2\,\|w_0-w^*\|^2}{m\,\epsilon}\right)
\]
iterations of gradient descent, the squared loss is at most \(\epsilon\) with probability at least \(1-\delta\). The argument uses convexity together with spectral control of \(\bar X\bar X^\top\) [1906.05032].

The corresponding normalized GaLU network induces the kernel
\[
\kappa(x,x')
=
\mathbb{E}_{u\sim N(0,I_d)}
\big[
\mathbf{1}\{u^\top x\ge 0\}\mathbf{1}\{u^\top x'\ge 0\}\langle x,x'\rangle
\big]
=
\left(
\frac{1}{2}
-
\frac{\arccos(\langle x,x'\rangle)}{2\pi}
\right)\langle x,x'\rangle.
\]
The random features \(\Phi_u(x)\) approximate this kernel in expectation. If the data distribution is realizable by some \(f^* \in B_\kappa(M)\), where \(B_\kappa(M)=\{f\in H_\kappa:\|f\|_\kappa\le M\}\), and if
\[
k \;\ge\; \left(\frac{m}{M^2\,\lambda(X)}+1\right)^2
\frac{32\,\|X\|^4}{\lambda(X)^2}\,
\log\!\left(\frac{m}{\delta}\right),
\]
then with probability at least \(1-2\delta\), the empirical risk minimizer satisfies
\[
L_{\mathcal D}(\hat f)
\;\le\;
C\,
\frac{2M^2\log^3 m + (2M^2+\sqrt{2}M)\log(1/\delta)}{m}.
\]
Under the realizability assumption and fixed gates, this gives an \(O(1/m)\) decay rate rather than the \(O(1/\sqrt m)\) rate emphasized in the comparison to cited ReLU analyses [1906.05032].

The relation to ReLU is subtle. At initialization, under hinge loss and bounded outputs, small gradient at initialization occurs with the same probability for GaLU and ReLU:
\[
\left\|\frac{\partial}{\partial v}L_S(\mathcal N^{G}_{U,V,\alpha})\right\|\le \epsilon
\;\text{w.p. }1-\delta
\Longleftrightarrow
\left\|\frac{\partial}{\partial w}L_S(\mathcal N^{R}_{W,\alpha})\right\|\le \epsilon
\;\text{w.p. }1-\delta.
\]
This aligns failure modes such as parity failure across the two models. A further result states that when ReLU training remains within \(\|w_i-u_i\|\le \epsilon\) of initialization—the “lazy training” regime—the fixed-gate GaLU is competitive with the trained ReLU. A plausible implication is that decoupled hard-gated models can capture a meaningful subset of ReLU behavior precisely when ReLU learning is dominated by a nearly fixed gating pattern.

## 4. Compact GaLU: proposed constructions and design rules

Within the GaLU line, a Compact GaLU (CGLU) is proposed by imposing parameter sharing or low-rank structure while keeping decoupled gating and linear prediction. One formal proposal is
\[
g^{\text{C}}_{u,v}(x)
=
\big((Br)^\top x\big)\,\mathbf{1}\{(Sq)^\top x \ge 0\},
\]
where \(B\in\mathbb{R}^{d\times p}\) and \(S\in\mathbb{R}^{d\times p_u}\) are shared bases, \(r\in\mathbb{R}^p\) is a per-neuron linear code, and \(q\in\mathbb{R}^{p_u}\) is a per-neuron gate code. The associated one-hidden-layer network is
\[
f_{\text{CGLU}}(x)
=
\sum_{i=1}^k
\big(r_i^\top B^\top x\big)\,
\mathbf{1}\{q_i^\top S^\top x \ge 0\}.
\]
If \(B\) is fixed, training in \(r_i\) remains convex; if \(B\) is trained, the problem becomes bi-linear. This compactifies the trainable linear part from \(O(kd)\) to \(O(dp+kp)\), with gate storage \(O(dp_u+kp_u)\) if gates are stored [1906.05032].

Three concrete compactification mechanisms are described.

First, **gate sharing** introduces a dictionary \(U=[u_1,\ldots,u_{k_g}]\) with \(k_g \ll k\) and reuses gates across neurons:
\[
f_{\text{CGLU}}(x)
=
\sum_{i=1}^{k}
(v_i^\top x)\,\mathbf{1}\{u_{g(i)}^\top x \ge 0\}.
\]
This reduces gate storage to \(k_g d\). However, duplicating gates does not increase \(\mathrm{rank}(\bar X)\), so memorization still requires sufficiently many distinct gates.

Second, **low-rank linear predictors** write \(v_i=Br_i\) with \(B\in\mathbb{R}^{d\times p}\), \(p\ll d\). The effective design matrix becomes \(\bar X B\in\mathbb{R}^{m\times kp}\), whose rank is at most \(kp\). Exact memorization therefore requires \(kp\ge m\), equivalently width \(k\gtrsim m/p\).

Third, **gate compression** writes \(u_i=S r_i^{(u)}\) with \(S\in\mathbb{R}^{d\times p_u}\), \(p_u\ll d\), and fixed random \(r_i^{(u)}\). This reduces gate storage but also reduces gate diversity. The synthesis notes that one should choose \(S\) so that the induced gate kernel maintains \(\lambda(X)\) bounded, for example by using a near-isometry on the data manifold.

These constructions lead to a compact design rule: because the achievable training loss depends on \(\mathrm{rank}(\bar X)\), a compact model with \(k_g\) distinct gates and per-unit linear dimension \(p\) should satisfy \(k_g p \gtrsim m\) to retain zero-loss memorization capacity. This is an inference from the rank analysis rather than a theorem stated in the original 2019 paper, but it follows directly from the stated bound \(\mathrm{rank}(\bar X)\lesssim k_g p\) and the exact-loss characterization.

## 5. Masked compact GLUs in transformer feed-forward networks

In the transformer setting, compactness is framed differently. A standard GLU up-projection uses two FP16 matrices \(W_g,W_v \in \mathbb{R}^{h\times d}\):
\[
\mathrm{GLU}(x)=g(xW_g)\odot(xW_v).
\]
The MGLU construction replaces these with a single shared matrix \(W\in\mathbb{R}^{h\times d}\) and one or more learned binary masks. The single-mask case,
\[
\mathrm{MGLU}_1(x)=g(x(M\odot W))\odot(x(\bar M\odot W)),
\]
is the minimal compact GLU. To increase expressiveness, MGLU introduces a Mixture of Element-wise Gating (MoEG) with multiple masks:
\[
\mathrm{MGLU}_{n_m}(x)
=
\sum_{i=1}^{n_m}
\big[
g(x(M_i\odot W))\odot(x(\bar M_i\odot W))
\big].
\]
Each route \((M_i,\bar M_i)\) induces a different gate/value partition while still using one shared FP16 matrix [2506.23225].

The compactness advantage is explicit in the memory accounting. For the up-projection at inference, a standard GLU reads \(32hd\) bits per token, whereas MGLU with \(n_m\) masks reads \((16+n_m)hd\) bits. At \(n_m=1\), the reduction is
\[
\frac{32hd-(16hd+hd)}{32hd}
=
\frac{15}{32}
\approx 0.46875,
\]
that is, 47% fewer bits transferred. The paper further notes that MGLU still breaks even with GLU up to \(n_m=16\) at FP16 inference. For Llama-1B with \(h=2048\) and \(d=8192\), the FFN up-projection weights per layer shrink from 96 MB to 64 MB, and one 1-bit mask adds approximately 2 MB for \(n_m=1\) [2506.23225].

Parameter counts also change materially. A GLU up-projection has \(2hd\) FP16 parameters. MGLU uses \(hd\) FP16 weights plus \(n_m hd\) mask bits at inference; during training, the masks are maintained as FP16 logits, adding \(n_m hd\) trainable FP16 parameters. Mask learning is performed through the straight-through estimator: the mask is thresholded to binary in the forward pass, while the backward pass treats the binarization as identity.

The compute trade-off is asymmetric between inference and training. For next-token inference, SwiMGLU incurs \(2(1+n_m)hd\) multiply-adds per token, versus \(6hd\) for SwiGLU. Because low-batch decoding is memory-bound, the reduction in FP16 reads dominates latency. During training, however, the reported cost is approximately \((6+8n_m)hd\) per token for SwiMGLU versus \(18hd\) for SwiGLU, so large \(n_m\) can increase compute cost even as weight storage is reduced.

A central misconception is that compact GLU is equivalent to naive weight tying. The MGLU study explicitly reports that setting \(W_g=W_v\) in SwiGLU severely hurts perplexity, to 27.0 relative to 23.6 for SwiGLU, whereas masked sharing preserves multiplicative capacity with one shared \(W\). Compactness therefore comes not from simple equality constraints, but from structured partitioning of a shared weight tensor.

## 6. Kernel implementation, empirical behavior, and limitations

The efficiency of masked compact GLUs depends on kernel design. A naive MGLU implementation would launch \(2n_m\) masked matrix-vector products and repeatedly reload \(W\), remaining memory-bound. FlashMGLU instead fuses these operations so that each weight is touched once. The reported implementation uses bit-packing of the \(n_m\) mask flags into a single 8-bit integer, single shared loading of \(W\) and mask words per tile, complementary masks to recover value sums from an unmasked total \(t\) and masked partial sums \(s_i\), Split-K tiling with on-chip accumulation, and fused arithmetic in registers. After reduction, the kernel writes gate sums \(s_i\) and value sums \(t-s_i\), after which the activation and elementwise multiplication are applied route-wise [2506.23225].

On an RTX 5090 GPU in FP16, FlashMGLU achieves up to a 19.66\(\times\) speed-up over a naive PyTorch MGLU at \(n_m=8, h=8192, d=2048\), reducing latency from 0.5210 ms to 0.0265 ms. Relative to standard PyTorch GLU, it is up to 1.51\(\times\) faster in the \(n_m=1\) case and remains at least 1.24\(\times\) faster for larger shapes. The abstract summarizes the result as 47% more memory-efficient and 34% faster than standard GLUs on an RTX5090 GPU. With four masks and Swish, the paper also reports a 29.1% reduction in projection-layer compute and 37.5% lower memory usage during inference, while matching or surpassing SwiGLU accuracy.

Model-level evaluations use Llama-style decoder-only architectures on FineWeb-Edu, with zero-shot and two-shot accuracy on ARC-E, ARC-C, HellaSwag, PiQA, SciQ, and Winogrande, together with validation perplexity. At the small scale, SwiGLU has 141M weights, whereas SwiMGLU has 113M weights plus mask bits; zero-shot averages are 46.20% for SwiGLU, 46.48% for SwiMGLU with \(n_m=4\), and 46.49% with \(n_m=8\). Validation perplexity improves from 25.0 at \(n_m=1\) to 23.5 at \(n_m=8\), close to SwiGLU’s 23.7. At the large scale, the baseline SwiGLU has 1.08B weights and SwiMGLU has 808M weights plus mask bits; zero-shot average improves from 56.00% to 56.85% at \(n_m=4\), and two-shot average improves from 57.36% to 57.87% [2506.23225].

The empirical picture across the two source lines is internally consistent but not identical. In the GaLU experiments, minimal width \(k \approx m/d\) suffices for both GaLU and ReLU to reach MSE \(<0.01\), GaLU loss follows \(1-kd/m\) in the under-parameterized regime, and parity is failed by both models. On linearly separable data in \(\mathbb{R}^{100}\), on MNIST, and on Fashion-MNIST, both GaLU and ReLU perform well, with ReLU slightly better. In the MGLU experiments, compact masked sharing is competitive or superior to dense SwiGLU, especially for \(n_m=4\) to \(8\). This suggests that “compactness” is not a single phenomenon: in hard-gated shallow models it refers to reduced trainable dimensionality under fixed random gates, whereas in LLM feed-forward blocks it refers to reduced memory traffic through shared weights and learned mask partitions.

Several limitations recur. The GaLU theory is restricted to one-hidden-layer networks with scalar outputs, hard binary gates \(\mathbf{1}\{u^\top x\ge 0\}\), fixed Gaussian-initialized gates, and realizability assumptions for the RKHS result. Deeper GaLU networks, vector-valued outputs, and soft gates are not analyzed, and soft gates would break the hard-gate convex reduction. In compact GaLU variants, sharing or compressing gates can reduce diversity, so one must preserve enough distinct halfspaces to keep \(\lambda(X)\) bounded and \(\mathrm{rank}(\bar X)\ge m\). In MGLU, mask learning is discrete and depends on the straight-through estimator; training cost rises with \(n_m\), and the strongest kernel optimizations are implemented for CUDA GPUs. The masked models also exhibit diminishing returns beyond \(n_m=4\) to \(8\), so maximum compactness at \(n_m=1\) and maximum accuracy need not coincide.

In sum, CGLU denotes a compact gating principle rather than a single canonical architecture. In the GaLU formulation, compactness arises from decoupling gating from linearity and imposing shared or low-rank structure on the trainable linear component, producing convex optimization, rank-based memorization guarantees, and kernel-style generalization [1906.05032]. In the MGLU formulation, compactness arises from collapsing the two GLU matrices into one shared matrix plus complementary masks, producing substantial memory-bandwidth savings and hardware-efficient inference without sacrificing downstream accuracy [2506.23225].

Source: https://www.emergentmind.com/topics/compact-gated-linear-unit-cglu