Deriving Coding-Specific Sub-Models from LLMs using Resource-Efficient Pruning

Laura Puccioni, Alireza Farshin, Mariano Scazzariello, Changjie Wang, Marco Chiesa, Dejan Kostic

Abstract

Large Language Models (LLMs) are increasingly deployed for specialized tasks, yet their immense parameter counts impose significant computational burdens. This paper investigates a resource-efficient methodology for deriving domain-specific sub-models—such as those specialized for Python, Java, or Mathematics—through unstructured pruning. By utilizing the Wanda (Weights and Activations) algorithm with targeted calibration data, we demonstrate that 50% sparse models can be "carved out" of general-purpose LLMs. These sub-models retain high functional accuracy without the need for expensive retraining or fine-tuning. Our findings highlight the importance of calibration data selection and provide evidence of spatial localization for specific tasks within the model's weight matrix.

1. Introduction

Large Language Models (LLMs) have become the backbone of modern AI, but their deployment is often limited by high inference costs and hardware requirements. While pruning is a standard technique to reduce model size, most approaches aim for general-purpose performance, which may retain unnecessary parameters for users focused on specific domains like software engineering or mathematical reasoning.

This research addresses two critical questions: First, can we extract a specialized sub-model (e.g., a "Python-only" version of a 7B model) without the massive computational overhead of retraining? Second, do different domains—such as coding, math, and common sense—occupy distinct structural regions within the model's weight matrix?

2. Methodology

2.1 Pruning Algorithm: Wanda

The researchers utilize Wanda (Weights and Activations), a pruning technique specifically optimized for LLMs. Unlike traditional magnitude pruning, which only considers the absolute value of weights, Wanda evaluates importance by multiplying a weight's magnitude by the norm of its corresponding input activations. This allows the pruning process to account for the dynamic behavior of the model during inference.

2.2 Domain-Specific Calibration

The core innovation lies in the calibration process. Rather than using generic text (e.g., the C4 dataset) to estimate weight importance, the methodology employs tiny, targeted calibration sets consisting of only 128 samples for specific programming languages or domains. This allows the pruning mask to be tailored to the specific activations triggered by that domain.

2.3 Experimental Setup

The study evaluated several 7B and 13B models, including CodeLlama, Mistral, and Gemma-1.1. The researchers induced 50% unstructured sparsity across these models. To analyze the resulting sub-models, they used the Penzai tool for weight mask visualization and Jaccard distance to measure the quantitative shift in "important" regions between different tasks.

3. Datasets and Evaluation

3.1 Calibration and Benchmarking

  • Coding: Calibrated using py_alpaca (Python), code-java, cpp_dataset, and code-javascript. Evaluation was conducted via the HumanEval benchmark.
  • Mathematics: Calibrated using math_qa, math_inst, and math_o, evaluated on GSM8K.
  • Common Sense Reasoning (CSR): Evaluated on hellaswag and ob_qa to test foundational language retention.
  • Translation: Calibrated using wmt14 and o_books (French-English).

4. Key Insights and Results

4.1 The Impact of Calibration

The choice of calibration data is the primary determinant of sub-model performance. A model pruned using Python-specific data performs significantly better on Python tasks than one pruned using generic English text. This suggests that the "importance" of specific weights is highly context-dependent.

4.2 Performance at 50% Sparsity

The researchers successfully created sub-models with 50% sparsity that exhibited minimal performance degradation. For instance, the Gemma-7B coding sub-model experienced only a ~5.83% drop in accuracy compared to the dense version. Interestingly, Gemma-7B proved more resilient to pruning than the domain-specific CodeLlama, likely due to a more robust internal representation from its broader pre-training.

4.3 Logical Overlap and Spatial Specialization

Analysis revealed a significant overlap between the weights utilized for coding and those used for mathematics. Sub-models pruned for math performed surprisingly well on coding tasks, indicating shared underlying "logical reasoning" circuits. Conversely, Jaccard distance analysis provided the first analytical evidence of spatial specialization: the weights critical for translation tasks are physically distinct from those critical for mathematical reasoning.

4.4 Robustness of Common Sense Reasoning

Common Sense Reasoning (CSR) tasks showed consistent accuracy across nearly all pruned versions. This suggests that the weights responsible for basic language understanding are foundational and are consistently retained regardless of the specific domain used for calibration.

5. Limitations and Future Work

Despite the success of this approach, several challenges remain:

  • Hardware Realization: Unstructured sparsity currently requires specialized hardware or software kernels to achieve actual inference speedups on standard GPUs.
  • Static vs. Dynamic Models: The current sub-models are static. Future research could explore dynamic inference systems that swap specialized sub-models in and out based on the prompt, similar to a Mixture of Experts (MoE) architecture.
  • Sparsity Granularity: Future work will investigate higher levels of sparsity and structured (N:M) sparsity patterns to better align with modern hardware acceleration.

6. Conclusion

This research demonstrates that LLMs can be efficiently specialized through domain-specific pruning. By "carving out" sub-models, we can maintain high performance in target domains like coding while significantly reducing the active parameter count. This approach offers a resource-efficient path toward deploying specialized AI agents without the need for exhaustive fine-tuning.

Summary updated

BibTeX
@inproceedings{puccioni2025deriving,
  author = {Laura Puccioni and Alireza Farshin and Mariano Scazzariello and Changjie Wang and Marco Chiesa and Dejan Kostic},
  title = {{Deriving Coding-Specific Sub-Models from LLMs using Resource-Efficient Pruning}},
  booktitle = {Llm4code@icse},
  year = {2025},
}
Figure