Authors: Abhishek Patnia* , Aman Gupta* and Shao Tang*.
*these authors contributed equally

Introduction

At Nubank, we train Transformer models on sequences of financial transactions to learn patterns in financial behavior. To improve these models, researchers are constantly running experiments to explore architectural or data changes [8]. Each experiment helps us evaluate a new modeling idea, but also consumes GPU time. Improving training efficiency shortens that feedback loop and lets us test more ideas within the same hardware budget. 

This article describes how we accelerated training for a hybrid model that combines Gated DeltaNet (GDN) layers with softmax attention in a 3:1 ratio [4]. We chose this architecture because it delivers better model quality for our task while training faster than a model using attention in every layer. To study its training efficiency, we use sequences of 16,384 tokens on a B200 cluster and examine two optimizer configurations: AdamW and Muon.

Check our job opportunies

Measuring training efficiency

We measure execution efficiency using model FLOPs utilization (MFU), which estimates how much of the hardware’s theoretical compute capacity goes toward the model’s required forward and backward passes [1].

MFU (%) = 100 × (tokens/s × FLOPs/token) / (peak FLOPs/s)

FLOPs/token estimates the model’s forward-and-backward work per token, excluding activation recomputation. The measured token rate and peak compute capacity refer to the same GPU allocation, with peak capacity taken at the training precision.

Our hybrid GDN Attention model at longer context lengths like 16,384 tokens requires fewer FLOPs per token than an all-attention model while delivering better model quality in our experiments. It can therefore process more tokens per second per GPU even when its MFU is lower. To illustrate this advantage, we also report the MFU an all-attention model would need to achieve to match the hybrid model’s measured token rate. We call this all-SDPA-equivalent MFU. For example, our AdamW hybrid baseline reports 21.1% MFU, while an all-attention model processing the same number of tokens per second per GPU would require 51.4% MFU. Throughout this article, we present both metrics to show the hybrid model’s execution efficiency alongside the training speed advantage of its architecture.

Starting from this hybrid baseline, we improve the training implementation one step at a time. Within each optimizer’s series, we hold the model configuration, batch size, training recipe, and hardware allocation fixed. Both series follow the same progression through attention-kernel selection and compiler integration, with Muon adding a final step that batches its weight updates. Together, these improvements raise hybrid-model MFU from 21.1% to 39.3% with AdamW and from 20.2% to 39.2% with Muon. Figure 1 shows how the improvements accumulate, using both hybrid-model and all-SDPA-equivalent MFU.

Figure 1. MFU across four cumulative stages for AdamW and five for Muon. Values represent the final logged interval at optimizer step 999. All-SDPA-equivalent MFU changes the FLOP accounting, not the architecture executed.

Choosing the right attention kernel

PyTorch’s scaled dot-product attention (SDPA) interface supports several implementations, so the same model code can run different kernels underneath. In practice, PyTorch selects the kernel through a set of backend rules, and the selected kernel is not always the fastest available. Our first step was to check which implementation was actually running [2].

In earlier experiments, correcting our software setup enabled NVIDIA’s optimized cuDNN attention kernels, delivering performance comparable to the third-party implementation we were testing. Using cuDNN through the existing PyTorch interface kept the change small and avoided maintaining a separate attention integration.

We applied this lesson to our hybrid GDN experiments, where cuDNN handles the softmax-attention layers while the GDN kernels remain unchanged. Both optimizer configurations benefited, with the model and workload held fixed within each series. Our first improvement came from selecting the right backend, without changing the model architecture.

MFU after enabling cuDNN

AdamW: 21.1% → 28.6%   +7.5 pp

Muon: 20.2% → 27.1%   +6.9 pp

Compared with each optimizer’s baseline; pp = percentage points.

Leveraging Torch Compile

Beyond the attention kernel, a training step also includes many surrounding tensor operations. PyTorch’s torch.compile can optimize this work by combining operations and reducing intermediate memory traffic. To realize those benefits, the compiled code must remain reusable as training progresses.

In our earlier training work, a changing loss weight stored as a Python number triggered repeated recompilation. Representing that value as a tensor allowed the compiled code to handle changing weights without generating a new version for each value [3].  Enabling compilation was therefore only part of the work; we also needed to address the issues preventing the compiled code from being reused.

With cuDNN already enabled, compilation improved MFU for both optimizers. We then turned to another obstacle: the GDN integration divided computation into separate compiled regions, limiting what the compiler could optimize across them.

MFU after enabling torch.compile

AdamW: 28.6% → 32.0%   +3.4 pp

Muon: 27.1% → 30.1%   +3.0 pp

Compared with the cuDNN-enabled stage; pp = percentage points.

Repackaging FLA Kernels for GDN

Our GDN layers already used kernels from Flash Linear Attention (FLA) [5].  The remaining issue was how the code around those kernels interacted with torch.compile. This code divided computation into separate compiled regions, limiting the compiler’s ability to optimize the surrounding operations.

