A Guide to Modern Large Language Model Architectures and Parameter Scale
This article provides a practical framework for understanding modern large language models from an architecture and engineering perspective. It covers decoder-only transformer structures, attention variants, KV cache, feed-forward networks, normalization, positional encoding, dense and sparse expert models, parameter and memory estimation, inference trade-offs, and model selection for business deployment.
Introduction: From Model Families to Architectural Commonalities
When people ask what structure modern large language models use and how large they are, they often start by listing specific model versions. However, from an engineering and architecture perspective, mainstream LLMs differ in parameter scale, context length, inference strategy, training data mixture, and post-training methods, but they are usually built around the same paradigm: decoder-style deep neural networks centered on self-attention. These models learn language, knowledge, reasoning, and generation through large numbers of parameters.
To understand LLMs, it is not enough to ask how many parameters a particular version has. Three core questions matter more:
- What structural modules make up the model: attention, feed-forward networks, normalization, positional encoding, embedding layers, and so on;
- How parameter scale is estimated: dense models and sparse expert models have different parameter compositions;
- How parameters translate into engineering cost: GPU memory usage, inference latency, throughput, and deployment complexity on cloud platforms are all closely related to parameter scale.
This article uses a general technical framework to help enterprise developers, algorithm engineers, and technical decision-makers build a reusable approach for understanding large models.
1. Mainstream Architecture: Decoder-Only Self-Attention Models
Most modern LLMs use a decoder-only autoregressive architecture. The basic objective is to predict the most likely next token given the preceding token sequence. The overall flow can be summarized as:
Raw text↓Tokenizer↓Token sequence↓Token embedding layer↓Multiple Transformer blocks↓Output projection layer / vocabulary logits↓Probability distribution over the next token
The Transformer blocks are what mainly determine the model’s capability ceiling. A typical Transformer block contains several components.
2. Attention Mechanism: The Core of Contextual Understanding
Attention is the key mechanism that allows LLMs to capture long-range dependencies. In decoder-only models, each token position typically has three sets of vectors:
- Query: what the current token needs to attend to;
- Key: what matching information historical tokens provide;
- Value: the actual content to be aggregated after matching.
By calculating the relevance between Query and Key and then performing a weighted sum over Value, the model can dynamically decide which previous positions the current token should attend to.
2.1 Full Attention, Multi-Query Attention, and Grouped-Query Attention
In traditional multi-head attention, each attention head has its own full Key and Value projections. This can create high memory and bandwidth overhead, especially during long-context inference. To improve inference efficiency, several variants are common:
- Full attention: each query head has independent Key and Value projections. It has strong representational capacity but higher inference cost.
- Multi-query attention: multiple query heads share the same Key and Value projections. This reduces memory pressure.
- Grouped-query attention: it sits between full attention and multi-query attention. Multiple query heads share one group of Key and Value projections, balancing effectiveness and efficiency.
The core goal of these designs is not simply to reduce parameters, but to reduce KV cache pressure during long-text inference.
2.2 KV Cache: A Key Engineering Point for Long-Context Inference
During autoregressive generation, each new token requires reading the Key and Value of previous tokens. Recomputing attention over all previous tokens every time would quickly become expensive. Therefore, inference systems usually cache historical Key and Value in memory. This is called KV Cache.
KV cache usage is roughly related to the following factors:
batch size × sequence length × number of layers × key/value dimension × data bytes × 2
The multiplication by 2 is because both Key and Value are cached. In long-context tasks, KV cache can become a more significant memory consumer than the model weights themselves.
3. Feed-Forward Networks: A Major Source of Parameter Capacity and Knowledge Representation
In addition to the attention layer, each Transformer block usually contains a feed-forward network. Its role is to apply nonlinear transformation to the contextual features extracted by the attention layer and increase the model’s representational capacity.
A common structure is “expand dimension - activation - reduce dimension”:
d_model → d_ff → activation function → d_model
Here, d_ff is usually several times larger than d_model, often around 4 times. Because the feed-forward network involves large matrix multiplications, it often accounts for a substantial proportion of model parameters.
3.1 Gated Activation Structures
Many modern models use feed-forward structures with gating mechanisms. For example, they use two parallel projection paths and then perform gated fusion. Compared with ordinary linear transformations, this structure usually has better representational capacity, but parameter computation increases slightly.
From a parameter scale perspective, if the feed-forward hidden dimension is F and the input dimension is D, a standard two-matrix feed-forward layer contains approximately:
2 × D × F
A gated feed-forward layer usually contains three main matrices, so the parameter count is approximately:
3 × D × F
This is also why feed-forward networks often contribute more parameters than attention layers when estimating the size of a large model.
4. Normalization and Residual Connections: Key to Stable Training
Deep neural network training relies heavily on numerical stability. Modern LLMs usually apply normalization and residual connections before and after each sub-layer.
A typical structure is:
x → normalization → attention → residual additionx → normalization → feed-forward network → residual addition
Common normalization methods include layer normalization and RMS normalization. Layer normalization considers both mean and variance, while RMS normalization is usually lighter to compute. Normalization layers themselves usually have few parameters, but they have a clear impact on training stability and convergence speed.
Residual connections allow gradients to flow back more smoothly, making it possible to stack dozens or even hundreds of layers.
5. Positional Encoding: Letting the Model Understand Token Order
Language is inherently sequential data, while self-attention itself is not sensitive to order. Without positional information, a model cannot distinguish differences in word order, such as “the model trains the data” versus “the data trains the model.”
Therefore, positional encoding is a necessary module. Common approaches include:
- Absolute positional encoding: assigns a vector directly to each position;
- Relative positional encoding: focuses on distance relationships between tokens;
- Rotary positional encoding: expresses position and relative relationships through a rotation mechanism and is relatively beneficial for length extrapolation.
Positional encoding design is especially important in long-context scenarios. Models usually have a fixed context length during training, but users may want the model to process longer text in practical applications. In such cases, engineering methods such as positional interpolation, scaling strategies, and sliding windows are often used to improve extrapolation ability.
6. Parameter Scale: Dense Models and Sparse Expert Models
To understand parameter scale, two concepts must be distinguished:
- Total parameters: the sum of all weights in the model;
- Activated parameters: the number of effective parameters that actually participate in computation for each token.
These two values are not always equal.
6.1 Dense Models
In a dense model, every token passes through all parameters of the model. Its characteristics are straightforward architecture and clear deployment path. However, as parameter scale increases, inference computation and memory requirements become more obvious.
A rough relationship is:
larger model → more parameters → higher memory demand → higher inference cost
However, actual cost is also affected by precision, quantization, batching, context length, framework optimization, and other factors.
6.2 Sparse Expert Models
Sparse mixture-of-experts structures use a router to select a small number of experts for each token. This allows the total model capacity to expand without significantly increasing the computation for a single token.
Their characteristics can be summarized as:
very large total parameterssmaller activated parameters per tokencontrollable theoretical computation costbut higher memory, routing, and communication complexity
This type of structure is suitable for scenarios that pursue high capacity and high concurrency efficiency, but deployment requires additional attention to expert distribution, load balancing, memory layout, and scheduling overhead.
7. Parameter Estimation: Replacing Guesswork with Formulas
In engineering practice, quickly estimating parameter scale helps determine deployment feasibility. The following is a general estimation approach that does not target any specific model.
7.1 Main Sources of Parameters
The parameter count of a typical decoder-only model mainly comes from:
- the token embedding layer;
- attention projection layers;
- the feed-forward network;
- the output layer;
- normalization layers and bias terms.
The token embedding layer and output layer may share weights or remain independent.
7.2 Estimation Pseudocode
# Pseudocode: estimate total model parametersfunction estimate_total_params(vocab_size,d_model,n_layers,n_heads,kv_heads,ffn_multiplier,n_experts,top_k,tie_embeddings):head_dim = d_model / n_headskv_dim = kv_heads * head_dim# Attention projection parameters: Query, Key, Value, and Outputattn_params = 2 * d_model * d_model + 2 * d_model * kv_dim# Feed-forward hidden dimensionffn_hidden = d_model * ffn_multiplier# Parameters of a single expert, with gated structure around three matricesexpert_params = 3 * d_model * ffn_hiddenif n_experts <= 1:block_ffn_params = expert_paramselse:block_ffn_params = n_experts * expert_paramstotal_params_per_layer = attn_params + block_ffn_paramsembedding_params = vocab_size * d_modelif tie_embeddings:output_params = 0else:output_params = vocab_size * d_modeltotal_params = embedding_params + n_layers * total_params_per_layer + output_paramsreturn total_params
If you further need to estimate the “effective computational parameters” per token, replace the dense FFN with the activated portion selected by the expert router:
effective_ffn_params ≈ top_k × single expert parameters
However, this is only an approximation. Actual computation is also affected by attention, routing, shared layers, and system optimizations.
8. GPU Memory Estimation: Parameters Are Not the Only Cost
Many teams ask during deployment: “How much GPU memory does a model of this scale need?” In practice, memory usage is mainly composed of the following parts:
model weights+ KV cache+ activations+ framework overhead+ communication buffers+ reserved fragmented space
8.1 Weight Usage
For common floating-point precision, the relationship between parameter count and weight memory usage can be approximated as:
memory usage ≈ parameter count × bytes per parameter
For example:
- half-precision floating point: about 2 bytes per parameter;
- 8-bit integer quantization: about 1 byte per parameter;
- 4-bit quantization: about 0.5 bytes per parameter, but actual usage is affected by quantization granularity, metadata, and alignment.
Therefore, a model with N parameters occupies approximately the following memory for weights in half precision:
N × 2 bytes
However, actual GPU memory usage usually needs to be higher because KV cache and runtime overhead must also be considered.
8.2 KV Cache Estimation
The following pseudocode can be used to estimate KV cache memory:
# Pseudocode: estimate KV cache memoryfunction kv_cache_bytes(batch_size,seq_len,n_layers,kv_heads,head_dim,bytes_per_value):total_cache = batch_size* seq_len* n_layers* kv_heads* head_dim* 2* bytes_per_valuereturn total_cache
Where:
× 2means both Key and Value are cached;bytes_per_valueis related to inference precision;seq_lenmeans that the longer the context, the more noticeable the cache growth.
For long-context, high-concurrency services, KV cache often determines the final throughput capacity that can be supported.
9. The Relationship Between Parameter Scale and Inference Characteristics
Parameter scale directly affects model capability, but it is not the only determining factor. In engineering practice, the following dimensions usually need to be considered together:
9.1 Parameter Scale
Larger parameter counts usually imply stronger knowledge capacity and potential for complex tasks, but they also bring higher memory, computation, and latency pressure.
9.2 Training Data Quality
High-quality data, clear labeling, reasonable data mixtures, and sufficient cleaning often improve practical usability more than simply increasing parameters.
9.3 Post-Training Methods
Methods such as supervised fine-tuning, preference optimization, instruction fine-tuning, and distillation can significantly improve model performance on specific tasks without necessarily changing the underlying parameter scale.
9.4 Context Length
Long-context capability supports tasks such as document analysis, code understanding, and dialogue memory. However, it also increases KV cache, attention computation, and memory pressure.
9.5 Quantization and Distillation
Low-precision inference, knowledge distillation, sparsification, and other techniques can reduce deployment cost to some extent, but they may also introduce accuracy loss or engineering complexity.
10. How to Choose Parameter Scale Based on Business Needs
For enterprise deployment, it is not recommended to pursue “larger parameters are always better.” Instead, model scale should be inferred from business objectives.
10.1 High-Concurrency, Low-Latency Scenarios
For tasks such as intelligent customer service, ticket classification, content summarization, and intent recognition, throughput and cost are usually more important. Such scenarios are suitable for:
- small and medium parameter models;
- quantized inference;
- distilled models;
- batching and caching strategies;
- lightweight context design.
10.2 Complex Reasoning and Long-Document Scenarios
Tasks such as code understanding, report analysis, complex question answering, and multi-step task planning require stronger contextual understanding and reasoning capabilities. Larger parameter models or models with higher activated capacity may be considered, but the following should also be evaluated:
- whether there is sufficient GPU memory;
- whether long context introduces latency;
- whether segmented retrieval can reduce context length;
- whether cache reuse is needed.
10.3 Private Deployment and Controllability Scenarios
Private deployment usually focuses more on data security, network isolation, and independent controllability. In this case, key evaluations include:
- memory usage of weights and KV cache;
- inference framework compatibility;
- logging and monitoring systems;
- model version management;
- data masking and audit capabilities.
11. Cloud Deployment: From Model to Service
Deploying large language models in a cloud environment is usually not a single-point problem but a systems engineering effort. A relatively complete service pipeline includes:
Data and knowledge preparation
Text cleaning, chunking, vectorization, index building, and access control.Model inference service
Model loading, batch scheduling, context management, streaming output, and concurrency control.Storage and logging
Using object storage, file storage, and logging services to store raw data, request logs, and audit records.Monitoring and alerting
Monitoring metrics such as latency, throughput, error rate, GPU memory usage, and queue backlog.Cost and quota governance
Controlling resource consumption through rate limiting, caching, tiered routing, and model fallback.
On cloud platforms, enterprises can usually combine common capabilities such as object storage, container services, message queues, logging services, and monitoring/alerting to build an inference platform. If using Baidu AI Cloud, its compute, storage, container, monitoring, and model service capabilities can also support engineering deployment. The key is to combine model capabilities with cloud-native infrastructure to form an observable, scalable, and governable inference service.
12. Common Misconceptions
Misconception 1: Larger parameters always mean stronger capability
Parameter scale is only one part of capability. Data quality, training objectives, context design, and post-training methods all significantly affect actual performance.
Misconception 2: Total parameters equal computational cost
In sparse expert models, total parameters and activated parameters per token can differ greatly. When estimating deployment cost, it is necessary to distinguish total parameters, activated parameters, and KV cache.
Misconception 3: Quantization always has no loss
Low-precision inference can usually reduce memory and latency, but it may cause changes in accuracy, stability, or compatibility. Sufficient evaluation should be conducted before actual deployment.
Misconception 4: Longer context is always better
Although long context improves information-carrying capacity, it also increases memory usage, latency, and noise interference. A reasonable approach is to combine retrieval augmentation, summarization compression, segmented processing, and caching strategies.
13. Summary
The structure of modern large language models does not depart from the basic principles of deep learning. Instead, it continues to evolve around “stronger contextual understanding, more stable training, and more efficient inference.” When understanding models, the following key points can be considered:
- Architecture level: decoder-only self-attention, feed-forward networks, normalization, and positional encoding form the mainstream backbone;
- Efficiency level: grouped-query attention, KV cache, quantization, and sparse experts are optimization priorities;
- Parameter level: dense models focus on total parameters and inference cost, while sparse models focus on the difference between total parameters and activated parameters;
- Engineering level: memory, latency, throughput, context length, and cloud governance capabilities determine final usability;
- Selection level: evaluation should combine business tasks, cost budgets, and deployment environments rather than simply comparing parameter sizes.
For developers and enterprises, mastering this general analytical framework enables them to quickly assess the capability boundaries, resource requirements, and deployment paths of evolving model architectures from their structural essence.
