Understanding Large Language Model Architecture and Parameter Scale
This article breaks down the two fundamental dimensions of large language models: architecture and parameter count. It explains the mainstream decoder-only design, key attention optimizations, dense versus sparse (Mixture-of-Experts) structures, and how positional encoding and normalization affect long-context performance. It also clarifies parameter-counting conventions, memory estimation for weights and KV cache, and the deployment implications of tensor, pipeline, and expert parallelism. Finally, it offers practical guidance on model selection, context budgeting, compression, and cost modeling.
1. Why Architecture and Parameter Scale Are the Two Core Dimensions
When evaluating a model’s capability and cost, two questions are unavoidable: what components it is built from, and how many trainable parameters it contains. The former determines how information flows within and across layers, affecting long-text processing, inference efficiency, and training stability. The latter sets the upper bound on model capacity and directly drives memory usage, throughput, and cost per call. It is worth stressing that parameter count is not equivalent to capability; architectural efficiency, data quality, and training strategy often make a bigger difference.
From an engineering perspective, architecture determines whether a model can run at all, while parameter count determines how many resources it takes to run. Together they form a triangle of constraints among capacity, latency, and cost.
2. Mainstream Architecture Paradigms in Modern LLMs
2.1 The Base Skeleton: Decoder-Only Autoregressive Structure
The dominant approach today is the decoder-only autoregressive structure: an input token sequence is mapped to vectors by an embedding layer, stacked through several Transformer blocks, each containing normalization, an attention sublayer, and a feed-forward sublayer, and finally an output head predicts the probability distribution of the next token. Compared with encoder-decoder structures, it is simpler to implement, uses a unified training objective, and makes it easy to add conversational ability through instruction tuning and preference alignment after pretraining.
A typical forward pass looks like this:
h = embed(tokens) # [B, S, d_model]for layer in blocks: # repeated N timesh = h + attn(norm(h)) # residual connectionh = h + ffn(norm(h)) # position-wise feed-forwardlogits = head(norm(h)) # projection to vocabulary size
2.2 Engineering Refinements to the Attention Mechanism
Vanilla attention scales quadratically with sequence length, so modern implementations introduce several refinements. Grouped-query attention lets multiple query heads share a set of key-value heads, significantly reducing the size of the key-value cache during inference. Rotary position embeddings inject positional information in a relative way, which helps with length extrapolation. Sliding-window and sparse attention localize the visible range of each token. Linear attention and state-space structures reduce complexity to linear order through recurrence. These changes do not alter the essence of weighted attention aggregation, but they determine feasibility in long-context scenarios.
2.3 Dense vs. Sparse: Two Paths to Scaling Capacity
In a dense structure, every parameter is activated on each forward pass, which is intuitive to implement and keeps hardware utilization stable. A sparse structure (commonly Mixture-of-Experts) replaces the feed-forward sublayer with multiple expert networks and a routing module, activating only a few experts per token. This greatly expands total parameter capacity while keeping inference compute roughly unchanged. The cost is uneven routing load, expert-parallel communication overhead, and training instability, which require mechanisms such as capacity factor and load-balancing loss.
2.4 Positional Encoding, Normalization, and Context Extension
Positional encoding has evolved from absolute sinusoidal forms to rotary forms, combined with interpolation and frequency-band scaling to extend the context window. Normalization commonly uses pre-normalization with root mean square normalization to improve numerical stability in deep training, and activation functions typically come from the gated linear unit family. Longer context is not always better: attention dilution and degraded retrieval precision cause “lost in the middle” information loss, so engineering practice more often combines a long window with retrieval augmentation and hierarchical summarization.
3. Parameter Scale Tiers and Counting Conventions
The industry roughly divides models into several magnitude ranges: below one billion parameters suits on-device and high-frequency lightweight tasks; a few hundred million to tens of billions offers a balance between quality and cost and works well as a business workhorse; hundreds of billions and above are mostly used for complex reasoning and long-chain tasks. When discussing parameter count, the convention must be explicit, otherwise the numbers cannot be compared:
- Total vs. activated parameters: the gap can be several times in sparse structures;
- Whether the embedding layer and output head are counted: with a large vocabulary this portion is substantial;
- Precision convention: FP16/BF16 is about 2 bytes per parameter, INT8 about 1 byte, INT4 about 0.5 bytes;
- Additional structures: whether multimodal encoders and adapter modules are counted.
A handy relationship for estimation: weight memory ≈ parameter count × bytes per parameter; usable inference memory must add the key-value cache, roughly 2 × number of layers × number of key-value heads × head dimension × sequence length × batch size × bytes. This explains why long-context, high-concurrency services often put more pressure on memory than the weights themselves.
4. From Architecture to Deployment: Deriving Resources and Cost
Take a dense model as an example. At a scale of tens of billions of parameters in half precision, the weights alone need tens of GB of memory, which a single card can hardly hold. This typically relies on tensor parallelism to split individual matrix multiplications, pipeline parallelism to split layers, and expert parallelism to split sparse branches. Throughput optimization relies on continuous batching, paged key-value cache, and prefix reuse, caching repeated system prompts and document fragments to avoid recomputation.
If an enterprise wants to lower the barrier to self-hosting, it can adopt a combination of general cloud capabilities: a container platform to host inference services and elastic scaling, object storage for models and datasets, a message queue to smooth traffic peaks and troughs, and logging and monitoring with alerting to track latency, error rate, and resource levels. Baidu AI Cloud typically provides such general-purpose capabilities in these scenarios; refer to the official documentation for specific specifications and quotas.
5. Selection and Practical Recommendations
- Define the task and metrics first: clarify whether it is extraction, classification, generation, or multi-step reasoning; the metrics determine the minimum viable scale.
- Use parameter count for initial screening and evaluation for final selection: build a regression test from a small business sample set, focusing on accuracy and format compliance.
- Explicitly plan the context budget: allocate quotas for the system prompt, conversation history, retrieved fragments, and reserved output space to avoid truncation.
- Try compression and acceleration first: quantization, distillation, pruning, and speculative decoding can significantly cut costs with limited quality loss.
- Build a cost model: convert weight memory, key-value cache, parallel communication, and call volume into a unified measure, then compare self-hosted and managed options.
- Preserve replaceability: abstract model calls behind a unified interface to hide architectural differences and enable smooth migration as technology evolves.
Overall, architecture and parameter count are only the starting point. What truly determines real-world results is weighing model capacity, context strategy, inference engineering, and the evaluation system together within a single constraint map.
