Alternating Bayesian Mixed Integer Optimization for Context Window Extension in Large Language Models Without Tuning Model Parameters

Expand
  • 1 National Center for Applied Mathematics in Chongqing, Chongqing Normal University, Chongqing 401331, China;
    2 School of Mathematical Sciences, Chongqing Normal University, Chongqing 401331, China;
    3 Chongqing Key Lab of Cognitive Intelligence and Intelligent Finance, Chongqing Normal University, Chongqing 401331, China;
    4 School of Science, Xichang University, Xichang 615000, Sichuan, China

Received date: 2025-04-29

  Revised date: 2025-12-02

  Accepted date: 2026-02-26

  Online published: 2026-10-15

Supported by

This work was supported by the Natural Science Foundation of Chongqing Municipality (No. CSTB2023NSCQ-LZX0056) and the Chongqing Graduate Student Research Innovation Project (No. YKC24001).

Abstract

Extending the context window of large language models (LLMs) is crucial for effectively processing long texts, yet existing models typically struggle due to their restricted input lengths. Existing methods for extending context windows mainly include training-based and training-free approaches. However, training-based methods require significant computational resources, while training-free methods typically achieve limited performance. In this paper, we propose a new method to effectively extend the context window of LLMs. This method consists of three key components: First, we conduct an experimental analysis of Rotary Position Embedding (RoPE), a primary positional encoding method used in LLMs, to identify the critical characteristics that influence the context window size and performance of LLMs. Second, based on the analysis results, we formulate a mixed integer black-box optimization model and utilize its optimal solution to determine the best adjustment strategy for RoPE. Third, we develop an alternating Bayesian mixed integer optimization algorithm to solve the model. Extensive experiments show that our method successfully extends the context window of LLMs and outperforms most existing training-based and training-free methods across various tasks.

Cite this article

Jia Liu, Zhi-You Wu, Huan Gao, Peng Hu, Ran Gu . Alternating Bayesian Mixed Integer Optimization for Context Window Extension in Large Language Models Without Tuning Model Parameters[J]. Journal of the Operations Research Society of China, 2026 , 14(3) : 1088 -1114 . DOI: 10.1007/s40305-026-00672-w

References

