Overview

5 Shaping model architectures via width pruning

Width pruning is presented as a way to reshape a language model by removing part of the MLP expansion while preserving the overall Transformer depth and compatibility. The chapter first shows a static, data-free method that ranks neurons by weight magnitude in paired GLU projections, then removes the least important pairs and rebuilds the MLP with smaller linear layers. This produces a slimmer model that keeps the same external structure but has fewer parameters, making it faster and more efficient without changing the attention blocks.

After pruning, the chapter emphasizes that model quality does not degrade uniformly. A broad evaluation reveals that some capabilities collapse sharply, especially perplexity, mathematical reasoning, and general knowledge benchmarks, while other behaviors can improve, including instruction following, truthfulness, and constraint adherence. The overall effect is not merely a worse model, but a different one: less creative and less capable of complex reasoning, yet often more disciplined, focused, and reliable for structured outputs or tool use.

The second half moves from generic pruning to data-driven specialization. By using PyTorch hooks to capture activation norms at the input of the MLP contraction layer, the method combines structural weight scores with real usage on a calibration dataset. Pruning decisions then reflect both what the neurons can do and what they actually do on domain-specific data, yielding specialized variants such as one tuned to formal text and another to SMS-like language. These models show better performance on the data they were calibrated with, while also delivering speed and energy gains, illustrating that pruning can be used not only for compression but also for targeted behavioral shaping.

The complete GLU structure. Information enters with dimension hidden_size (2048 in Llama-3.2-1B) and expands to intermediate_size (8192) via gate_proj and up_proj. The gate_proj output, modulated by SiLU, is element-wise multiplied with up_proj’s output. The result is contracted back to hidden_size by down_proj.
The complete GLU structure. Information enters with dimension hidden_size (2048 in Llama-3.2-1B) and expands to intermediate_size (8192) via gate_proj and up_proj. The gate_proj output, modulated by SiLU, is element-wise multiplied with up_proj’s output. The result is contracted back to hidden_size by down_proj.
Impact of width pruning on perplexity (PPL). Since this is a metric where "lower is better," the bars on the right show severe degradation: removing 40% of the expansion neurons causes perplexity to spike, indicating that the model has lost much of its ability to predict text sequences fluently.
Impact of width pruning on perplexity (PPL). Since this is a metric where "lower is better," the bars on the right show severe degradation: removing 40% of the expansion neurons causes perplexity to spike, indicating that the model has lost much of its ability to predict text sequences fluently.
Degradation across reasoning and knowledge benchmarks. Mathematical reasoning (GSM8K -68.9%) and common sense understanding (HellaSwag -41.3%) suffer the most severe losses, while reading comprehension tasks (BoolQ -1.9%, WinoGrande -4.8%) remain relatively stable.
Degradation across reasoning and knowledge benchmarks. Mathematical reasoning (GSM8K -68.9%) and common sense understanding (HellaSwag -41.3%) suffer the most severe losses, while reading comprehension tasks (BoolQ -1.9%, WinoGrande -4.8%) remain relatively stable.
Unexpected performance gains in instruction-following and truthfulness benchmarks. The pruned model dramatically improves at following precise instructions (IFEval +46.5%) and multi-step reasoning under constraints (MUSR +26.1%), while also becoming more truthful and less prone to generating plausible but incorrect answers (TruthfulQA +13.9% on MC2).
Unexpected performance gains in instruction-following and truthfulness benchmarks. The pruned model dramatically improves at following precise instructions (IFEval +46.5%) and multi-step reasoning under constraints (MUSR +26.1%), while also becoming more truthful and less prone to generating plausible but incorrect answers (TruthfulQA +13.9% on MC2).
Hybrid importance calculation in GLU architecture. The static component combines weight ranges from gate_proj, up_proj, and down_proj. The dynamic component captures activation norms at the input of down_proj, where gated information flows. Both components multiply to produce the final importance score.
Hybrid importance calculation in GLU architecture. The static component combines weight ranges from gate_proj, up_proj, and down_proj. The dynamic component captures activation norms at the input of down_proj, where gated information flows. Both components multiply to produce the final importance score.
Hybrid importance combines structural capacity with activation patterns. Neuron [0] survives with moderate weights (0.9) but high activation (32). Neurons [1] and [2] are removed despite having identical or higher structural scores due to low activations (0.7 and 0.2).
Hybrid importance combines structural capacity with activation patterns. Neuron [0] survives with moderate weights (0.9) but high activation (32). Neurons [1] and [2] are removed despite having identical or higher structural scores due to low activations (0.7 and 0.2).
Activation capture pipeline. The hooks registered in down_proj (1-2) are automatically triggered during the forward pass (3-4), intercept X_d, calculate L2 norms and accumulate them in CPU (5), finally returning an importance dictionary per layer (6-7).
Activation capture pipeline. The hooks registered in down_proj (1-2) are automatically triggered during the forward pass (3-4), intercept X_d, calculate L2 norms and accumulate them in CPU (5), finally returning an importance dictionary per layer (6-7).
Model surgery using hybrid importance. The update_model function (Listing 5.7) iterates over each layer (1-2), calls prune_neuron_pairs (3) that calculates hybrid scores by multiplying structural magnitudes by activation norms (4), selects the top-K neurons and creates new layers (5), replaces the original layers (6), and returns the specialized model (7).
Model surgery using hybrid importance. The update_model function (Listing 5.7) iterates over each layer (1-2), calls prune_neuron_pairs (3) that calculates hybrid scores by multiplying structural magnitudes by activation norms (4), selects the top-K neurons and creates new layers (5), replaces the original layers (6), and returns the specialized model (7).
The dichotomy visualized in Llama-3.2-3B. Panel A shows the progressive collapse of fragile capabilities (knowledge and reasoning) as the expansion ratio decreases. Panel B reveals the paradox: robust capabilities (instruction-following and truthfulness) improve dramatically, with IFEval reaching a peak of 174% of baseline at 1.6x expansion (40% pruning). Performance is normalized to the base model (2.67x expansion = 100%).
The dichotomy visualized in Llama-3.2-3B. Panel A shows the progressive collapse of fragile capabilities (knowledge and reasoning) as the expansion ratio decreases. Panel B reveals the paradox: robust capabilities (instruction-following and truthfulness) improve dramatically, with IFEval reaching a peak of 174% of baseline at 1.6x expansion (40% pruning). Performance is normalized to the base model (2.67x expansion = 100%).

