Quantized Deployment of MoE LLMs on Unified Memory Devices

    This article explains why sizing a Mixture-of-Experts (MoE) model by its active parameters underestimates memory needs. It shows how to estimate weight memory from total parameter count and bit width, describes the numerical issues that can appear when porting MoE routing to local inference frameworks, and provides a checklist for evaluating quantized deployments on end-user devices with unified memory.

    As open-source large language models keep growing in parameter count, Mixture-of-Experts (MoE) architectures have become a popular choice for many teams, because each inference step activates only part of the model’s parameters. However, running models that span hundreds of gigabytes on end-user devices remains a major challenge for developers. Recently, several open-source MoE models at the tens-of-billions-parameter scale and preview versions of new architectures have been released, and the community has tried many approaches to local deployment. Based on these public efforts, this article analyzes the difficulties of quantized deployment on unified memory devices and provides an evaluation method that readers can apply directly.

    1. Memory Bottlenecks and Common Misconceptions in MoE Models

    Consider an open-source MoE model with 320B total parameters, of which 18B are activated per inference step. The model uses a hybrid of linear attention and sparse attention, and it natively supports a 1M-token context. The official recommended deployment method is a high-performance inference server. With FP8 precision, the model weights alone require more than 300 GB of memory.

    Many developers assume that a model with fewer active parameters also needs less memory. This holds for compute but not for memory. When generating each token, an MoE model computes only some of its experts. However, the gating network can route any token to any expert, so the weights of all experts must stay resident in unified memory.

    The memory estimate follows a simple formula:

    Memory (GB) ≈ Total parameters (B) × Bits per parameter ÷ 8

    Using this formula, the pure weight size of the 320B model is:

    • FP8 or 8-bit: about 320 GB
    • 4-bit: about 160 GB

    One team first claimed that the model could run on a thin-and-light laptop. They later retracted this and acknowledged that even very low-bit quantization requires a workstation-class device with large memory. The community reported about 180 GB for configurations between 4-bit and 8-bit. This figure is higher than the pure-weight estimate for 4-bit. It suggests that practical deployments usually use mixed quantization, keeping sensitive layers at higher precision, and that runtime cache and framework overhead must also be counted. When judging whether a device can hold a model, use the memory footprint of all parameters as the baseline, not the active parameter count, and reserve headroom for runtime overhead.

    2. Local Framework Adaptation and Routing Numerical Fixes

    Official inference stacks mainly target cloud servers. When community developers move to local inference frameworks, they often run into numerical problems. Converting the model structure directly into a format that a local framework supports can introduce activation overflow or computation errors.

    While integrating the model into a local multimodal framework, one developer found that reusing the native Transformers routing logic caused activation overflow. The cause is that expert selection in MoE is sensitive to numerical precision. When local frameworks apply graph optimizations or operator fusion, they may not account for the specific order of Top-K selection and Softmax normalization that MoE requires.

    The code below is a simplified version of the community’s fix. Before running it, make sure the following conditions are met:

    • Dependencies: PyTorch 2.x. In the code, F refers to torch.nn.functional.
    • gate_logits has the shape [tokens, num_experts], which holds the score each token gets for each expert.
    • top_k must be less than or equal to num_experts.
    • The input can be float16 or bfloat16. The function converts it to float32 for computation and returns the output in the original dtype.
    • The function returns only the Top-K weights and indices. If you need the full expert weight matrix, use scatter to write the results back into a [tokens, num_experts] tensor. Also decide whether the Top-K weights should be renormalized.
    1. import torch
    2. import torch.nn.functional as F
    3. def stable_moe_routing(gate_logits: torch.Tensor, top_k: int = 2):
    4. # Shape: [tokens, num_experts]
    5. assert gate_logits.dim() == 2 and top_k <= gate_logits.size(-1)
    6. # Cast to float32 to reduce the risk of softmax overflow caused by large logit values
    7. logits_fp32 = gate_logits.float()
    8. topk_logits, topk_indices = torch.topk(logits_fp32, top_k, dim=-1)
    9. # Apply softmax only over the Top-K values, then restore the original dtype
    10. routing_weights = F.softmax(topk_logits, dim=-1).to(gate_logits.dtype)
    11. return routing_weights, topk_indices

    After applying the fix, run two checks. First, compare the Top-K indices and weight errors against a cloud reference implementation. Second, check the output for NaN or Inf values. The 4-bit to 8-bit versions that the community considers relatively stable were released only after the numerical issues in routing and activations were fixed. On-device porting requires handling weight conversion and operator compatibility at the same time.

    3. Practice with a New Architecture That Integrates N-gram Structures

    Another preview model has 176B total parameters, made up of a 125B backbone network and 51B of n-gram embeddings. It activates 6B parameters per token. The n-gram embeddings can be stored in memory as a lookup-table cache, which reduces the amount of dynamic computation.

    The community tested the model on a device with 128 GB of unified memory. The reports show that with mixed 2-bit quantization, the model size is about 37 GB and the inference speed is about 31 tokens/s. With 4-bit quantization, the size is about 74 GB, and the speed is in the low thirties. Public sources do not fully describe the measurement conditions, including the device model, context length, batch size, prompt length, and whether the KV cache is counted. Readers should rerun these tests before citing the numbers.

    These sizes also do not fully match the pure-weight formula. For the 176B model, the pure weights are about 88 GB at 4-bit and about 44 GB at 2-bit. The reported values are lower than these theoretical figures. This suggests that the deployment uses mixed precision, and that the n-gram embeddings may be stored differently.

    After the developers initially integrated image multimodal capability, they found that the generated text was fluent but often wrong on complex logical calculations. Under 2-bit or mixed low-bit quantization, the multimodal alignment layers and the deep reasoning layers may lose a noticeable amount of representation capability. Keeping these layers at higher precision is generally the safer choice.

    More aggressive 1-bit quantization would bring the theoretical pure-weight size to about 22 GB. However, some reports say that certain 1-bit versions suffer from output collapse and loss of semantic coherence. Between compression ratio and output quality, there is a clear inflection point. File size alone cannot show whether a model is usable, so teams need to validate it with their own evaluation sets.

    4. Selection Guidelines and Checklist for On-Device Quantized Deployment

    Under the test conditions described in this article, 4-bit or mixed 8-bit configurations on a 128 GB device offer a fairly good balance. However, this conclusion still needs to be checked against your device’s memory and your task’s accuracy requirements, and it should not be applied directly. The following checklist can help teams evaluate a deployment systematically:

    1. Memory estimation: Calculate pure weight memory as total parameters times bits per parameter, divided by 8. Then add the KV cache, runtime buffers, and system overhead. Use the measured peak memory as the final reference.
    2. Quantization level selection: Start from