In-Context Learning State Vector with Inner and Momentum Optimization
Dongfang Li, Zhenyu Liu, Xinshuo Hu, Zetian Sun, Baotian Hu, Min Zhang
Abstract
Large Language Models (LLMs) have exhibited an impressive ability to perform In-Context Learning (ICL) from only a few examples. Recent works have indicated that the functions learned by ICL can be represented through compressed vectors derived from the transformer. However, the working mechanisms and optimization of these vectors are yet to be thoroughly explored. In this paper, we address this gap by presenting a comprehensive analysis of these compressed vectors, drawing parallels to the parameters trained with gradient descent, and introduce the concept of state vector. Inspired by the works on model soup and momentum-based gradient descent, we propose inner and momentum optimization methods that are applied to refine the state vector progressively as test-time adaptation. Moreover, we simulate state vector aggregation in the multiple example setting, where demonstrations comprising numerous examples are usually too lengthy for regular ICL, and further propose a divide-and-conquer aggregation method to address this challenge. We conduct extensive experiments using Llama-2 and GPT-J in both zero-shot setting and few-shot setting. The experimental results show that our optimization method effectively enhances the state vector and achieves the state-of-the-art performance on diverse tasks. Code is available at https://github.com/HITsz-TMG/ICL-State-Vector
Ask Lune
Know this paper in minutes, not an afternoon.
Lune can read every page of it and the top-tier papers that cite it, and gives you its claims, its evidence and its limits, each one cited to the paper it comes from. No skimming, no AI slop.
8 top-tier papers have cited it since. Know what they found before your reviewers do.
Lune can draw on
the full paper · the top-tier papers that cite it · related work
Free to start. No credit card required.
Lineage
- Optimization Inspired Few-Shot Adaptation for Large Language Models cites Language Models are Few-Shot Learners
- Take Off the Training Wheels! Progressive In-Context Learning for Effective Alignment cites FlashAttention: Fast and Memory-Efficient Exact Attention with IO-Awareness
- Take Off the Training Wheels! Progressive In-Context Learning for Effective Alignment cites Language Models are Few-Shot Learners
- FlashAttention: Fast and Memory-Efficient Exact Attention with IO-Awareness cites Language Models are Few-Shot Learners
- Unifying Attention Heads and Task Vectors via Hidden State Geometry in In-Context Learning cites Language Models are Few-Shot Learners
- An Explanation of In-context Learning as Implicit Bayesian Inference cites Language Models are Few-Shot Learners
- Understanding Task Vectors in In-Context Learning: Emergence, Functionality, and Limitations cites An Explanation of In-context Learning as Implicit Bayesian Inference
- Understanding Task Vectors in In-Context Learning: Emergence, Functionality, and Limitations cites Language Models are Few-Shot Learners
- Efficient Memory Management for Large Language Model Serving with PagedAttention cites FlashAttention: Fast and Memory-Efficient Exact Attention with IO-Awareness
- Efficient Memory Management for Large Language Model Serving with PagedAttention cites Language Models are Few-Shot Learners
Cited by top-tier papers8
- Unifying Attention Heads and Task Vectors via Hidden State Geometry in In-Context LearningHaolin Yang, Hakaze Cho, Yiqiao Zhong, Naoya InoueNeurIPS 2025 · 11 citations
- Understanding Task Vectors in In-Context Learning: Emergence, Functionality, and LimitationsYuxin Dong, Jiachen Jiang, Zhihui Zhu, Xia NingICLR 2026 · 9 citations
- Context Learning for Multi-Agent DiscussionXingyuan Hua, Sheng Yue, Xinyi Li, Yizhe Zhao et al.ICLR 2026 · 4 citations
- Optimization Inspired Few-Shot Adaptation for Large Language ModelsBoyan Gao, Xin Wang, Yibo Yang, David A. CliftonNeurIPS 2025 · 3 citations
- Take Off the Training Wheels! Progressive In-Context Learning for Effective AlignmentZhenyu Liu, Dongfang Li, Xinshuo Hu, Xinping Zhao et al.EMNLP 2024 · 1 citation
Builds on21
- Language Models are Few-Shot LearnersTom B. Brown, Benjamin Mann, Nick Ryder, Melanie Subbiah et al.NeurIPS 2020 · 64,255 citations
- FlashAttention: Fast and Memory-Efficient Exact Attention with IO-AwarenessTri Dao, Daniel Y. Fu, Stefano Ermon, Atri Rudra et al.NeurIPS 2022 · 5,493 citations
- Model soups: averaging weights of multiple fine-tuned models improves accuracy without increasing inference timeMitchell Wortsman, Gabriel Ilharco, Samir Yitzhak Gadre, Rebecca Roelofs et al.ICML 2022 · 1,464 citations
- An Explanation of In-context Learning as Implicit Bayesian InferenceSang Michael Xie, Aditi Raghunathan, Percy Liang, Tengyu MaICLR 2022 · 1,030 citations
- Efficient Memory Management for Large Language Model Serving with PagedAttentionWoosuk Kwon, Zhuohan Li, Siyuan Zhuang, Ying Sheng et al.SOSP 2023 · 1,016 citations
Related papers
- Why Can GPT Learn In-Context? Language Models Secretly Perform Gradient Descent as Meta-OptimizersDamai Dai, Yutao Sun, Li Dong, Yaru Hao et al.ACL Findings 2023 · 154 citations
- Label Words as Local Task Vectors in In-Context LearningBowen Zheng, Ming Ma, Zhongqiao Lin, Tianming YangACL Findings 2026
- In-Context Learning Creates Task VectorsRoee Hendel, Mor Geva, Amir GlobersonEMNLP Findings 2023 · 43 citations
- Beyond Demonstrations: Dynamic Vector Construction from Latent RepresentationsWang Cai, Hsiu-Yuan Huang, Zhixiang Wang, Yunfang WuEMNLP 2025
- Learning Task Representations from In-Context LearningBaturay Saglam, Xinyang Hu, Zhuoran Yang, Dionysis Kalogerias et al.ACL Findings 2025 · 1 citation
