WorksComputer Science
Non-Expanding Gated Continued Fraction Architecture for Feedforward Layers in Language Models
Abstract
Recent work has shown that continued fraction inspired neural architectures (CoFrGeNets) can be highly parameter efficient yet performant for language modeling. In this work, we revisit continued fraction-based channel mixing with the goal of improving its performance and simplifying integration into standard pre-training protocols for language models. We achieve this by two simple yet critical contributions: i) we propose a novel non-expanding gated continued fraction inspired architectural component to replace feedforward layers in established language model architectures that may use vanilla multilayer perceptrons or gated linear units or (vanilla/gated) experts in mixture-of-experts (MoE) type architectures. ii) We propose a way to re-implement divisions – the non-linearity in these architectures – in terms of logarithms and exponentials. By experimenting on different language modeling architectures such as GPT-2, Llama-3, Mamba-2 and (nano) Llama-MoE we find that our proposed architecture performs similarly or significantly better than the continued fraction architecture proposed in prior work along with having higher throughput. In addition, our re-implementation of divisions makes training of deeper CoFrGeNets stable without the need for incremental training which was proposed in prior work as a means to stabilize training, but added notable complexity to existing large language model training implementations. Code is available at http://github.com/IBM/CoFrNets
Introduction
Large Language Models (LLMs) have taken the world by storm [38, 19] revolutionizing how tasks such as web search, writing, coding, planning and even research are being done. A few neural architectures seem to be lying at the core of these advancements. Transformers [46] are arguably the most leveraged architecture appearing in many popular models such as in Generative Pre-trained Transformers (GPTs) [37], Llama [18] and even in the mixture-of-experts type of architectures [9] which are in vogue currently. State space architectures such as Mamba [19] have gained popularity given that they are more efficient than Transformers especially over long sequences. Diffusion models [40] which leverage Transformers are also gaining traction given their ability to generate sequences in parallel as opposed to auto-regressively. A major and the most parameter heavy component of these architectures is the feedforward network (FFN) which consists of a 2-layer perceptron with the hidden state being expanded by a factor of two or more over the input or embedding dimension. Large number of parameters implies slow and expensive training and inference with a large carbon footprint. Hence, having alternatives that are parameter efficient yet performant is a highly sought after goal [43].
Recently, a new architecture inspired by the mathematical concept of continued fractions CoFrGeNets [14] was proposed for language generation. The main contribution was proposing readily pluggable components for attention and FFNs in transformers that are parameter efficient. Replacing FFNs in dense Transformer models such as GPT2 and Llama led to models that were roughly the size, while replacing both attention and FFNs led to roughly the size with some degradation in performance. A continued fraction can be written as (ladder like structure) where, s are complex numbers. In the recent CoFrGeNets and the original CoFrNets [36], which was introduced for supervised settings, the s were replaced by linear functions of the input by taking the inner product of with weight vector in each layer .1 The reciprocal of the function thus far is applied as a nonlinearity in each layer leading to the following kind of form for a single ladder:
The s are parameters that can be learned. Here, the input gets multiplied by the parameter vector in each layer with the non-linearity being a reciprocal. This simplistic architecture has nice properties including universal approximability when enough ladders are ensembled together [36].
In this work, inspired by CoFrGeNets and motivated by the need to have parameter efficient yet performant alternatives to FFNs which contributes the most to model size, we propose a novel non-expanding, gated continued fraction inspired architectural component to replace FFNs. The resulting module can be used as a drop-in replacement for FFNs in standard MLP, GLU, and MoE settings, enabling direct integration into architectures such as GPT-2, Llama-style models, and state-space models. This new variant can have slightly more number of parameters than the component proposed in [14], due to the inclusion of the non-expanding gating, but having similar or significantly better performance across models. Additionally, our variant also has higher throughput, a consequence of improved arithmetic intensity.
One challenge with training continued fraction architectures is that deep ladders can result in slow training and inference as well as training instabilities due to reciprocal calculations. To address the former, in [14] a ladder was cast in terms of continuants –a mathematically equivalent formulation (see § 3)– which reduced the number of divisions from to for a depth ladder. However, training instabilities persisted for deep ladders (i.e. ) for which the authors introduced an incremental training protocol whereby training starts at a single depth and incrementally larger depths are trained following a dyadic schedule. This however, added non-trivial complexity to standard pre-training recipes for LLMs. To allow for a drop-in replacement that would require no change to standard pre-training recipes, in this work, we propose a simple reformulation that entirely avoids these stability issues. The reformulation involves transforming the division-based nonlinearities using logarithmic and exponential transformations. By avoiding explicit division, we improve gradient flow leading to improved stability.
As such, our contributions in this work are threefold:
We propose a novel non-expanding gated continued fraction architecture to replace (gated and vanilla) feedforward layers in LLMs (see Figure 1), which offers performance and throughput improvements over previously proposed continued fraction architectures [14].
We propose a simple reformulation of the division operation, which accounts for the non-linearity in CoFrNets, in terms for logarithms and exponentials to make training stable for deeper ladders. This facilitates drop-in replacement with a broad class of language models without the need to modify pre-training strategies.
We replace experts in MoE architectures as well as gated FFNs in Mamba-2 with our novel continued fraction architectural component further distinguishing it from prior work. We showcase the broad efficacy of our architectural component by reporting promising results on diverse LLM architectures such as GPT-2, Llama-3, Mamba-2 and Llama-MoE. Notably, the parameter savings for dense models are close to 33% which is already considerable, but for MoEs it reaches even higher to about 50%.
Figure 1. Above we see our continued fraction inspired architecture that can replace feedforward layers in dense as well as MoE architectures. Our architecture performs a non-expansive gating of the input that then passes through an (ensemble of) continued fraction ladders. The fact that we do not expand the hidden representation and each layer of our ladders requires only a linear number of parameters we obtain significant parameter savings over typical (gated and vanilla) feedforward layers leading to dense models that are the size and MoEs that are the size. In our implementations we create a different class for CoFrGeNet that has the same api as the FFN class, that is, same parameters are passed and the same size output tensor (equal to embedding size) is returned. The depth and width parameters for CoFrGeNet could be additionally passed or just set in the CoFrGeNet class itself. Hence, no changes are made to the residual stream or other aspects of the original architecture. The input in the figure is thus simply the output of the attention or SSM layer where the residual stream is added and the representation normalized in the particular block. In other words, nothing else in the model architectures changes and the input and output tensors are both size embedding dimension.
Overall, our contributions retain the lower parameter count and compactness of continued-fraction architectures, while simplifying (stable) training and improving performance in many cases with also improved throughput.
Related Work
Modern large language models are predominantly built on the transformer backbone [46], in which each block alternates a self-attention sublayer with a position-wise feedforward network (FFN). The FFN is typically implemented as a multilayer perceptron with a pointwise nonlinearity, typically ReLU [34], GELU [21] or Swish/SiLU [39]. Recently, the gated linear unit family [13] was shown to outperform vanilla MLPs at matched parameter budgets [41] in several settings, motivating the adoption of SwiGLU in the Llama family of models [44, 45, 18]. A parallel line of work is mixture-of-expert (MoE) models, where each token is routed to a small set of experts that themselves are MLPs or gated MLPs [42, 26, 15, 23, 9, 51]. Beyond attention-based models, state-space architectures such as Mamba [19] and Mamba-2 [11] replace quadratic attention with selective recurrences but still rely on MLP- or GLU-style channel mixers. Across all of these designs, the FFN sublayer dominates the parameter count, making it a natural target for architectural redesign.
Because of this reason, few works have explored alternatives to dense MLPs. Kolmogorov–Arnold Networks (KANs) [28] replace fixed activations with learnable univariate functions and have shown promise on small-scale scientific tasks in terms of performance and interpretability, although their scalability and training cost remain open questions. Many times KANs are 10x slower to train than MLPs of the same size. Structured-matrix approaches such as Monarch [10] factorize dense weights into block-diagonal components to reduce FLOPs and memory, and are not really a novel architecture but a strategy than can be applied across architectures. Polynomial networks [7] introduce multiplicative interactions between linear projections and have been shown effective in vision tasks. These alternatives however, have not been shown to match the empirical performance, scalability and stability of MLPs across varied large language model architectures.
The closest work to ours is the recent work CoFrGeNets [14], which proposed continued fraction architectures for attention and FFNs in dense Transformers. The FFN replacements produced models that were the size and with higher throughput. These replacements were however, not incorporated into other models such as Mamba and MoEs. In this work, we incorporate our component into these architectures as well and show that it should be the preferred alternative as we obtain similar level of parameter savings but much better performance in many cases and even higher throughput.
Background and Methods
We first introduce some notation. We denote the input or embedding dimension by , the number of ladders in an ensemble by , the sequence length by and the depth of a ladder by .
Next, we describe what a continued fraction is. The generalized form for a continued fraction is
where 's and 's can be complex numbers. If none of the or are zero , then using equivalence transformations [24], one can create simpler equivalent forms where either the or the , with in the latter form. A more concise way to write these two forms is as follows: i) and ii) . Form i) is known as the canonical form. One of the nice properties of continued fractions is that they are the best possible rational approximation to real numbers [24, 33].
In this work, we consider continued fractions in canonical form, with partial numerators for and depth . We thus view continued fractions as functions of the partial denominators, where we separate from the others and use as a shorthand. Hence,
where we also define as the “fractional part” of . Another way of representing a continued fraction is in terms of continuants, which we describe next. The continued fraction in (2) can be expressed as the following ratio of polynomials and ,
Polynomials are part of a sequence of polynomials , , known as continuants. They satisfy the recursion
Using (5), (3) can also be written as and hence,
This formalism as shown in previous work [14] significantly enhances training and inference speed over standard layer wise forward and backward passes done in [36], since the number of divisions for a depth ladder reduces from to 1 and divisions are significantly more expensive than multiplications or additions on modern hardware. Nonetheless, it still causes some training instability especially for deep ladders (even ). This resulted in the proposal for incremental training requiring non-trivial modifications to language model pre-training procedures. Below we propose a simple alternative that stabilizes training and absolves the need for these training modifications.
We design neural networks inspired by continued fractions by letting the partial denominators be affine functions of an input , , where is a row vector and a 1 is prepended to the elements of so that the corresponding coefficient is the intercept or bias term. We will often refer to a continued fraction with as a (CoFrNet) ladder, and we will also construct ensembles of such ladders.
Continued Fraction Architecture for FFNs
In Figure 1 we observe our continued fraction architecture for FFNs. We pass the -variate input to two linear layers where the output of one of them (bottom right portion in the figure) is gated by a Swish non-linearity. Then the outputs of the two layers are element-wise multiplied producing a (potentially) sparse representation . This representation is then input to continued fraction ladders that produce an -variate output. Note that one could have an arbitrary number of ladders in the ensemble and one projects to dimensions using the linear layer. The input to the ladders is a gated non-expanded (i.e. the expansion factor ) representation. The purpose of expansion and sparsification is typically understood to unpack information in a representation [12]. CoFrNets being a compact yet expressive function class are able to extract information with just partial unpacking, where they benefit from sparsification but do not necessarily need the expansion. Not performing expansion produces significant parameter savings as seen in the experiments. In particular, the number of parameters is as opposed to the typical for vanilla FFNs and for gated FFNs, where .
The continued fraction architecture suggested in [14] and depicted in Figure 3 in the appendix consists of two continued fraction ladder ensembles, which directly ingest the input. The output of the ladders is element-wise multiplied for better representation power. Thus no gating of the input was performed and two rather than one ensemble of continued fraction ladders was leveraged. The number of parameters for this variant was .

