Adapting and Benchmarking Open-Source LLM Architectures Across Model Sizes
Supporting multiple sizes within an open-source LLM family requires more than scaling parameter counts. This article examines how per-layer embeddings, shared KV caches, heterogeneous KV heads, multimodal pipelines, and sparse expert routing affect inference-engine integration. It outlines practical approaches to model export, memory planning, operator fusion, quantization, scheduling, and reproducible benchmarking across edge, desktop, and server deployments.
Adapting and Benchmarking Open-Source LLM Architectures Across Model Sizes
1. Why Multiple Model Sizes Mean More Than Parameter Scaling
Open-source large language model families increasingly span small edge models, mid-sized desktop models, and larger server models. At first glance, these variants may appear to differ mainly in parameter count and layer depth. In practice, however, different sizes often use different combinations of architectural mechanisms.
Some variants prioritize low memory usage and power consumption. Others focus on throughput and multimodal integration. Still others introduce sparse expert routing to increase representational capacity within a given compute budget.
These differences directly affect inference-engine integration. An engine cannot assume that every variant uses the same computational graph with different weights. It must account for:
- Graph branches introduced by dynamic shapes and multimodal inputs.
- Attention variants such as shared KV caches, heterogeneous KV heads, and K=V.
- Lookup, prefetching, and quantization requirements for per-layer embedding tables.
- Load balancing and communication overhead from sparse expert routing.
- Different batching, memory-bandwidth, and power constraints on edge devices, desktops, and servers.
Deployment quality therefore cannot be judged by generation speed alone. A reproducible evaluation should include time to first token, decoding throughput, peak memory, KV cache usage, multimodal preprocessing time, quantization error, long-sequence stability, energy and thermal constraints, and deployment complexity.
2. Architectural Evolution: From Uniform Designs to Combined Mechanisms
Multi-size model families often evolve from relatively uniform architectures through edge-oriented transitional designs to newer architectures that combine several mechanisms. The following table provides an abstract comparison rather than a specification for any particular model family.
| Feature | Earlier architecture | Transitional edge architecture | Newer multi-size architecture |
|---|---|---|---|
| Attention mechanism | Hybrid attention | Hybrid attention | Hybrid attention |
| KV cache | Independent per layer | Shared within layer groups | Shared across larger layer groups |
| Embeddings | Shared embeddings | Direct injection from per-layer embedding lookups | Per-layer embedding lookups with projection-based fusion |
| QKV normalization | Q/K normalization | Q/K/V normalization | Q/K/V normalization with attention scaling |
| V projection | Separate projection | Separate projection | K=V in some configurations |
| KV heads | Uniform | Uniform | Heterogeneous |
| Vision encoding | Vision Transformer | Lightweight vision encoder | Vision Transformer with pooling-based fusion |
| Audio support | None | Audio encoder module | More capable audio encoder module |
| Sparse experts | None | None | Sparse expert routing |
| Distinctive mechanisms | — | Activation sparsity and block structures | Dual positional encodings and heterogeneous KV heads |
The central point is that differences in deployment behavior arise primarily from combinations of mechanisms, not parameter count alone.
Edge variants place greater pressure on memory bandwidth, embedding lookups, and quantization robustness. Server variants emphasize expert routing, batching throughput, and tail latency. Multimodal variants require coordination between vision and audio preprocessing and the language-decoding pipeline.
3. Adapting Three Key Mechanisms
3.1 Per-Layer Embeddings: From Direct Injection to Projection-Based Fusion
Per-layer embeddings introduce lookup-based embedding information at each layer or selected layers, adding representational capacity at relatively low computational cost. Earlier edge-oriented designs tend to inject lookup results directly. Newer designs add a projection step to align the embedding information with the hidden-state channels.
Key integration considerations include:
- Table placement: Large embedding tables may require sharding, persistent accelerator-memory residency, or layer-by-layer scheduling.
- Memory bandwidth: Lookups are bandwidth-sensitive, so edge implementations should avoid repeated copies.
- Quantization precision: Embedding tables need appropriate precision protection to prevent semantic drift from low-bit lookups.
- Operator fusion: Projection, addition, and normalization may be fused to reduce intermediate tensors.
Illustrative pseudocode:
def ple_fuse(token_ids, hidden, layer_id):raw = gather(ple_tables[layer_id], token_ids)projected = linear(raw, ple_proj[layer_id])return hidden + projected
Measure embedding-table cache hit rates, the proportion of execution time spent on lookups, and peak accelerator-memory usage. If lookups become a bottleneck, prioritize table paging, prefetching, and fused operators rather than simply increasing batch size.
3.2 Shared KV Caches: Lower Memory Usage, Greater Coupling
KV cache sharing allows groups of layers to share cache storage, substantially reducing cache usage during long-sequence decoding. Newer architectures may extend sharing across larger groups while introducing heterogeneous KV heads and K=V configurations.
The benefits include lower peak memory and more practical long-context deployment. The trade-off is tighter coupling between layers and more complex cache layouts and write policies.
Important integration considerations include:
- Sharing granularity: Allocate caches by layer group and manage lifetimes through reference counting or copy-on-write where appropriate.
- Heterogeneous KV heads: Different head groups may require different cache layouts and grouped kernels.
- K=V: Removing an independent V projection requires the inference graph to support configurations both with and without that projection.
- Prefix caching and continuous batching: Shared-cache management must prevent cross-request contamination.
Illustrative pseudocode:
def build_shared_kv_cache(layers, group_size):groups = partition_layers(layers, group_size)cache = {}for gid, members in groups.items():cache[gid] = allocate_kv_slot(max_seq_len, num_kv_heads, head_dim)return cache
Benchmark an independent-cache baseline and the shared-cache implementation separately, recording peak memory, decoding throughput, and long-sequence stability.
Shared caches generally reduce memory pressure. However, insufficient kernel grouping can introduce additional scheduling overhead.
3.3 Multimodal Support: Preprocessing Can Bottleneck Edge Deployment
A multimodal architecture typically includes vision and audio encoders, pooling or projection modules, and a language decoder.
The vision pipeline may involve resizing, normalization, image patching, and pooling. The audio pipeline may require resampling, framing, and encoding. On edge devices, preprocessing and encoder execution can become bottlenecks before language decoding does.
Practical integration steps include:
- Run image and audio preprocessing asynchronously, overlapping it with decoding where possible.
- Pool visual tokens to control context length.
- Process audio in segments to avoid peak-memory spikes from long recordings.
- Use memory pools for multimodal temporary buffers to reduce repeated allocations.
def multimodal_encode(image, audio):tokens = []if image is not None:tokens += pool(visual_encoder(preprocess_image(image)))if audio is not None:tokens += pool(audio_encoder(preprocess_audio(audio)))return tokens
4. An Inference-Engine Adaptation Workflow
Model Export
Use a consistent graph representation and explicitly represent dynamic shapes, control flow, and multimodal branches.
Apply operator decomposition and constant folding as appropriate for K=V, heterogeneous KV heads, and per-layer embeddings. Weight-layout conversion should align with cache layouts to avoid runtime reordering.
Memory Planning
Pool KV cache allocations and manage shared layer groups with reference counting. Per-layer embedding tables can remain resident or use paging, depending on memory constraints.
Give multimodal encoders separate temporary buffers. For long sequences, define cache capacity limits and eviction policies.
Operator Fusion
Potential fusion targets include QKV normalization, attention scaling, K=V branches, per-layer embedding projections, and routing computations.
Every fused implementation should have a fallback path. Retain a reference implementation for numerical comparisons.
Quantization
Treat weight quantization, KV cache quantization, and embedding-table quantization as separate decisions.
Protect sensitive components such as attention normalization, routing layers, and embedding projections. Use a small calibration dataset to assess quantization error rather than relying on perplexity alone.
Scheduling
On servers, use continuous batching and prefix caching. On edge devices, prioritize thread affinity and asynchronous preprocessing.
For sparse expert routing, monitor expert loads to prevent heavily used experts from driving up tail latency.
5. Reproducible Benchmarking Instead of Subjective Speed Claims
A single “fast” or “slow” label is not useful when hardware, batch sizes, and sequence lengths differ.
A more reliable approach is to fix the hardware configuration and input distribution, then report results normalized against a baseline. A benchmark record can include:
record = {"hardware": "consistent test environment","batch": 1,"prompt_len": 512,"decode_len": 256,"ttft_ms": None,"decode_tps": None,"peak_mem_mb": None,"kv_mem_mb": None,"ple_lookup_ratio": None,"multimodal_preprocess_ms": None,"quant_error": None}
The evaluation should also cover long-sequence stability, energy consumption, thermal constraints, and deployment complexity.
Typical trends to investigate include:
- Shared KV caches: Lower peak memory for long sequences, with possible scheduling overhead.
- Per-layer embeddings: Greater representational capacity at the cost of additional lookup bandwidth.
- Heterogeneous KV heads: More architectural flexibility, but greater kernel complexity.
- Multimodal edge inference: Preprocessing and encoder execution can dominate latency.
- Sparse experts on servers: Potential throughput benefits, provided routing loads remain balanced and tail latency is controlled.
These are trends to validate under the target workload, not substitutes for measurements.
6. Deployment Recommendations and Conclusion
Edge Devices
Prioritize memory bandwidth and peak memory. Relevant techniques include low-bit quantization, embedding-table paging, shared KV caches, and asynchronous preprocessing.
Desktop Systems
Use batching and prefix caching where appropriate, while balancing execution across GPU and NPU resources.
Servers
Focus on expert parallelism, continuous batching, monitoring and alerting, and long-sequence stability.
For deployments using Baidu AI Cloud, model weights can be placed in object storage and inference services hosted on a container platform. Logging and monitoring services can collect latency, throughput, memory, and error-rate metrics. Confirm the availability of the relevant services in the intended deployment region.
Ultimately, adapting a multi-size open-source LLM family is not just about getting each model to run. It is about running different combinations of architectural mechanisms reliably, with behavior that can be explained and measured.
A reusable engineering approach brings architectural differences, memory planning, operator fusion, quantization, and evaluation into one coherent workflow.
