From General-Purpose Language Models to Million-Token Contexts

    General-purpose language models are evolving from systems that can hold conversations into systems that can reason for extended periods with verifiable intermediate results. This article explains how long-term pretraining strategies, fine-grained mixture-of-experts architectures, code and mathematics specialization, memory-efficient reinforcement learning, multimodal document alignment, and compressed key-value memory work together to improve efficiency, verifiability, and long-context performance. It also outlines the engineering constraints and evaluation practices required to make million-token contexts genuinely useful.

    General-purpose language models are moving from “can hold a conversation” to “can reason over long periods with verifiable results.” In practice, the biggest engineering gains rarely come from slogans about scaling alone. They depend on whether three conditions can be achieved at the same time: pretraining data and training strategies must be designed for long-term returns; sparse activation must control the computation required by each forward pass without undermining expert specialization; and post-training must stabilize reasoning through memory-efficient reinforcement learning. The following sections trace how these components connect and extend the discussion to attention and cache design for extremely long contexts.

    Pretraining: Long-Term Strategy Over Short-Term Benchmarks

    Dense language models are typically pretrained on trillions of tokens, with parameter counts ranging from several billion to well beyond that scale. The central challenge is that public benchmarks can often be improved through short-term tuning, while coding, mathematics, and multistep reasoning are much more sensitive to data cleaning, deduplication, difficulty distributions, and curriculum-based sampling.

    A long-term strategy treats data processing, contamination removal, quality tiers, and training schedules as compounding assets rather than focusing only on the validation loss for the current training run.

    In practice, training data should be divided into categories such as general web content, high-quality books and academic papers, code repositories, and mathematical derivations. Each category should have its own sampling weight and deduplication threshold. Allocating too much compute too early to synthetic problems that merely appear difficult can cause distribution shift. Introducing reasoning-oriented data too late, however, may leave the model without intermediate steps that can be reinforced during later reinforcement learning.

    Evaluation should cover general understanding, code generation, symbolic manipulation, and long-chain question answering at the same time. This prevents a single metric from dominating training decisions.

    Mixture of Experts: Fine-Grained Partitioning and Shared Experts

    As dense models grow, every inference step must activate the full set of weights, and the cost-effectiveness of additional parameters declines quickly. Mixture-of-experts architectures divide feed-forward layers into multiple experts, with the router activating only a subset for each token.

    Traditional designs often use a small number of large experts. This can lead to router collapse, where a few experts are selected repeatedly while the others remain mostly idle.

    A more stable direction is fine-grained expert partitioning. By splitting one large expert into multiple smaller experts, the router can make decisions at a higher resolution, improving specialization. A shared group of experts can also be made visible to every token. These shared experts handle transformations common across tasks, such as general syntax and shallow semantics, removing universally required capabilities from the competitive routing process.

    This design allows the total parameter count to become very large while activating only a small portion of the model for each token. The activation ratio can often be controlled at roughly the tens-of-percent level, enabling performance close to that of a much larger dense model at a similar activated-compute budget.

    Production implementations require supporting mechanisms, including load-balancing losses, expert capacity limits, and auxiliary-loss annealing. Without them, some experts may become overloaded, creating communication hotspots and unstable training. At the systems level, expert parallelism should be decoupled from data parallelism as much as possible to prevent routing fluctuations from creating pipeline bubbles.

    Code and Mathematics: From General Capability to Executable and Verifiable Results

    After general pretraining, continued pretraining for code and mathematics aims to turn a model that can “talk” into one that can produce correct, executable results.

    For code, the data should cover multiple programming languages and repository-level context. The goal is not merely single-file completion, but also cross-file dependencies, interface constraints, and executable tests. Training data should prioritize repositories with clear licensing and reproducible builds. It should also include aligned samples connecting natural-language documentation, implementations, and tests. This reduces the risk of producing models that imitate comment styles but cannot pass tests.

    Mathematics depends more heavily on step-by-step derivations and symbolic consistency. If supervision is based only on whether the final answer is correct, the intermediate reasoning remains difficult to control. A stronger approach is to include texts with complete derivations during continued pretraining, then use automatically verifiable problems for reinforcement learning during post-training.

    A specialized model should not be treated as an entirely separate system. It should build on a general-purpose foundation while increasing the density and difficulty of domain-specific tokens. Otherwise, improvements in a narrow area may come at the expense of transferability.

    Reinforcement Learning: Group-Relative Advantage Without an Independent Critic

    Methods in the Proximal Policy Optimization family typically maintain both a policy network and a value, or critic, network. This increases memory usage and implementation complexity.

    A more resource-efficient approach is to sample multiple complete responses for the same prompt, estimate advantage from their relative performance within the group, and then update the policy. Group normalization uses the other responses as a baseline, reducing reliance on an independent critic.

    This approach is particularly suitable for tasks such as mathematics and competitive programming, where results can be scored automatically. Rewards may combine final-answer correctness, unit-test pass rates, format compliance, and penalties for excessive length.

    Important implementation considerations include the following:

    • The group must be large enough to reduce the variance of advantage estimates.
    • Excessively long or repetitive hallucinations should receive length or repetition penalties.
    • KL constraints should prevent the policy from moving too far away from the stable region established by supervised fine-tuning.

    When a task cannot be automatically verified, human preferences or a process-reward model may still be necessary. Group-relative advantage is not a universal replacement for these mechanisms.

    For training stability, it is advisable to begin with supervised fine-tuning on high-quality step-by-step demonstrations before entering the reinforcement-learning stage. Starting with random exploration on complex reasoning tasks can destabilize training. When rewards are sparse, rules or lightweight process scoring can be applied to important intermediate steps. However, the system must be monitored for reward hacking, where the model learns to satisfy the reward function without actually solving the problem.

    Multimodal and Document Understanding: Aligning Visual Structure, Not Just Image Patches

    The central challenge in vision-language models is to encode image regions or document layouts as sequences in the same semantic space as text. Document understanding adds further requirements, including tables, multi-column layouts, headers and footers, and references across pages.

    A simple process of splitting an entire image into patches and concatenating them can lose the correct reading order. A more reliable design combines layout analysis with an explicit reading sequence, allowing the language model to perform question answering and information extraction over that sequence.

    Training objectives should go beyond image-text matching. They should also include localization, OCR correction, and the generation of structured outputs based on visual document structure. Otherwise, the model may learn to describe a document without being able to operate on it.

    Toward Million-Token Contexts: Compressed Key-Value Memory and Hierarchical Storage

    As context windows expand from thousands of tokens to hundreds of thousands or even millions, the main bottlenecks are usually the attention key-value cache and long-range noise.

    Possible approaches include compressing keys and values into a low-rank or latent space so that cache growth with sequence length and layer count becomes less costly. Remote context can use sparse or block-wise attention, while nearby context remains densely attended. Document-level summaries and section indexes can also serve as retrievable external memory instead of keeping every original token permanently in the active window.

    A longer context window does not automatically mean that the model can use more information effectively. Long-range retrieval evaluations, preservation of intermediate-position information, and “needle-in-a-haystack” stress tests are necessary. These tests should also detect whether the model focuses mainly on the beginning and end of a context while ignoring its middle.

    Training can use a length curriculum, starting with shorter sequences and gradually introducing longer ones. Long-sequence training should also include explicit supervision that requires alignment across distant sections.

    Conclusion: Treat Efficiency, Verifiability, and Context as One Set of Constraints

    The transition from general-purpose language models to long-context intelligence is not the result of stacking isolated innovations. Dense pretraining establishes the model’s representations. Fine-grained mixture-of-experts architectures control activation costs. Code and mathematics specialization improve executability and verifiability. Group-relative policy optimization lowers the memory cost of reasoning alignment. Multimodal and document-structure alignment expands the types of inputs the model can handle. Key-value compression and hierarchical memory make extremely long contexts more deployable.

    When designing or reviewing a technical roadmap, three questions should always be asked:

    1. How many parameters are activated during each forward pass?
    2. Can the intermediate reasoning be checked automatically?
    3. After the context window is extended, does the model still use information from the middle?

    Including these questions in the training and evaluation checklist is more likely to produce deployable system capabilities than optimizing for a single benchmark.