Summary

  • Our width pruning technique modifies LLMs by removing specific neurons from MLP expansion layers in GLU architectures, offering more fine-grained control than depth pruning's aggressive block elimination. This technique can reshape model behavior without destroying all capabilities.
  • In GLU architectures, the gate_proj and up_proj layers work as a synchronized pair. Neurons must be pruned simultaneously in both projections based on a combined importance score.
  • The reconstruction process creates new, smaller Linear layers while preserving connections with attention modules. By maintaining hidden_size dimensions at module boundaries, the surgery remains internal to the MLP block without breaking the Transformer architecture.
  • Data-driven neuron selection combines structural importance (weight magnitudes) with dynamic importance (activation norms). This hybrid approach multiplies a neuron's structural score by its actual usage during calibration, ensuring only neurons that are both structurally significant and actively used survive.
  • PyTorch hooks capture activations at down_proj's input, after the gating mechanism but before dimensionality reduction, using register_forward_hook(). The L2 norm measures activation intensity, rewarding specialist neurons with sharp peaks over those with constant low-level noise.
  • Domain-specialized models emerge from identical pruning percentages applied with different calibration data. A WikiText-calibrated model preserves neurons for formal text processing, while an SMS-calibrated model retains neurons for conversational language, despite sharing the same architecture externally.
  • The efficiency gains from width pruning are most visible in compute-bound scenarios.
  • Energy efficiency gains result from architectural changes, not behavioral modifications. However, width pruning's benefits are limited by the attention module bottleneck.
  • Aligning the resulting intermediate_size to be divisible by 64, 128, or 256 maximizes GPU Tensor Core utilization in compute-bound scenarios. This optimization matters most in production deployments with high traffic on modern GPUs (A100/H100).
  • Research papers "Fragile Knowledge, Robust Instruction-Following" (Martra, 2025) and "CFSP" (Wang et al., 2024) validate the dichotomy between degrading and improving capabilities, and the effectiveness of activation-based importance metrics. The practical implementation adapts their core insights into a simpler hybrid approach that combines structural capacity with dynamic usage.