[1] Bai, Y., Lv, X., Zhang, J., Lyu, H., Tang, J., Huang, Z., Du, Z., Liu, X., Zeng, A., Hou, L., Dong, Y., Tang, J., Li, J.: LongBench: a bilingual, multitask benchmark for long context understanding. In: Proceedings of the 62nd Annual Meeting of the Association for Computational Linguistics (Volume 1: Long Papers), pp. 3119-3137. Association for Computational Linguistics, Bangkok, Thailand (2024)
[2] Bartz-Beielstein, T., Zaefferer, M.: Model-based methods for continuous and discrete global optimization. Appl. Soft Comput. 55, 154-167(2017)
[3] Beltagy, I., Peters, M.E., Cohan, A.: Longformer: the long-document transformer (2020). arXiv:2004.05150
[4] Bull, A.D.: Convergence rates of efficient global optimization algorithms. J. Mach. Learn. Res. 12, 2879-2904(2011)
[5] Chen, S., Wong, S., Chen, L., Tian, Y.: Extending context window of large language models via positional interpolation (2023). arXiv:2306.15595
[6] Chen, Y., Qian, S., Tang, H., Lai, X., Liu, Z., Han, S., Jia, J.: LongLoRA: efficient finetuning of long-context large language models (2024). arXiv:2309.12307
[7] Clark, K., Luong, M.T., Le, Q.V., Manning, C.D.: Electra: pre-training text encoders as discriminators rather than generators (2020). arXiv:2003.10555
[8] Devlin, J., Chang, M.W., Lee, K., Toutanova, K.: BERT: pre-training of deep bidirectional transformers for language understanding. In: Proceedings of the 2019 Conference of the North American Chapter of the Association for Computational Linguistics: Human Language Technologies, pp. 4171-4186. Association for Computational Linguistics, Minneapolis, Minnesota (2019)
[9] Ding, Y., Zhang, L.L., Zhang, C., Xu, Y., Shang, N., Xu, J., Yang, F., Yang, M.: LongRoPE: extending LLM context window beyond 2 million tokens. In: Proceedings of the 41st International Conference on Machine Learning. ICML’24, pp. 1-14. JMLR.org, Vienna, Austria (2024)
[10] Fei, W., Niu, X., Zhou, P., Hou, L., Bai, B., Deng, L., Han, W.: Extending context window of large language models via semantic compression. In: Findings of the Association for Computational Linguistics: ACL 2024, pp. 5169-5181. Association for Computational Linguistics, Bangkok, Thailand (2024)
[11] Frazier, P.I.: A tutorial on Bayesian optimization (2018). arXiv:1807.02811
[12] Fu, Y., Panda, R., Niu, X., Yue, X., Hajishirzi, H., Kim, Y., Peng, H.: Data engineering for scaling language models to 128k context. In: Proceedings of the 41st International Conference on Machine Learning. ICML’24, pp. 14125-14134. JMLR.org, Vienna, Austria (2024)
[13] Gong, Z., Zhou, K., Zhao, X., Sha, J., Wang, S., Wen, J.R.: Continual pre-training of language models for math problem understanding with syntax-aware memory network. In: Proceedings of the 60th Annual Meeting of the Association for Computational Linguistics, pp. 5923-5933. Association for Computational Linguistics, Dublin, Ireland (2022)
[14] Gu, Y., Han, X., Liu, Z., Huang, M.: PPT: pre-trained prompt tuning for few-shot learning. In: Proceedings of the 60th Annual Meeting of the Association for Computational Linguistics, pp. 8410- 8423. Association for Computational Linguistics, Dublin, Ireland (2022)
[15] Huang, Y., Xu, J., Lai, J., Jiang, Z., Chen, T., Li, Z., Yao, Y., Ma, X., Yang, L., Chen, H., Li, S., Zhao, P.: Advancing transformer architecture in long-context large language models: a comprehensive survey (2024). arXiv:2311.12351
[16] Hutter, F., Hoos, H.H., Leyton-Brown, K.: Sequential model-based optimization for general algorithm configuration. In: Proceedings of the 5th International Conference on Learning and Intelligent Optimization. LION’05, pp. 507-523. Springer, Berlin, Heidelberg (2011)
[17] Jin, H., Han, X., Yang, J., Jiang, Z., Liu, Z., Chang, C.Y., Chen, H., Hu, X.: LLM maybe longLM: Selfextend LLM context window without tuning. In: Proceedings of the 41st International Conference on Machine Learning. ICML’24, pp. 22099-22114. JMLR.org, Vienna, Austria (2024)
[18] Lee, H., Park, G., Suh, J., Hwang, S.J.: InfiniteHIP: extending language model context up to 3 million tokens on a single GPU (2025). arXiv:2502.08910
[19] Li, J.: Improving LLM long context understanding via synthetic data and adaptive compression, Master’s thesis, Massachusetts Institute of Technology, Cambridge, MA, USA (2024)
[20] Li, R., Xu, J., Cao, Z., Zheng, H.T., Kim, H.G.: Extending context window in large language models with segmented base adjustment for rotary position embeddings. Appl. Sci. 14(7), 3076(2024)
[21] Li, T., Zhang, G., Do, Q.D., Yue, X., Chen, W.: Long-context LLMS struggle with long in-context learning (2024). arXiv:2404.02060
[22] LocalLLaMA: dynamically scaled rope further increases performance of long context llama with zero fine-tuning (2023). https://www.reddit.com/r/LocalLLaMA/comments/14mrgpr/dynamically_ scaled_rope_further_increases/
[23] LocalLLaMA: NTK-aware scaled rope allows llama models to have extended (8k+) context size without any finetuning and minimal perplexity degration (2023). https://www.reddit.com/r/LocalLLaMA/comments/14lz7j5/ntkaware_scaled_rope_allows_llama_models_to_have/
[24] Pawar, S., Tonmoy, S.M.T.I., Zaman, S.M.M., Jain, V., Chadha, A., Das, A.: The what, why, and how of context length extension techniques in large language models - a detailed survey (2024). arXiv:2401.07872
[25] Peng, B., Quesnelle, J., Fan, H., Shippole, E.: YaRN: efficient context window extension of large language models (2023). arXiv:2309.00071
[26] Rasmussen,C.E.,Williams,C.K.I.:GaussianProcessesforMachineLearning.MITPress,Cambridge, MA, USA (2006)
[27] Shahriari, B., Swersky, K., Wang, Z., Adams, R.P., de Freitas, N.: Taking the human out of the loop: a review of Bayesian optimization. Proc. IEEE 104(1), 148-175(2016)
[28] Shi, H., Xu, Z., Wang, H., Qin, W., Wang, W., Wang, Y., Wang, Z., Ebrahimi, S., Wang, H.: Continual learning of large language models: a comprehensive survey. ACM Comput. Surv. 58(5), 1-42(2026)
[29] Snoek, J., Larochelle, H., Adams, R.P.: Practical Bayesian optimization of machine learning algorithms. In: Proceedings of the 26th International Conference on Neural Information Processing Systems. NIPS’12, pp. 2951-2959. Curran Associates Inc., Red Hook, NY, USA (2012)
[30] Song, M., Zheng, M., Luo, X.: Counting-stars: a multi-evidence, position-aware, and scalable benchmark for evaluating long-context large language models. In: Proceedings of the 31st International Conference on Computational Linguistics, pp. 3753-3763. Association for Computational Linguistics, Abu Dhabi, UAE (2025)
[31] Srinivas,N.,Krause,A.,Kakade,S.,Seeger,M.:Gaussianprocessoptimizationinthebanditsetting:no regret and experimental design. In: Proceedings of the 27th International Conference on International Conference on Machine Learning. ICML’10, pp. 1015-1022. Omnipress, Madison, WI, USA (2010)
[32] Su, J., Ahmed, M., Lu, Y., Pan, S., Bo, W., Liu, Y.: RoFormer: enhanced transformer with rotary position embedding. Neurocomputing 568, 127063(2024)
[33] Vaswani, A., Shazeer, N., Parmar, N., Uszkoreit, J., Jones, L., Gomez, A.N., Kaiser, L., Polosukhin, I.: Attention is all you need. In: Proceedings of the 31st International Conference on Neural Information Processing Systems. NIPS’17, pp. 6000-6010. Curran Associates Inc., Red Hook, NY, USA (2017)
[34] Wang, S., Bai, Y., Zhang, L., Zhou, P., Zhao, S., Zhang, G., Wang, S., Chen, R., Xu, H., Sun, H.: XL3M: a training-free framework for LLM length extension based on segment-wise inference (2024). arXiv:2405.17755
[35] Wang, X., Salmani, M., Omidi, P., Ren, X., Rezagholizadeh, M., Eshaghi, A.: Beyond the limits: A survey of techniques to extend the context length in large language models. In: Proceedings of the Thirty-ThirdInternationalJointConferenceonArtificialIntelligence,IJCAI-24,pp.8299-8307.International Joint Conferences on Artificial Intelligence Organization, Jeju Island, South Korea (2024)
[36] Xiao, C., Zhang, P., Han, X., Xiao, G., Lin, Y., Zhang, Z., Liu, Z., Sun, M.: InfLLM: Trainingfree long-context extrapolation for LLMS with an efficient context memory. In: Advances in Neural Information Processing Systems, pp. 119638-119661. Curran Associates, Inc., Red Hook, NY, USA (2024)
[37] Xu, F., Goyal, T., Choi, E.: Recycled attention: efficient inference for long-context language models (2024). arXiv:2411.05787
[38] Yang, J., Jin, H., Tang, R., Han, X., Feng, Q., Jiang, H., Zhong, S., Yin, B., Hu, X.: Harnessing the power of LLMs in practice: a survey on ChatGPT and beyond. ACM Trans. Knowl. Discov. Data 18(6), 1-32(2024)
[39] Ye, H., Xie, C., Cai, T., Li, R., Li, Z., Wang, L.: Towards a theoretical framework of out-of-distribution generalization. In: Proceedings of the 35th International Conference on Neural Information Processing Systems. NIPS’21, pp. 1-13. Curran Associates Inc., Red Hook, NY, USA (2021)
[40] Yu, Y., Qi, Z., Huang, Y., Wang, W., Liu, W., Chen, R., Pei, J.: Long-context language models fail in basic retrieval tasks without sufficient reasoning steps. In: Findings of the Association for Computational Linguistics: EMNLP 2025, pp. 5615-5634. Association for Computational Linguistics, Suzhou, China (2025)
[41] Zhang, P., Liu, Z., Xiao, S., Shao, N., Ye, Q., Dou, Z.: Long context compression with activation beacon. In: International Conference on Representation Learning, vol. 2025, pp. 101932-101948(2025)
[42] Zhang, Y., Li, J., Liu, P.: Extending LLMs’ context window with 100 samples (2024). arXiv:2401.07004
[43] Zhong, M., Zhang, C., Lei, Y., Liu, X., Gao, Y., Hu, Y., Chen, K., Zhang, M.: Understanding the RoPE extensions of long-context LLMs: an attention perspective. In: Proceedings of the 31st International Conference on Computational Linguistics, pp. 8955-8962. Association for Computational Linguistics, Abu Dhabi, UAE (2025)
[44] Zhu, D., Yang, N., Wang, L., Song, Y., Wu, W., Wei, F., Li, S.: PoSE: efficient context window extension of LLMs via positional skip-wise training. In: International Conference on Representation Learning, vol. 2024, pp. 18940-18954(2024)
Options
Outlines

/

〈 〉