How Layered Embeddings Help Solve On-Device AI Memory Bottlenecks
This article introduces layered embeddings as a practical approach to memory constraints in on-device AI. By keeping core Transformer weights resident in accelerator-accessible storage and loading large, sparsely used parameters on demand, layered embeddings can reduce peak memory usage while preserving model capability. The article explains how data movement, prefetching, caching, and quantization must be designed together, and covers memory budgeting, latency trade-offs, engineering best practices, troubleshooting, and suitable deployment scenarios.
Key takeaway: Layered embeddings treat memory as a layered resource
Layered embeddings are not about forcing an entire large model into accelerator memory. Instead, they treat memory as a tiered resource. Core Transformer weights remain resident in accelerator-accessible memory or high-bandwidth cache, while large, sparsely accessed parameters are loaded on demand from CPU memory, host memory, or unified memory.
This approach can reduce peak memory usage without significantly sacrificing model capability. However, data movement, prefetching, caching, and quantization must be included in the same design. Otherwise, an optimization that saves memory can turn into a latency burden.
1. Why on-device AI is often limited by memory
Large language models and multimodal models continue to grow in parameter count, while on-device hardware such as phones, tablets, wearables, vehicles, and smart speakers often has only a few gigabytes of usable memory.
Model weights, activations, KV cache, temporary tensors, framework overhead, and operating system usage all compete for the same memory budget. If the model must remain entirely in accelerator memory, the device may simply not have enough capacity. If the model is aggressively compressed instead, capability may degrade.
Traditional approaches mainly rely on quantization, pruning, and distillation to make models smaller. These methods can reduce both memory and compute requirements, but they often change the model’s precision distribution or expression capacity. Layered embeddings offer another path: they recognize that not all parameters are equally important, and that hardware memory is naturally layered. The goal is not only to compress parameters, but to rearrange where parameters reside and when they are loaded.
| Method | Main benefit | Main cost | Suitable hardware or scenarios |
|---|---|---|---|
| Quantization | Reduces weight and activation bit width, lowering memory and transfer volume | May introduce accuracy loss and requires calibration | Most on-device NPU/GPU/CPU platforms |
| Pruning | Removes redundant structures, reducing parameter count and computation | May reduce expression capacity and requires fine-tuning to recover | Latency-sensitive devices with limited compute |
| Distillation | Transfers capability from a larger model to a smaller model | High training cost, and the capability ceiling is limited by the teacher model | Customized model development |
| Layered embeddings | Preserves larger model capability while reducing peak memory | Requires handling data movement, prefetching, and cache complexity | Memory-constrained on-device platforms with manageable bandwidth |
2. How layered embeddings change memory assumptions
To avoid confusion, the term layered embeddings in this article, also referred to as per-layer embeddings, does not mean only input vocabulary embeddings. It refers to an engineering method that divides parameter residency strategy by Transformer layer, module type, or parameter access frequency.
The focus is not simply “where should a particular embedding table be placed.” Instead, the key questions are:
- Which parameters should remain resident in accelerator-accessible memory?
- Which parameters should be loaded layer by layer?
- Which parameters can be moved out at any time?
More precisely, layered embeddings do not mean putting most parameters on the CPU. Instead, they move the portion of model parameters that is relatively large, sparsely accessed, and suitable for on-demand loading into host memory or unified memory. Meanwhile, core Transformer weights that drive most of the computation remain in high-speed storage accessible to the accelerator.
Different models have very different parameter distributions. For example, input vocabulary embeddings, positional embeddings, layer normalization parameters, and some intermediate-layer weights may occupy a significant portion of total parameters, but they are not all accessed at full scale during inference. Core Transformer layers, by contrast, handle a large amount of matrix multiplication and attention computation and are accessed more frequently.
In practical deployment, it is useful to estimate three types of parameters:
- Core weights: resident in accelerator-accessible memory or high-bandwidth cache to avoid frequent transfers.
- Hot parameters: cacheable parameters, such as those related to the current sequence, current batch, or nearby layers.
- Cold parameters: parameters that can be loaded by layer, by token, or on demand, such as large embedding tables, low-frequency adapter layers, or inactive experts in MoE architectures.
Loading order also needs to be defined. Typically, the core layers required for the current forward pass should be loaded first. Then, subsequent parameters should be prefetched layer by layer according to the computation graph. If embedding tables are used, token lookup should happen first, and only the compact embedding vectors should be sent to the accelerator. The following Transformer layers should then be scheduled layer by layer. If the accelerator cannot hold all layers at once, a double-buffering pattern can be used: compute the current layer while prefetching the next layer, using computation to hide transfer latency.
3. Where parameters should live: discrete accelerator memory is not the same as unified memory
On devices with discrete memory, such as some standalone GPUs, discrete NPUs, or high-bandwidth accelerators, there can be a clear distinction between host memory and accelerator memory. In this case, layered embeddings usually mean that core weights remain resident in accelerator memory, while offloaded parameters reside in CPU-side memory and are moved through explicit copies or DMA transfers.
However, many on-device devices, including phones, tablets, and wearables, use SoC-based unified memory architectures. The CPU, GPU, and NPU often share the same physical memory pool. In this case, it is not accurate to simply say “put parameters into accelerator memory.” A more accurate description is to place parameters into a unified memory region that the accelerator can access, and explicitly manage residency and caching.
Whether memory is truly shared depends on the specific chip, memory controller, and runtime. Whether zero-copy is possible also depends on memory mapping, cache coherence, DMA capabilities, memory attributes, and framework support. Some platforms may support zero-copy or single-copy paths, while others may still require additional copies or memory synchronization. Therefore, unified memory does not mean “free high-speed access.” Developers must validate behavior on the specific chip and memory architecture.
4. Inference path: embedding lookup is only the starting point; layered loading is the key
The inference flow of layered embeddings can be abstracted as follows: CPU-side work performs large table lookups or prepares cold parameters, the accelerator executes high-frequency core computation, and transfer buffers and prefetching mechanisms reduce the number of cross-boundary operations.
The pseudocode below only shows a skeleton for embedding lookup and layered loading. It does not represent a complete model inference path.
# Pseudocode: only shows a skeleton for embedding lookup and layered loading.# It does not represent a complete model inference path.class LayeredEmbeddingModel:def __init__(self, core_weights, cpu_tables, layer_plan):# Core weights remain in an accelerator-accessible region.self.core_weights = to_accelerator(core_weights)# Large table parameters remain in CPU host memory or unified memory.self.cpu_tables = cpu_tables# Layer scheduling plan: which layers stay resident and which are loaded on demand.self.layer_plan = layer_planself.layer_cache = LayerCache()self.transfer_buffer = TransferBuffer()def forward(self, tokens):# 1. Look up tokens on the CPU side and fetch only the required embedding vectors.embeddings = lookup_on_cpu(self.cpu_tables, tokens)# 2. Transfer the compact embedding results to the accelerator via the transfer buffer.embeddings = self.transfer_buffer.to_accelerator(embeddings)# 3. Compute the core Transformer layers in the accelerator.hidden = embeddingsfor layer_id in self.layer_plan.order:if not self.layer_cache.resident(layer_id):# While computing the current layer, prefetch parameters for the next layer.self.prefetch_next_layer(layer_id, hidden.shape)self.layer_cache.load(layer_id)hidden = self.core_weights.apply(hidden, layer_id)return hiddendef prefetch_next_layer(self, layer_id, hidden_shape):# Illustrative example: move next-layer parameters ahead of time# while the current layer is being computed.next_layer = self.layer_plan.get(layer_id + 1)if next_layer:self.transfer_buffer.prefetch(next_layer)
This code illustrates three key points:
- Large table lookups should happen on the CPU or host side as much as possible, and only compact results should be sent to the accelerator.
- The accelerator does not need to hold all parameters. It only needs to hold the layers required for the current computation.
- Prefetching and caching are essential for reducing latency. Synchronous transfer alone is not enough.
5. How to balance memory and latency
Layered embeddings are not free. They convert part of the computational waiting time into data movement. Therefore, before deployment, it is important to establish a verifiable memory budget formula:
Peak memory ≈ core weights + peak activations + KV cache + transfer buffers + quantization overhead
If the device runtime has memory fragmentation, temporary tensors from the framework, or system-reserved memory, an additional safety margin should be added.
The main terms are as follows:
- Core weights: the main Transformer parameters that remain resident in accelerator-accessible memory or high-speed cache.
- Peak activations: activation tensors under the largest batch size and longest sequence length during inference.
- KV cache: a key source of memory growth during autoregressive generation as context length increases.
- Transfer buffers: buffers used for prefetching, double buffering, temporary copies, or mappings.
- Quantization overhead: quantization scales, zero points, temporary dequantization tensors, and alignment padding.
For latency, it is important to monitor the following factors:
- The proportion of time spent on data movement.
- Prefetch hit rate.
- Batch size.
- Sequence length.
- Quantization bit width.
- Memory bandwidth.
- Scheduling overhead.
Any claim that “memory usage drops significantly” or “latency is close to the fully resident baseline” should be validated against specific chip bandwidth, batch size, quantization bit width, and real model measurements. Performance benefits should not be discussed without considering hardware and batching conditions.
6. Engineering best practices and troubleshooting checklist
To use layered embeddings in a real system, the following principles are recommended:
- Divide residency levels reasonably: determine resident locations based on access frequency and parameter size. High-frequency, small-sized, and critical-path parameters should stay higher in memory hierarchy. Low-frequency, large-sized, and on-demand parameters should be offloaded.
- Use batching and prefetching: combine scattered lookups into batch operations, and prefetch the next layer while computing the current layer to reduce accelerator idle time.
- Coordinate with quantization: apply low-bit quantization to offloaded parameters to reduce transfer volume and memory usage, but verify accuracy regression.
- Model the memory budget: account for core weights, peak activations, KV cache, transfer buffers, and quantization overhead item by item to avoid out-of-memory failures after deployment.
- Drive iteration with profiling: use general monitoring, alerting, and performance analysis tools to locate transfer bottlenecks, and adjust residency strategy based on data rather than intuition.
A minimal checklist can include five items:
- Does the memory budget cover peak activations and KV cache?
- Has CPU-to-accelerator bandwidth been measured?
- Does the prefetch hit rate meet expectations?
- Is the batch size large enough to amortize transfer overhead?
- Is a fallback threshold defined?
A troubleshooting checklist is also important. If any of the following situations occur, negative returns should be suspected:
- The accelerator frequently waits for data, CPU utilization is high, but NPU/GPU utilization is idle.
- Small-batch inference causes too many transfers, and end-to-end latency is higher than the fully resident baseline.
- CPU-to-accelerator bandwidth is insufficient, and transfer time takes up too large a share of end-to-end time.
- Frequent mapping or copying under unified memory causes memory jitter, reclamation pressure, or cache coherence overhead.
- Latency SLOs are strict, and layered loading introduces obvious tail latency.
In such cases, fallback options can be considered: reduce the number of offloaded parameters and keep more layers in accelerator memory; increase quantization compression; switch to full residency with a smaller model; adjust layer partitioning and move critical-path layers higher; increase batch size and transfer buffer capacity; or choose a different hardware platform. Layered embeddings are not a silver bullet. They are one strategy in the on-device deployment toolbox and should be used together with quantization, pruning, distillation, sparsification, and KV cache optimization.
7. Suitable scenarios and deployment guidance
Layered embeddings are most suitable for on-device scenarios where memory is constrained but strong model capability is still desired. Examples include offline intelligent assistants, local speech understanding, on-device multimodal recognition, privacy-sensitive inference, and in-vehicle cockpit assistants. It is particularly suitable for models where core weights can remain resident and cold parameters can be loaded in a streaming manner.
Common questions:
Which chips are suitable for layered embeddings?
Platforms with relatively high memory bandwidth, support for asynchronous transfer, or unified memory cache management are suitable, including certain CPU, GPU, NPU, or SoC platforms. Suitability must be determined based on the specific chip’s bandwidth, memory architecture, and operator support.What are common causes of performance regression?
Common causes include excessive transfer frequency, too-small batch size, insufficient prefetch hit rate, lack of quantization coordination, cache jitter, bandwidth bottlenecks, and unmet conditions for zero-copy in unified memory.How should deployment work under unified memory?
Developers should explicitly define an accelerator-accessible cache region, keep core layers resident, load cold parameters on demand, use single-copy or zero-copy paths where possible, and limit transfer buffer size to avoid consuming too much unified memory.When should layered embeddings not be used?
If hardware bandwidth is extremely low, latency SLOs are extremely strict, inter-layer dependencies prevent parallelism, or transfer overhead cannot be hidden by computation, it is better to prioritize full residency, quantization, or a smaller model.
8. Conclusion
The value of layered embeddings is that it turns the hardware fact that memory is a layered resource into an actionable engineering method. It does not promise that all devices can run larger models at zero cost. Instead, through resident core weights, on-demand loading of cold parameters, prefetch buffers, and coordinated quantization, it seeks a balance between memory and latency.
For developers facing the problem that “the model is too large and the device is too small,” layered embeddings are worth evaluating as an important option for on-device AI deployment, along with practical testing and validation.
