Very Large Language Model Training and Serving: Challenges and Cloud Platform Selection

    This article examines the engineering challenges of training and deploying very large language models. It covers memory wall and communication bottlenecks, long-context extension and reasoning validation, inference throughput and latency optimization, and key criteria for cloud platform selection. The discussion emphasizes measured throughput and memory usage, real-document evaluation, percentile latency, and workload-specific platform selection.

    1. Addressing the Memory Wall and Communication Bottlenecks

    In training models with more than one hundred billion parameters, a single accelerator card usually cannot hold the complete model state, including parameters, gradients, and optimizer states. Under mixed-precision training, optimizer states often consume the most memory. ZeRO (Zero Redundancy Optimizer) partitions these states across multiple cards, with each card storing only its assigned portion. Different ZeRO stages partition different objects. Higher stages reduce per-card memory usage but increase communication volume, so the choice must be balanced against cluster bandwidth.

    3D parallelism combines data parallelism, tensor parallelism, and pipeline parallelism. Tensor parallelism is most sensitive to communication latency and is usually performed within a node over a high-speed interconnect such as NVLink. Pipeline parallelism has less cross-node communication and is suitable for deployment across machines. The number of micro-batches affects the proportion of pipeline bubbles: more micro-batches reduce idle time but increase the memory occupied by activations. When tuning parameters, use measured throughput and memory usage as the basis; theoretical values are only a starting point.

    In clusters with thousands to tens of thousands of accelerator cards, hardware failures occur regularly. Asynchronous checkpointing can reduce training pause time, but checkpoint frequency must balance three costs: the overhead of writing to storage, the number of training steps lost during a failure, and the time required for recovery. Checkpointing too frequently slows training, while checkpointing too sparsely can lose substantial progress in a single failure. The process of isolating abnormal nodes and recovering from the latest checkpoint should be rehearsed regularly. An unrehearsed recovery process may take far longer than expected during a real failure.

    2. Extending Long Context and Validating Reasoning Capability

    Early models’ positional encodings performed reliably only within the training length and degraded noticeably beyond it. Rotary position embedding (RoPE) is a common approach today. There are two common ways to extend its context length: position interpolation, which compresses position indices proportionally so that longer sequences fall within the position range seen during training; and adjusting the base of the rotation frequency. These methods usually require a small amount of continued training on long texts to restore performance. Applying them directly without fine-tuning generally reduces effectiveness.

    The following code only illustrates the calculation logic for position interpolation and should not be used directly in production. Real projects should use the official implementation in their framework.

    1. import torch
    2. def rope_with_position_interpolation(x, positions, scale=4.0, base=10000.0):
    3. # x: [seq_len, dim], dim is even
    4. # scale: position compression factor, e.g. 4 compresses 16K positions into the original 4K training length
    5. dim = x.shape[-1]
    6. inv_freq = 1.0 / (base ** (torch.arange(0, dim, 2).float() / dim))
    7. # Position interpolation: divide position indices by scale before computing rotation angles
    8. angles = torch.outer(positions.float() / scale, inv_freq)
    9. cos = torch.repeat_interleave(torch.cos(angles), 2, dim=-1)
    10. sin = torch.repeat_interleave(torch.sin(angles), 2, dim=-1)
    11. # Rotate adjacent dimension pairs: (x0, x1) -> (-x1, x0)
    12. x_rot = torch.stack([-x[..., 1::2], x[..., 0::2]], dim=-1).flatten(-2)
    13. return x * cos + x_rot * sin

    A model’s effective context window depends on the specific model, extension method, and training data. Publicly reported windows of hundreds of thousands or even millions of tokens usually rely on long-text training data and dedicated long-context evaluations. During selection, test information recall and answer quality using real long documents from the target business scenario. The window length in a parameter table can only serve as a reference.

    For reasoning capability, supervised fine-tuning (SFT) and reinforcement learning from human feedback (RLHF) are the main alignment methods. Data quality is usually more critical than quantity. If incorrect reasoning processes are mixed into training data, the model may learn to produce fluent derivations with wrong conclusions. Chain of Thought (CoT) enables the model to process mathematics, code, and multi-step logic problems step by step, but it cannot eliminate hallucinations. The output reasoning process also needs to be sampled and checked.

    It is advisable to establish an evaluation checklist that includes at least the following: the deduplication rate and fact-checking results of training data, accuracy on standard answers for reasoning tasks, manual review records of hallucination samples, and regression test results on a held-out set. After each change to data or training configuration, the checklist should be run again.

    3. Improving Inference Service Throughput and Reducing Latency

    During autoregressive generation, the size of the KV Cache grows linearly with sequence length and quickly becomes the main memory consumer. PagedAttention divides the KV Cache into fixed-size blocks and allocates them on demand, reducing memory fragmentation caused by reserving large contiguous spaces. This approach can increase the number of requests a single card can handle concurrently, but block size, reservation ratio, and scheduling policy all need to be adjusted according to the actual request length distribution.

    Continuous batching allows new requests to join a batch during generation, while completed requests leave at any time. When request lengths vary widely, it keeps the GPU busier than static batching. The cost is more complex scheduling logic, and the tail latency of an individual request may be affected by other requests in the same batch.

    When evaluating an inference service, observe the following metrics separately: time to first token (TTFT) reflects user waiting time, time per output token (TPOT) reflects generation speed, and throughput reflects the number of tokens processed per unit time. These three constrain one another. For example, increasing batch size usually improves throughput but lengthens TTFT. During stress testing, use request length distributions and concurrency levels close to those in production, and record percentiles such as P95 and P99 rather than only averages.

    Common problems and troubleshooting directions are as follows:

    • Low memory utilization but requests are queued: check the KV Cache reservation ratio and the maximum concurrency limit.
    • TTFT suddenly becomes longer: check whether an extremely long request is filling the batch, or whether the prefill phase and decode phase are competing for compute.
    • Memory keeps rising: check whether cache is correctly released after requests finish, and whether an upper limit is set for extremely long context requests.

    4. Choosing a Cloud Platform for Large Model Applications

    Enterprises usually do not build training clusters from scratch; instead, they use the compute, storage, and inference services provided by cloud platforms. During selection, compare platforms across the following five dimensions:

    1. Compute: accelerator card models, memory capacity, elastic scaling capability, and whether resource supply is stable during peak periods.
    2. Network: interconnect bandwidth and latency between nodes, and whether RDMA is supported. Multi-machine training is most sensitive to this dimension.
    3. Storage: read throughput for training data, latency differences between object storage and file storage, and checkpoint write speed.
    4. Monitoring and operations: visualization and alerting for GPU utilization, memory levels, and request latency, as well as support for autoscaling based on metrics.
    5. Cost: price differences among on-demand, reserved, and spot instances, and billing methods for idle resources.

    The weight of each dimension depends on the business model. Teams focused mainly on training pay more attention to compute and network, while teams focused mainly on inference pay more attention to scaling speed and tail latency. Before selection, it is advisable to run a small-scale trial of your own workload on candidate platforms and verify service level agreements (SLAs) and data compliance requirements.

    5. Conclusion

    Training and deploying very large language models is an engineering problem that requires algorithms, systems, and networks to work together. The training phase needs to address memory and communication issues, the capability phase needs to validate long-context and reasoning performance with real tasks, and the serving phase needs to make trade-offs between throughput and latency. Each technique has applicable conditions. Only by validating numbers on specific workloads and evaluations can you determine whether it suits your business.