We addressed this in two steps. First, we exposed key FLA operations through compiler-friendly interfaces with explicit gradient rules. We then treated a fixed GPU hardware property as a constant, removing another source of graph breaks. These changes preserved the model architecture, GDN equations, and core FLA kernels.

Figure 2. Fixing GDN compilation reduced captured graphs in an isolated diagnostic and improved training MFU for both optimizer configurations. One captured graph does not imply one GPU kernel or one graph for the entire training job.

With cuDNN and torch.compile already enabled, the complete set of GDN compile fixes improved MFU for both AdamW and Muon in our fixed-workload B200 experiments. The improvement came from making the existing GDN computation more compiler-friendly, without changing the model or replacing its core kernels. This showed why the code surrounding an optimized kernel deserves attention alongside the kernel itself.

MFU after GDN compile fixes

AdamW: 32.0% → 39.3%   +7.3 pp

Muon: 30.1% → 36.7%   +6.6 pp

Compared with the previous compiled stage; pp = percentage points.

Keeping Optimizer Overhead low

As the model’s forward and backward passes become faster, optimizer execution can take a larger share of each training step. Muon prepares weight updates through repeated matrix operations, and processing each matrix separately creates many small GPU operations. We focused on executing this work more efficiently while retaining the update rule used in our earlier Muon research [6]. 

Our MuonMegaBatch implementation groups compatible updates with the same matrix shape and processes them together. It also batches the surrounding momentum and parameter updates, reducing repeated per-matrix launches. We adapted this execution strategy from Microsoft’s Dion implementation [7].  Here, batching refers to optimizer operations—the training batch size stays unchanged.

Figure 3. MuonMegaBatch groups compatible matrix updates while preserving each matrix’s independent update. This schematic illustrates execution, not a literal count of GPU kernels.

Each matrix still receives its own independent update. MuonMegaBatch preserves the intended Muon update rule, although batched arithmetic can introduce floating-point differences. With all earlier kernel and compilation improvements retained, this final Muon-only optimization increased MFU in our fixed-workload B200 comparison. The improvement came from changing how optimizer updates execute, without changing the model or training batch size.

MFU after enabling MuonMegaBatch

Muon: 36.7% → 39.2%   +2.5 pp

Compared with standard Muon after GDN compile fixes; pp = percentage points.

Conclusion

Together, these changes raised MFU from roughly 20% to nearly 40% with AdamW and from 20.2% to 39.2% with Muon in our fixed-workload B200 comparisons. We achieved these gains without changing the model architecture or training batch size. The gains  came from attention-kernel selection, reusable compiled code, fixes to GDN compilation, and, for Muon, batched optimizer updates.

The broader lesson is that training efficiency depends on the whole execution path. Fast kernels matter, but so do the code surrounding them and the work performed between model passes. Holding the workload fixed and measuring each change helped us identify which improvements translated into better hardware use. 

References

[1] Chowdhery, A., et al. (2022). PaLM: Scaling Language Modeling with Pathways. arXiv:2204.02311, Section 4.1 (Training Efficiency).

https://arxiv.org/html/2204.02311v5#S4.SS1

[2] PyTorch contributors. (n.d.). torch.nn.functional.scaled_dot_product_attention. PyTorch 2.9 documentation.

https://docs.pytorch.org/docs/2.9/generated/torch.nn.functional.scaled_dot_product_attention.html

[3] PyTorch contributors. (n.d.). torch.compile Troubleshooting: Wrapping constants with tensors. PyTorch 2.9 documentation. https://docs.pytorch.org/docs/2.9/torch.compiler_troubleshooting.html#wrapping-constants-with-tensors

[4] Yang, S., Kautz, J., & Hatamizadeh, A. (2025). Gated Delta Networks: Improving Mamba2 with Delta Rule. International Conference on Learning Representations.

https://arxiv.org/abs/2412.06464

[5] Flash Linear Attention contributors. (n.d.). Flash Linear Attention [Computer software]. GitHub.

https://github.com/fla-org/flash-linear-attention

[6] Braithwaite, D., Yoshida, A., Celente, R., & Gupta, A. (2025, September 15). Muon for Improved Foundation Model Pretraining Data Efficiency. Building Nubank.

https://building.nu.com/muon-for-improved-foundation-model-pretraining-data-efficiency/

[7] Microsoft. (n.d.). Dion [Computer software]. GitHub. Prior work for the same-shape batching strategy.

https://github.com/microsoft/dion

[8] Yoshida, A., Braithwaite, D., Buga, M., Foust, T. (2026, September 03). How we built a benchmarking framework to horizontally accelerate transaction model research.

https://building.nu.com/how-we-built-a-benchmarking-framework-to-horizontally-accelerate-transaction-model-research/

Check our job opportunies