Figure 3. CoFrNet architecture from [14] to simulate FFNs. Two ensembles are used each consisting of specified number of -variate ladders. Element wise multiplication is done between the representations coming out of the linear layer of each ensemble for higher expressivity.
Although our new architecture has a quadratic dependence on , the non-expansion of the intermediate (hidden) FFN layer leads to significant parameter savings in practice as seen for the different models in the experiments. Additionally, as seen in these experiments the number of parameters is only slightly more or similar to the previous continued fraction architecture. More interestingly, even though our architecture may sometimes have more parameters than the previous one, since we have only one ensemble rather than two the arithmetic intensity is higher for our model as the input does not have to be read twice and processed separately by two ensembles. The gating is implemented so that the input is projected by a linear map to a representation twice its size and then Swish is applied to the latter half of this representation followed by elementwise multiplication with the prior half needing the input to be read just once. This leads to higher throughput as seen in the experiments, thus mitigating the adverse effects of (the slightly) increased parameter count.
Replacing Divisions
The continuant formulation described in the previous section does reduce the number of divisions significantly as a -depth ladder which would normally require divisions now requires only one. Nonetheless, the number of divisions scale with the size of the ensemble requiring -divisions for ladders. More importantly though even a single division can cause poles or abrupt discontinuities that can hurt gradient based optimization. This was observed in [14] and hence for higher depths incremental training was introduced where one would freeze deeper layers and start training them only after the shallower layers were trained reasonably well for the training to be stable.
We propose here a pytorch favorable replacement for the division operation which is performed in CoFrGeNets. In particular, the non-linearity in CoFrGeNets is division which is the ratio of two continuants for a depth ladder. To avoid poles the denominator was capped from below to a small producing the following non-linearity:
where denotes absolute value and the sign function which returns a value of +1 or −1. We rewrite (7) as follows:
This simple re-implementation absolves the need for incremental training. The logarithms and exponential smoothen out the division operation as logarithms compress the dynamic range of values, which reduces the skew in gradients and helps the optimizer move more smoothly towards a minima. This is confirmed in our experiments where CoFrGeNet-FNG is effectively optimized by optimizers such as AdamW for larger () depth and width of the continued fraction ensemble.
Experiments
Setup
Pre-Training Datasets and Models: We pre-train GPT2-xl and its variants on OpenWebText (OWT) [17] and the GneissWeb 35B (GW) [16] datasets. The remaining architectures, that is, Llama-3, Mamba-2 and Llama-MoE (4 experts, 1 activated) are pre-trained on the 2T data mix used to train Docling [2] models. This data mix contains web (DCLM2, DCLM3Plus [27]), multilingual (FineWeb-2-edu [29]), code (Starcoder, stack-edu [1]), math (Finemath [1], Infiwebmath [20], opcfineweb-math-corpus [22]) and synthetic data (Cosmopedia [3]), which are heavily used to train models for diverse document understanding. The mixture proportions for the different datasets are as follows: dclm3plus 0.5, dclm2 0.24, cosmopedia_v2 0.06, fineweb_math_corpus 0.01, finemath-4plus 0.015, infiwebmath-4plus 0.01, finemath-3plus 0.015, infiwebmath-3plus 0.005, starcoder 0.01, stack-edu 0.17 and fineweb-2-edu 0.01.
Baselines: We compare our non-expansive gated architecture CoFrGeNet-FNG with i) the original models with the existing FFNs, ii) CoFrGeNet-F which corresponds to replacing FFNs with the architecture proposed in [14] and depicted in Figure 3 and iii) the original models where non-expansive gating (NG) is applied for the up projection in the FFNs, but where the down projection is a typical (although non-expanded) linear layer (no CoFrNet) seen in the original models. This baseline checks the value of having our continued fraction architecture in the down projection.
Evaluations: For GPT2-xl and its variants we report perplexity on Penn Tree Bank (PTB) [30], Wikitext2 [31], Wikitext103 [31], Lambada [35], AgNews [50] and One Billion Words (LM1B) [5] datasets. We use a stride of 512 for wikitext2, wikitext103 as recommended in these works. For all the other datasets, we use a stride of 256. We then fine tune our models on GLUE [47] (classification) tasks and compare accuracies as done in previous works [40, 14]. We average results over five runs. The other models and their variants we evaluate on openbookqa [32], piqa [4], arc-easy [8], winogrande [25], hellaswag [49], lambada open AI [37], boolq [6] and sciq [48] which cover open domain Q&A, reasoning and text understanding tasks. For all the models we also report throughput, train time and floating point operations (FLOPs). For the Llama model we also report NF4 post training quantization (PTQ) results using bitsandbytes (https://huggingface.co/docs/bitsandbytes/en/index).
We also compare the effect of our division replacement with the previous implementation that performs divisions with and without incremental training. This experiment we report on GPT2-xl as the results are representative for other models which for all the reported experiments leveraged our division re-implementation from § 3.2. We employ a dyadic training schedule for incremental training as recommended in [14].
Parameter Settings: We use the recommended settings for pre-training GPT2-xl in https://github.com/karpathy/nanoGPT where, the learning rate is , weight decay is 0.1, there is no dropout and the maximum iterations is .
For fine tuning the GPT2-xl model the learning rate is , batch size is 64 and there is no dropout. This is the same for all the baselines. For our models the learning rate was with other parameters being the same. These learning rates produced the best results for the respective models.
We pre-train the other models for about 2M iterations. The initial learning rate is and follows an annealing schedule with no dropout.
For the continued fraction architectures we set . We experiment with equal to 1, 2, 5, 8 with the widths (i.e. number of ladders in each ensemble) taking the same values as well when replacing FFNs.
All experiments were performed with a batch size of 16 using the AdamW optimizer (, ) and a weight decay of 0.1. More details of each architecture are given in Table 1.
| Model | Size | Layers | ||
| GPT2-xl | 1.5B | 48 | 1600 | 4 |
| Llama | 3.2B | 24 | 3072 | 2.67 |
| Mamba-2 | 3.2B | 9 | 4096 | 3.5 |
| Llama-MoE | 403M | 30 | 576 | 2.67 |
Table 1. Below we see architectural details such as number of parameters, number of layers, embedding dimension () and expansion factor () of the different (original) models.
Table 2: Downstream task accuracies (best results bolded) for GPT2-xl and its variants on GLUE benchmark after finetuning. The first column is the pre-training dataset. Standard deviations are reported in Table 10 in the appendix. The CoFrGeNet variants perform similarly (best) in this case.
| Data | Model | MNLI | QQP | QNLI | SST2 | COLA | MRPC | RTE | WNLI |
| OWT | GPT2-xl (1.5B) | 86.89 | 88.93 | 91.35 | 93.56 | 81.78 | 79.83 | 60.27 | 58.28 |
| OWT | CoFrGeNet-F (972M) | 87.24 | 89.95 | 91.87 | 94.12 | 82.57 | 80.17 | 61.36 | 58.30 |
| OWT | CoFrGeNet-FNG (985M) | 87.26 | 89.95 | 91.89 | 94.16 | 82.59 | 80.21 | 61.35 | 58.30 |
| OWT | GPT2-xl-NG (985M) | 81.17 | 81.35 | 83.94 | 87.22 | 75.99 | 74.37 | 56.42 | 58.28 |
| GW | GPT2-xl (1.5B) | 78.28 | 86.83 | 82.93 | 91.82 | 74.18 | 77.72 | 60.19 | 58.33 |
| GW | CoFrGeNet-F (972M) | 79.23 | 87.24 | 82.69 | 92.38 | 74.79 | 78.04 | 61.37 | 58.33 |
| GW | CoFrGeNet-FNG (985M) | 79.62 | 87.26 | 82.73 | 92.36 | 74.83 | 78.01 | 61.35 | 58.33 |
| GW | GPT2-xl-NG (985M) | 74.83 | 84.74 | 77.82 | 83.94 | 68.93 | 71.83 | 57.85 | 58.33 |
Table 2.
| Data | Model | MNLI | QQP | QNLI | SST2 | COLA | MRPC | RTE | WNLI |
| OWT | GPT2-xl (1.5B) | ||||||||
| OWT | CoFrGeNet-F (972M) | ||||||||
| OWT | CoFrGeNet-FNG (985M) | ||||||||
| OWT | GPT2-xl-NG (985M) | ||||||||
| GW | GPT2-xl (1.5B) | ||||||||
| GW | CoFrGeNet-F (972M) | ||||||||
| GW | CoFrGeNet-FNG (985M) | ||||||||
| GW | GPT2-xl-NG (985M) |
Table 10. Downstream task accuracies with standard deviations (best results bolded) for GPT2-xl and its variants on GLUE benchmark after finetuning. The first column is the pre-training dataset.
Table 3: Perplexities of GPT2-xl and its variants with best results bolded.
| Data | Model | PTB | Wikitxt2 | Lbda | AgNews | Lm1b | Wikitxt103 |
| OWT | GPT2-xl (1.5B) | 30.12 | 18.30 | 8.66 | 37.13 | 41.20 | 17.50 |
| OWT | CoFrGeNet-F (972M) | 29.94 | 17.09 | 8.15 | 35.72 | 40.11 | 16.17 |
| OWT | CoFrGeNet-FNG (985M) | 29.87 | 17.14 | 8.11 | 35.69 | 40.17 | 16.13 |
| OWT | GPT2-xl-NG (985M) | 35.98 | 27.74 | 16.35 | 50.75 | 51.95 | 29.29 |
| GW | GPT2-xl (1.5B) | 29.07 | 19.12 | 31.78 | 45.62 | 52.36 | 18.93 |
| GW | CoFrGeNet-F (972M) | 29.83 | 18.08 | 30.55 | 41.77 | 46.59 | 18.11 |
| GW | CoFrGeNet-FNG (985M) | 29.68 | 18.10 | 30.55 | 41.65 | 46.86 | 18.06 |
| GW | GPT2-xl-NG (985M) | 34.26 | 27.38 | 39.44 | 61.81 | 58.64 | 29.02 |
Table 3.
Hardware: The GPT2 models were pre-trained on 16 H100 GPUs leveraging just distributed data parallel (ddp) training as done previously. Fine tuning was done using a single A100 GPU for each model. The Llama-3 and Mamba-2 models were pre-trained using 128 H100 GPUs with fully sharded distributed data parallel (fsdp) training. The Llama-MoE models were pre-trained using 64 H100 GPUs with fsdp.
Table 4: Zero-shot accuracies on open domain Q&A, reasoning and text understanding tasks for Llama and its variants. As can be seen CoFrGeNet-FNG is much better than CoFrGeNet-F and Llama-NG in most cases and much closer to the original model Llama being roughly the latters size. The docling data mix of 2 trillion tokens was used for pre-training.
| Model | openqa | piqa | arc | wino | hswag | lambada | boolq | sciq |
| Llama (3.2B) | .282 | .76 | .77 | .654 | .503 | .581 | .691 | .941 |
| CoFrGeNet-F (1.9B) | .292 | .764 | .765 | .643 | .482 | .581 | .659 | .941 |
| CoFrGeNet-FNG (2.1B) | .294 | .764 | .778 | .649 | .491 | .583 | .668 | .944 |
| Llama-NG (2.1B) | .277 | .755 | .762 | .639 | .477 | .576 | .660 | .938 |
Table 4.
Observations
Performance: From Table 2 and Table 3 we see that our CoFrGeNet-FNG architecture performs best or close to it on different benchmarks for GPT2-xl. It has slightly more parameters than the previously suggested CoFrGeNet architecture CoFrGeNet-F. Since, GPT2-xl employs a vanilla FFN it seems the gating in our architecture is not as needed, although it does not harm the performance either. Not using a CoFrGeNet and doing non-expansive gating however, hurts performance.
Looking at Table 4 and Table 5 we see the advantage of our architecture where it is closer to the original Llama and Mamba-2 models than the CoFrGeNet-F. It is in fact significantly better than CoFrGeNet-F on many benchmarks and where it is not worse than it even in a single instance. The non-expansive gated version without CoFrNet is again worse. This shows our architecture is particularly useful for models that use gated FFNs.
Table: Zero-shot accuracies on open domain Q&A, reasoning and text understanding tasks for Mamba-2 and its variants. Here too CoFrGeNet-FNG is much better than CoFrGeNet-F and Mamba2-NG in most cases and closer to the original model Mamba-2 being roughly the latters size. The docling data mix of 2 trillion tokens was used for pre-training.
| Model | openqa | piqa | arc | wino | hswag | lambada | boolq | sciq |
| Mamba-2 (3.2B) | .324 | .761 | .768 | .615 | .486 | .548 | .655 | .919 |
| CoFrGeNet-F (1.9B) | .302 | .751 | .765 | .613 | .482 | .541 | .651 | .913 |
| CoFrGeNet-FNG (2.1B) | .322 | .763 | .773 | .619 | .484 | .543 | .651 | .924 |
| Mamba-2-NG (2.1B) | .297 | .757 | .762 | .609 | .478 | .539 | .646 | .918 |
Table 5.
For the MoE case, we observe in Table 6 that the non-expansive versions are roughly half the size of the original MoE, and our model outperforms even the original model in most cases. Here the size becomes roughly half because more (4 in this case) FFNs (a.k.a. experts) are replaced by our non-expansive gated architecture.
Table: Zero-shot accuracies on open domain Q&A, reasoning and text understanding tasks for Llama-MoE and its variants. In this case, CoFrGeNet-FNG is much better than CoFrGeNet-F, Llama-MoE-NG and even the original model Llama-MoE in most cases being roughly half the latters size. The docling data mix of 2 trillion tokens was used for pre-training.
| Model | openqa | piqa | arc | wino | hswag | lambada | boolq | sciq |
| Llama-MoE (403M) | .142 | .6 | .472 | .501 | .275 | .178 | .608 | .726 |
| CoFrGeNet-F (204M) | .148 | .609 | .511 | .499 | .280 | .196 | .414 | .761 |
| CoFrGeNet-FNG (204M) | .152 | .610 | .511 | .498 | .281 | .212 | .532 | .776 |
| Llama-MoE-NG (204M) | .142 | .576 | .417 | .499 | .267 | .157 | .607 | .681 |
Table 6.
As the number of experts increase, our parameter savings should approach the expansion factor in these models as a larger fraction of the model would be our continued fraction architecture. For Llama-MoE the expansion factor was 2.67 and so we start coming close to it in terms of scale of parameter savings as we move from dense models to MoEs. Hence, with more experts the percentage savings in parameters will be even higher. Interestingly here, the new architecture has the same size as CoFrGeNet-F. Also observing the validation loss during pre-training in Figure 2, we see faster convergence and better loss when compared to the original Llama-MoE.

Figure 2. Validation loss for Llama-MoE and CoFrGeNet-FNG as a function of the number of training tokens. As can be seen the loss for CoFrGeNet-FNG converges faster and to a lower value (2.92 vs 3.01) than the original model qualitatively consistent with the benchmark results in Table 6.
Efficiency: In Table 7 we observe the throughput, train times and FLOPS for the different models. Our variant, CoFrGeNet-FNG, is much faster than the original models and requires much fewer FLOPS. While CoFrGeNet-FNG although is slightly larger than the previously proposed CoFrGeNet-F variant, in most cases it has higher throughput and lower training time. This is because the (gated) input has to pass only through a single ensemble of ladders as opposed to two distinct ones and hence has to be read only once leading to higher arithmetic intensity for the new architecture. This improves training efficiency albeit with slightly more parameters and FLOPS/token.
| Model | Tokens/day | Train Time (days) | FLOPS/token (GF) |
| GPT2-xl (1.5B) | 1.15B | 7.9, 17.2 | 9.1 |
| CoFrGeNet-F (972M) | 1.17B | 7.8, 16.9 | 5.9 |
| CoFrGeNet-FNG (985M) | 1.20B | 7.6, 16.2 | 6.1 |
| GPT2-xl-NG (985M) | 1.21B | 7.6, 16.1 | 6.1 |
| Llama (3.2B) | 235B | 8.5 | 19.3 |
| CoFrGeNet-F (1.9B) | 288B | 7 | 11.7 |
| CoFrGeNet-FNG (2.1B) | 306B | 6.5 | 12.5 |
| Llama-NG (2.1B) | 306B | 6.5 | 12.5 |
| Mamba-2 (3.2B) | 475B | 4.2 | 19.1 |
| CoFrGeNet-F (1.9B) | 478B | 4.2 | 11.5 |
| CoFrGeNet-FNG (2.1B) | 486B | 4.1 | 12.2 |
| Mamba2-NG (2.1B) | 491B | 4 | 12.1 |
| Llama-MoE (403M) | 299B | 6.7 | 1.1 |
| CoFrGeNet-F (204M) | 301B | 6.6 | 0.70 |
| CoFrGeNet-FNG (204M) | 309B | 6.4 | 0.71 |
| Llama-MoE-NG (204M) | 310B | 6.3 | 0.70 |
Table 7.
Post Training Quantization: We see in Table 8 that the accuracy drop after performing 4-bit PTQ on the CoFrGeNet-FNG variant of Llama is minimal for all benchmarks. This implies that our variants are robust to quantization. The peak memory usage dropped from 8.3548 GB to 2.3564 GB for the quantized variant.
| Model | openqa | piqa | arc | wino | hswag | lambada | boolq | sciq |
| CoFrGeNet-FNG (2.1B) | .0120 | .0141 | .0126 | .0032 | .0120 | .0136 | .0141 | −.0070 |
Table 8.
Replacing Divisions: Note that all models were trained using equation (8) as a replacement for divisions. We see from the results we discussed before that the performance for CoFrGeNet-F matches that of those reported in [14], which did not use this replacement, but used incremental training, thus showing the efficacy of our no division replacement. Moreover, the results for our variant CoFrGeNet-FNG is competitive or better than the original models in several cases further strengthening our claim.
Table 7: Throughput, training time and the number of (training) floating point operations (FLOPS) for the different models and our variants of them. For GPT2-xl the train time is for OWT, GW respectively, while for others its on the docling data mix.
Table 8: Zero-shot accuracy difference between (bf16) CoFrGeNet-FNG for Llama and its post training quantized NF4 variant. As can be seen the difference in accuracies is minimal on open domain Q&A, reasoning and text understanding tasks. The docling data mix of 2 trillion tokens was used for pre-training.
In Table 9, we see a comparison of the three approaches –no incremental training (NIT) using divisions, incremental training (IT) using divisions, and no incremental training and no divisions (NIT-ND)– for depth 5 CoFrGeNet-FNG networks replacing FFNs in GPT2-xl.
| Data | Model | PTB | Wikitxt2 | Lbda | AgNews | Lm1b | Wikitxt103 |
| OWT | NIT | 33.72 | 26.71 | 12.56 | 42.18 | 47.28 | 22.65 |
| OWT | IT | 29.89 | 17.12 | 8.12 | 35.72 | 40.14 | 16.14 |
| OWT | NIT-ND | 29.87 | 17.14 | 8.11 | 35.69 | 40.17 | 16.13 |
| GW | NIT | 35.88 | 25.55 | 37.33 | 45.46 | 49.53 | 20.44 |
| GW | IT | 29.72 | 18.13 | 30.52 | 41.63 | 46.83 | 18.11 |
| GW | NIT-ND | 29.68 | 18.10 | 30.55 | 41.65 | 46.86 | 18.06 |
Table 9.
Table 9: Perplexities of CoFrGeNet-FNG (GPT2-xl) with no incremental training (NIT), with incremental training (IT) and with no incremental training and using no divisions log/exp trick (NIT-ND). NIT-ND performs similar to IT absolving the need for complicating the standard training procedure of language models. Best results bolded.
As can be seen the perplexities are quite similar for IT and NIT-ND with NIT being much worse. This apples-to-apples comparison clearly shows that our reformulation is effective in stabilizing the training of these networks foregoing the need for incremental training.
Discussion
In this work we have proposed a novel continued fraction architecture to replace FFNs that performs similarly or significantly better than prior work, while still being parameter efficient and having higher throughput. We have evaluated this across different models such as GPT2, Llama-3, Mamba-2 and Llama-MoE, where the latter two replacements were not performed in prior work. We also proposed a simple way to re-implement divisions in these architectures in terms of logarithms and exponentials making training stable and accurate precluding the need for incorporating complex incremental training procedures. Even though our work significantly enhances the efficacy and applicability of continued fraction architectures for language modeling it has certain limitations. Our networks are still susceptible to prompt injection attacks, hallucinations and other kinds of output manipulation that other architectures are. A memory efficient implementation possibly leveraging Triton kernels is something missing in our implementations, which would possibly further speed up models. We would also like to test our contributions on larger MoE models, although that is constrained by the amount of compute we have available.
We believe, our work makes an important contribution to the field of efficient architectures which can have significant societal implications. Having to train more compact models can lead to savings in time, cost and a reduced carbon footprint. They could be easier to audit, maintain and track. The favorable post training quantization results further support that compact CoFrGeNet models can be performant. Moreover, given that our proposed component has favorable interpretability properties [36] may open new avenues to appropriate trust in these models rather than relying solely on post-hoc (mechanistic) interpretability methods, which could have varying degrees of faithfulness.
In the future, it would be exciting to understand if there are ways to guide this unique architecture, which has multiple intervention points as it accepts an input at every layer, to inherently become more robust or safe without simply doing the standard data augmented training. Foraying into such and other trust and efficiency related directions would be, in our opinion, a worthwhile endeavor.
Appendix
References
- [1]L. B. Allal, A. Lozhkov, E. Bakouch, G. M. Blázquez, G. Penedo, L. Tunstall, A. Marafioti, H. Kydl̋ček, A. P. Lajman, V. Srivastav, J. Lochner, C. Fahlgren, X.-S. Nguyen, C. Fourrier, B. Burtenshaw, H. Larcher, H. Zhao, C. Zakka, M. Morlon, C. Raffel, L. von Werra, and T. Wolf. Smollm2: When smol goes big – data-centric training of a small language model, 2025.
- [2]C. Auer, M. Lysak, A. Nassar, M. Dolfi, N. Livathinos, P. Vagenas, C. B. Ramis, M. Omenetti, F. Lindlbauer, K. Dinkla, L. Mishra, Y. Kim, S. Gupta, R. T. de Lima, V. Weber, L. Morin, I. Meijer, V. Kuropiatnyk, and P. W. J. Staar. Docling technical report. Technical report, 8 2024.arxiv.org/abs/2408.09869
- [3]L. Ben Allal, A. Lozhkov, G. Penedo, T. Wolf, and L. von Werra. Cosmopedia, 2024.
- [4]Y. Bisk, R. Zellers, R. L. Bras, J. Gao, and Y. Choi. Piqа: Reasoning about physical commonsense in natural language. In Thirty-Fourth AAAI Conference on Artificial Intelligence, 2020.arxiv.org/abs/1911.11641
- [5]C. Chelba, T. Mikolov, M. Schuster, Q. Ge, T. Brants, P. Koehn, and T. Robinson. One billion word benchmark for measuring progress in statistical language modeling. In H. Li, H. M. Meng, B. Ma, E. Chng, and L. Xie, editors, 15th Annual Conference of the International Speech Communication Association, INTERSPEECH 2014, Singapore, September 14-18, 2014, pages 2635–2639. ISCA, 2014.
- [6]C. Christopher, L. Kenton, C. Ming-Wei, K. Tom, C. Michael, and T. Kristina. Boolq: Exploring the surprising difficulty of natural yes/no questions. In NAACL, 2019.arxiv.org/abs/1905.10044
- [7]G. G. Chrysos, S. Moschoglou, G. Bouritsas, Y. Panagakis, J. Deng, and S. Zafeiriou. π-nets: Deep polynomial neural networks. In Proceedings of the IEEE/CVF Conference on Computer Vision and Pattern Recognition (CVPR), pages 7325–7335, 2020.DOI
- [8]P. Clark, I. Cowhey, O. Etzioni, T. Khot, A. Sabharwal, C. Schoenick, and O. Tajford. Think you have solved question answering? try arc, the ai2 reasoning challenge. arXiv:1803.05457v1, 2018.arxiv.org/abs/1803.05457
- [9]D. Dai, C. Deng, C. Zhao, R. X. Xu, H. Gao, D. Chen, J. Li, W. Zeng, X. Yu, Y. Wu, Z. Xie, Y. K. Li, P. Huang, F. Luo, C. Ruan, Z. Sui, and W. Liang. DeepSeekMoE: Towards ultimate expert specialization in mixture-of-experts language models. In Proceedings of the 62nd Annual Meeting of the Association for Computational Linguistics (ACL), 2024.
- [10]T. Dao, B. Chen, N. S. Sohoni, A. Desai, M. Poli, J. Grogan, A. Liu, A. Rao, A. Rudra, and C. Ré. Monarch: Expressive structured matrices for efficient and accurate training. In International Conference on Machine Learning (ICML), pages 4690–4721. PMLR, 2022.arxiv.org/abs/2204.00595
- [11]T. Dao and A. Gu. Transformers are SSMs: Generalized models and efficient algorithms through structured state space duality. In International Conference on Machine Learning (ICML), 2024.arxiv.org/abs/2405.21060
- [12]S. Dasgupta and C. Tosh. Expressivity of expand-and-sparsify representations. Technical report, 6 2020.arxiv.org/abs/2006.03741
- [13]Y. N. Dauphin, A. Fan, M. Auli, and D. Grangier. Language modeling with gated convolutional networks. In International Conference on Machine Learning (ICML), 2017.
- [14]A. Dhurandhar, V. Chenthamarakshan, D. Wei, T. Pedapati, K. N. Ramamurthy, and R. Nair. Cofrgenet: Continued fraction architectures for language generation. In Proceedings of the 43rd International Conference on Machine Learning, ICML’26. JMLR.org, 2026.arxiv.org/abs/2601.21766
- [15]W. Fedus, B. Zoph, and N. Shazeer. Switch transformers: Scaling to trillion parameter models with simple and efficient sparsity. Journal of Machine Learning Research, 23(120):1–39, 2022.arxiv.org/abs/2101.03961
- [16]H. E. Gohari, S. R. Kadhe, S. Y. S. C. Adam, A. Adebayo, P. Adusumilli, F. Ahmed, N. B. Angel, S. Borse, Y.-C. Chang, X.-H. Dang, N. Desai, R. Eres, R. Iwamoto, A. Karve, Y. Koyfman, W.-H. Lee, C. Liu, B. Lubinsky, T. Ohko, P. Pesce, M. Touma, S. Wang, S. Witherspoon, H. Woisetschlager, D. Wood, K.-L. Wu, I. Yoshida, S. Zawad, P. Zerfos, Y. Zhou, and B. Bhattacharjee. Gneissweb: Preparing high quality data for llms at scale, 2025.arxiv.org/abs/2502.14907
- [17]A. Gokaslan, V. Cohen, E. Pavlick, and S. Tellex. Openwebtext corpus. http://Skylion007.github.io/OpenWebTextCorpus, 2019.
- [18]A. Grattafiori, A. Dubey, A. Jauhari, A. Pandey, A. Kadian, A. Al-Dahle, A. Mathur, A. Schelten, A. Vaughan, et al. The llama 3 herd of models. arXiv preprint arXiv:2407.21783, 2024.arxiv.org/abs/2407.21783
- [19]A. Gu and T. Dao. Mamba: Linear-time sequence modeling with selective state spaces. In First Conference on Language Modeling, 2024.arxiv.org/abs/2312.00752
- [20]X. Han, Y. Jian, X. Hu, H. Liu, Y. Wang, Q. Fan, Y. Ai, H. Huang, R. He, Z. Yang, and Q. You. Infimm-webmath-40b: Advancing multimodal pre-training for enhanced mathematical reasoning, 2024.arxiv.org/abs/2409.12568
- [21]D. Hendrycks and K. Gimpel. Gaussian error linear units (GELUs). arXiv preprint arXiv:1606.08415, 2016.
- [22]S. Huang, T. Cheng, J. K. Liu, J. Hao, L. Song, Y. Xu, L. Yang, J. H. Liu, C. Zhang, L. Chai, R. Yuan, Z. Zhang, J. Fu, Q. Liu, J. Zhang, Z. Wang, Y. Qi, Y. Xu, and W. Chu. Opencoder: The open cookbook for top-tier code large language models. 2024.arxiv.org/abs/2411.04905
- [23]A. Q. Jiang, A. Sablayrolles, A. Roux, A. Mensch, B. Savary, C. Bamford, D. S. Chaplot, D. de las Casas, E. B. Hanna, F. Bressand, et al. Mixtral of experts. arXiv preprint arXiv:2401.04088, 2024.arxiv.org/abs/2401.04088
- [24]W. B. Jones and W. Thron. Continued fractions. Analytic theory and applications. Encyclopedia of Mathematics and its Applications. Addison-Wesley, 1980.
- [25]S. Keisuke, L. B. Ronan, B. Chandra, and C. Yejin. Winogrande: An adversarial winograd schema challenge at scale. 2019.arxiv.org/abs/1907.10641
- [26]D. Lepikhin, H. Lee, Y. Xu, D. Chen, O. Firat, Y. Huang, M. Krikun, N. Shazeer, and Z. Chen. GShard: Scaling giant models with conditional computation and automatic sharding. In International Conference on Learning Representations (ICLR), 2021.
- [27]J. Li, A. Fang, G. Smyrnis, M. Ivgi, M. Jordan, S. Gadre, H. Bansal, E. Guha, S. Keh, K. Arora, S. Garg, R. Xin, N. Muennighoff, R. Heckel, J. Mercat, M. Chen, S. Gururangan, M. Wortsman, A. Albalak, Y. Bitton, M. Nezhurina, A. Abbas, C.-Y. Hsieh, D. Ghosh, J. Gardner, M. Kilian, H. Zhang, R. Shao, S. Pratt, S. Sanyal, G. Ilharco, G. Daras, K. Marathe, A. Gokaslan, J. Zhang, K. Chandu, T. Nguyen, I. Vasiljevic, S. Kakade, S. Song, S. Sanghavi, F. Faghri, S. Oh, L. Zettlemoyer, K. Lo, A. El-Nouby, H. Pouransari, A. Toshev, S. Wang, D. Groeneveld, L. Soldaini, P. W. Koh, J. Jitsev, T. Kollar, A. G. Dimakis, Y. Carmon, A. Dave, L. Schmidt, and V. Shankar. Datacomp-lm: In search of the next generation of training sets for language models. arXiv preprint arXiv:2406.11794, 2024.arxiv.org/abs/2406.11794
- [28]Z. Liu, Y. Wang, S. Vaidya, F. Ruehle, J. Halverson, M. Soljačić, T. Y. Hou, and M. Tegmark. KAN: Kolmogorov-Arnold networks. arXiv preprint arXiv:2404.19756, 2024.arxiv.org/abs/2404.19756
- [29]A. Lozhkov, L. Ben Allal, L. von Werra, and T. Wolf. Fineweb-edu, May 2024.DOI
- [30]M. P. Marcus, B. Santorini, and M. A. Marcinkiewicz. Building a large annotated corpus of english: The penn treebank. Comput. Linguistics, 19(2):313–330, 1993.
- [31]S. Merity, C. Xiong, J. Bradbury, and R. Socher. Pointer sentinel mixture models. In 5th International Conference on Learning Representations, ICLR 2017, Toulon, France, April 24-26, 2017, Conference Track Proceedings. OpenReview.net, 2017.arxiv.org/abs/1609.07843
- [32]T. Mihaylov, P. Clark, T. Khot, and A. Sabharwal. Can a suit of armor conduct electricity? a new dataset for open book question answering. In EMNLP, 2018.arxiv.org/abs/1809.02789
- [33]K. Milton. Summation techniques, Padé approximants, and continued fractions. 2011. http://www.nhn.ou.edu/~milton/p5013/chap8.pdf.
- [34]V. Nair and G. E. Hinton. Rectified linear units improve restricted boltzmann machines. In Proceedings of the 27th International Conference on Machine Learning (ICML), pages 807–814. Omnipress, 2010.
- [35]D. Paperno, G. Kruszewski, A. Lazaridou, Q. N. Pham, R. Bernardi, S. Pezzelle, M. Baroni, G. Boleda, and R. Fernández. The LAMBADA dataset: Word prediction requiring a broad discourse context. In Proceedings of the 54th Annual Meeting of the Association for Computational Linguistics, ACL 2016, August 7-12, 2016, Berlin, Germany, Volume 1: Long Papers. The Association for Computer Linguistics, 2016.
- [36]I. Puri, A. Dhurandhar, T. Pedapati, K. Shanmugam, D. Wei, and K. R. Varshney. Cofrnets: Interpretable neural architecture inspired by continued fractions. In M. Ranzato, A. Beygelzimer, Y. Dauphin, P. Liang, and J. W. Vaughan, editors, Advances in Neural Information Processing Systems, volume 34, pages 21668–21680. Curran Associates, Inc., 2021.
- [37]A. Radford, K. Narasimhan, T. Salimans, and I. Sutskever. Improving language understanding by generative pre-training. 2018.
- [38]A. Radford, J. Wu, R. Child, D. Luan, D. Amodei, I. Sutskever, et al. Language models are unsupervised multitask learners. OpenAI blog, 1(8):9, 2019.
- [39]P. Ramachandran, B. Zoph, and Q. V. Le. Searching for activation functions. arXiv preprint arXiv:1710.05941, 2017.arxiv.org/abs/1710.05941
- [40]S. S. Sahoo, M. Arriola, Y. Schiff, A. Gokaslan, E. Marroquin, J. T. Chiu, A. Rush, and V. Kuleshov. Simple and effective masked diffusion language models, 2024.arxiv.org/abs/2406.07524
- [41]N. Shazeer. GLU variants improve transformer. arXiv preprint arXiv:2002.05202, 2020.arxiv.org/abs/2002.05202
- [42]N. Shazeer, A. Mirhoseini, K. Maziarz, A. Davis, Q. Le, G. Hinton, and J. Dean. Outrageously large neural networks: The sparsely-gated mixture-of-experts layer. In International Conference on Learning Representations (ICLR), 2017.arxiv.org/abs/1701.06538
- [43]W. Sun, J. Hu, Y. Zhou, J. Du, D. Lan, K. Wang, T. Zhu, X. Qu, Y. Zhang, X. Mo, D. Liu, Y. Liang, W. Chen, G. Li, and Y. Cheng. Speed always wins: A survey on efficient architectures for large language models. Technical report, 8 2025.arxiv.org/abs/2508.09834
- [44]H. Touvron, T. Lavril, G. Izacard, X. Martinet, M.-A. Lachaux, T. Lacroix, B. Rozière, N. Goyal, E. Hambro, F. Azhar, A. Rodriguez, A. Joulin, E. Grave, and G. Lample. LLaMA: Open and efficient foundation language models. arXiv preprint arXiv:2302.13971, 2023.arxiv.org/abs/2302.13971
- [45]H. Touvron, L. Martin, K. Stone, P. Albert, A. Almahairi, Y. Babaei, N. Bashlykov, S. Batra, P. Bhargava, S. Bhosale, et al. Llama 2: Open foundation and fine-tuned chat models. arXiv preprint arXiv:2307.09288, 2023.arxiv.org/abs/2307.09288
- [46]A. Vaswani, N. Shazeer, N. Parmar, J. Uszkoreit, L. Jones, A. N. Gomez, L. u. Kaiser, and I. Polosukhin. Attention is all you need. In Advances in Neural Information Processing Systems, 2017.arxiv.org/abs/1706.03762
- [47]A. Wang, A. Singh, J. Michael, F. Hill, O. Levy, and S. R. Bowman. Glue: A multi-task benchmark and analysis platform for natural language understanding. In Proceedings of the 24th International Conference on Learning Representations, 2019.
- [48]J. Welbl, N. F. Liu, and M. Gardner. Crowdsourcing multiple choice science questions. 2017.arxiv.org/abs/1707.06209
- [49]R. Zellers, A. Holtzman, Y. Bisk, A. Farhadi, and Y. Choi. Hellaswag: Can a machine really finish your sentence? In Proceedings of the 57th Annual Meeting of the Association for Computational Linguistics, 2019.arxiv.org/abs/1905.07830
- [50]X. Zhang, J. Zhao, and Y. LeCun. Character-level convolutional networks for text classification. In Proceedings of the 28th International Conference on Neural Information Processing Systems - Volume 1, NIPS’15, page 649–657, Cambridge, MA, USA, 2015. MIT Press.arxiv.org/abs/1509.01626
- [51]T. Zhu, X. Qu, D. Dong, J. Ruan, J. Tong, C. He, and Y. Cheng. LLaMA-MoE: Building mixture-of-experts from LLaMA with continual pre-training. In Proceedings of the 2024 Conference on Empirical Methods in Natural Language Processing (EMNLP), 2024.arxiv.org/abs/2406.16554