FAQ

What is width pruning in an LLM, and why use it instead of depth pruning?Width pruning removes neurons from the model’s expanded MLP layers while keeping the Transformer blocks intact. Compared with depth pruning, it is less destructive to the model’s structure and is especially useful when you want to reduce compute, improve inference speed, or specialize behavior without removing whole blocks.
Why does this chapter focus on pruning the MLP expansion size rather than the attention layers?The chapter targets the MLP’s intermediate expansion because it can be reduced without breaking the model’s overall tensor flow. The attention layers still receive the expected hidden-size tensor, so the model remains structurally compatible while shrinking the MLP width.
How are neurons selected for static width pruning?Static pruning uses a weight-magnitude style heuristic. For each neuron pair in the GLU MLP, the method computes a range-based importance score from the weights in gate_proj and up_proj, then keeps the neurons with the highest scores and removes the least important ones.
Why must gate_proj and up_proj neurons be pruned together?Because the two projections work as a coordinated pair in the GLU structure. The gate output modulates the up output before the result is passed onward, so removing a neuron from one without the matching neuron in the other would break that synchronization.
What does the importance score measure in the static pruning method?The score estimates a neuron pair’s transformation potential by measuring the spread of its weights. A larger positive-and-negative weight range suggests the neuron can create stronger activations, so it is considered more important and less suitable for pruning.
How does the chapter reconstruct the MLP after pruning?It creates new smaller Linear layers for gate_proj, up_proj, and down_proj, then copies only the kept rows or columns of the original weights into those layers. This preserves compatibility with the rest of the model while reducing the intermediate size.
Why does the chapter update model.config.intermediate_size after pruning?Updating the config ensures the model’s metadata matches its new architecture. Without this change, downstream tools and libraries could still think the old intermediate size exists, which may cause loading or shape-mismatch errors.
What is the key idea behind the data-driven pruning approach?It combines static weight-based importance with activation information captured from real calibration data. The goal is to keep neurons that are not only structurally important but also actually active on the data you care about.
Why are PyTorch hooks used in the hybrid pruning method?Hooks let the chapter capture activations inside the model during a normal forward pass. Here they record the input to down_proj, compute L2 norms per neuron, and accumulate those values without storing large activation tensors on GPU.
What are the main trade-offs observed after width pruning?Width pruning reduces parameters, speeds up inference, and can lower energy use, but it can also harm reasoning and general knowledge. Interestingly, the chapter shows that some capabilities like instruction-following and truthfulness may improve, so pruning changes the model’s capability profile rather than simply making it worse.

pro $24.99 per month

  • access to all Manning books, MEAPs, liveVideos, liveProjects, and audiobooks!
  • choose one free eBook per month to keep
  • exclusive 50% discount on all purchases
  • renews monthly, pause or cancel renewal anytime

lite $19.99 per month

  • access to all Manning books, including MEAPs!

team

5, 10 or 20 seats+ for your team - learn more


Close
choose your plan

team

monthly
annual
$49.99
$499.99
only $41.67 per month
  • five seats for your team
  • access to all Manning books, MEAPs, liveVideos, liveProjects, and audiobooks!
  • choose another free product every time you renew
  • choose twelve free products per year
  • exclusive 50% discount on all purchases
  • renews monthly, pause or cancel renewal anytime
  • renews annually, pause or cancel renewal anytime
  • Rearchitecting LLMs Rearchitecting LLMs ebook for free
Close
choose your plan

team

monthly
annual
$49.99
$499.99
only $41.67 per month
  • five seats for your team
  • access to all Manning books, MEAPs, liveVideos, liveProjects, and audiobooks!
  • choose another free product every time you renew
  • choose twelve free products per year
  • exclusive 50% discount on all purchases
  • renews monthly, pause or cancel renewal anytime
  • renews annually, pause or cancel renewal anytime
  • Rearchitecting LLMs Rearchitecting LLMs ebook for free