Hierarchical Attention Mechanism in Transformers: GPU Optimization and Regularization Effect
( Pp. 13-23)

More about authors
Veselov Dmitry I. junior researcher, Youth Laboratory of Computer Vision, Department of Artificial Intelligence, Faculty of Information Technology and Big Data Analysis
Financial University under the Government of the Russian Federation
Moscow, Russian Federation Andriyanov Nikita A. Cand. Sci. (Eng.), Associate Professor; Head, Youth Laboratory of Computer Vision, Department of Artificial Intelligence, Faculty of Information Technology and Big Data Analysis; Financial University under the Government of the Russian Federation; Moscow, Russian Federation
Abstract:
The attention mechanism of transformers has quadratic complexity O(n2d), and it is precisely this that limits its use on long sequences. Subquadratic approaches appear to resolve the issue, yet in practice they rarely deliver the promised speedup – the overhead of a particular implementation gets in the way. Our goal was to develop a methodology for low-level GPU optimization of a hierarchical attention mechanism that yields tangible acceleration without degrading language modeling quality. The proposed mechanism couples local attention with a 256-token window and inter-chunk attention built on aggregated segment representations. At the core of the implementation are three fused GPU kernels: they remove intermediate tensor materialization and keep the score matrices in shared memory. Testing was carried out on the WikiText-103 corpus; the model had 16.3 M parameters, and sequence lengths were taken from the set n ∈ {256, 512, 1024}. The optimized version speeds up inference up to 1.77× (n = 1024) and training up to 1.20×, while the practical efficiency coefficient at n = 512 reaches 18% – the upper edge of the 3–14% range typical of such methods. Perplexity dropped by 11% (44.53 vs. 50.11, p < 0.001), which we attribute to the regularization effect of the structural constraints of hierarchical attention.
How to Cite:
Veselov D.I. and Andriyanov N.A. Hierarchical attention mechanism in transformers: GPU optimization and regularization effect. Computational Nanotechnology. 13, 3 (2026), 13–23. DOI: 10.33693/2313-223X-2026-13-3-13-23. EDN: WCEGAU
Reference list:
Bezruchenko A.Yu., Egunov V.A. Study of the efficiency of program optimization methods for parallel computing systems with GPU. Bulletin of Dagestan State Technical University. Technical Sciences. 2023. Vol. 50. No. 4. Pp. 59–74. (In Rus.). DOI: 10.21822/2073-6185-2023-50-4-59-74. EDN: JZSYDM.
Berezhnov N.I., Sirota A.A. Improving attention mechanisms for the transformer architecture in image quality enhancement tasks. Computer Optics. 2024. Vol. 48. No. 5. Pp. 726–733. (In Rus.). DOI: 10.18287/2412-6179-CO-1393. EDN: HXOXQD.
Borisenko D.S. Comparison of natural speech processing algorithms: Longformer-encoder-decoder and Big Bird. Inter­national Journal of Information Technologies and Energy Efficiency. 2024. Vol. 9. No. 6 (44). Pp. 75–79. (In Rus.). EDN: ZOOCTH.
Bulatov A.S., Kuratov Yu.M., Burtsev M.S. Review of the recurrent transformer architecture in the context of neural networks with memory. Proceedings of Moscow Institute of Physics and Technology. 2024. Vol. 16. No. 4 (64). Pp. 5–20. (In Rus.). EDN: TTOVIO.
Gisin V.B. Dynamic attention model in transformers. Digital Solutions and Artificial Intelligence Technologies. 2025. Vol. 1. No. 4. Pp. 35–42. (In Rus.). DOI: 10.26794/3033-7097-2025-1-4-35-42.
Karpov D.A., Konovalov V.P. Encoder-agnostic transformer-type models: Knowledge transfer for conversational tasks in Russian. Speech Technologies. 2023. No. 2. Pp. 64–77. (In Rus.). EDN: HGCSWS.
Kashko V.V., Oleynikova S.A. Effect of dropout regulariza­tion of a deep network on the convergence and stability of the advantage Actor Critic (A2C) policy gradient algo­rithm. Bulletin of Penza State University. 2025. No. 1 (49). Pp. 62–65. (In Rus.). EDN: UDCJBF.
Kopylova Ya.A. Study of methods for optimizing the use of the attention mechanism in neural network architectures. Paradigm. 2025. No. 5-2. Pp. 191–199. (In Rus.). EDN: NEJANF.
Koshelev N.M., Tarlykov A.V., Preobrazhenskiy A.P. Trans­formers and attention mechanisms for financial time series forecasting: Application in investment analysis of the energy sector. Bulletin of Voronezh Institute of High Technologies. 2026. No. 1 (56). (In Rus.). EDN: fdnbdx.
Tatarnikova T.M., Mokretsov N.S. Optimization of knowledge distillation models for language models. Scientific and Technical Journal of Information Technologies, Mechanics and Optics. 2025. Vol. 25. No. 4. Pp. 737–743. (In Rus.). DOI: 10.17586/2226-1494-2025-25-4-737-743. EDN: PSPNOU.
Khusainova A.M., Romanov V.A., Khan A.M. Multilingual machine translation using a hierarchical transformer. Bulletin of Voronezh State University. Series: System Analysis and Information Technologies. 2022. No. 1. Pp. 125–138. (In Rus.). DOI: 10.17308/sait.2022.1/9207. EDN: UZTTNL.
Bae J., Cheon B.D., Kim H.Y. Pro-attention: Efficient probability distribution matching-based attention through feature space conversion. IEEE Access. 2022. Vol. 10. Pp. 131192–131201. DOI: 10.1109/access.2022.3229055. EDN: SMLRFM.
Dai Z., Lai G., Yang Y., Le Q.V. Funnel-transformer: Filtering out sequential redundancy for efficient language processing. Advances in Neural Information Processing Systems (NeurIPS). 2020. Vol. 33. Pp. 4271–4282. DOI: 10.48550/arXiv.2006.03236.
Dao T. FlashAttention-2: Faster attention with better parallelism and work partitioning. In: International Conference on Learning Representations (ICLR). 2024. DOI: 10.48550/arXiv.2307.08691.
Dao T., Fu D.Y., Ermon S. et al. FlashAttention: Fast and memory-efficient exact attention with IO-awareness. Advances in Neural Information Processing Systems (NeurIPS). 2022. Vol. 35. Pp. 16344–16359. DOI: 10.48550/arXiv.2205.14135.
Loshchilov I., Hutter F. Decoupled Weight Decay Regularization. In: International Conference on Learning Representations (ICLR). 2019. DOI: 10.48550/arXiv.1711.05101.
Park T., Kim H.Ch. Improving systematic generalization of linear transformer using normalization layers and orthogonality loss function. Mathematics. 2024. Vol. 12. No. 21. P. 3390. DOI: 10.3390/math12213390. EDN: JWJBUW.
Samonov A. Methods for optimizing the training and fine-tuning of large language models. Intellectual Technologies on Transport. 2024. No. 3 (39). Pp. 5–12. DOI: 10.20295/2413-2527-2024-339-5-12. EDN: SBXKCF.
Tay Y., Dehghani M., Bahri D., Metzler D. Efficient transformers: A survey. ACM Computing Surveys. 2022. Vol. 55. No. 6. Pp. 1–28. DOI: 10.1145/3530811.
Wang X., Zhang H., Zhao Sh. et al. HiBERT: Detecting the illogical patterns with hierarchical BERT for multi-turn dialogue reasoning. Neurocomputing. 2023. Vol. 524. Pp. 167–177. DOI: 10.1016/j.neucom.2022.12.038. EDN: HBYPXI.
Keywords:
transformers, attention mechanism, hierarchical architecture, GPU optimization, language models, subquadratic algorithms.