Skip to main content
Redhat Developers  Logo
  • AI

    Get started with AI

    • Red Hat AI
      Accelerate the development and deployment of enterprise AI solutions.
    • AI learning hub
      Explore learning materials and tools, organized by task.
    • AI interactive demos
      Click through scenarios with Red Hat AI, including training LLMs and more.
    • AI/ML learning paths
      Expand your OpenShift AI knowledge using these learning resources.
    • AI quickstarts
      Focused AI use cases designed for fast deployment on Red Hat AI platforms.
    • No-cost AI training
      Foundational Red Hat AI training.

    Featured resources

    • OpenShift AI learning
    • Open source AI for developers
    • AI product application development
    • Open source-powered AI/ML for hybrid cloud
    • AI and Node.js cheat sheet

    Red Hat AI Factory with NVIDIA

    • Red Hat AI Factory with NVIDIA is a co-engineered, enterprise-grade AI solution for building, deploying, and managing AI at scale across hybrid cloud environments.
    • Explore the solution
  • Learn

    Self-guided

    • Documentation
      Find answers, get step-by-step guidance, and learn how to use Red Hat products.
    • Learning paths
      Explore curated walkthroughs for common development tasks.
    • Guided learning
      Receive custom learning paths powered by our AI assistant.
    • See all learning

    Hands-on

    • Developer Sandbox
      Spin up Red Hat's products and technologies without setup or configuration.
    • Interactive labs
      Learn by doing in these hands-on, browser-based experiences.
    • Interactive demos
      Click through product features in these guided tours.

    Browse by topic

    • AI/ML
    • Automation
    • Java
    • Kubernetes
    • Linux
    • See all topics

    Training & certifications

    • Courses and exams
    • Certifications
    • Skills assessments
    • Red Hat Academy
    • Learning subscription
    • Explore training
  • Build

    Get started

    • Red Hat build of Podman Desktop
      A downloadable, local development hub to experiment with our products and builds.
    • Developer Sandbox
      Spin up Red Hat's products and technologies without setup or configuration.

    Download products

    • Access product downloads to start building and testing right away.
    • Red Hat Enterprise Linux
    • Red Hat AI
    • Red Hat OpenShift
    • Red Hat Ansible Automation Platform
    • See all products

    Featured

    • Red Hat build of OpenJDK
    • Red Hat JBoss Enterprise Application Platform
    • Red Hat OpenShift Dev Spaces
    • Red Hat Developer Toolset

    References

    • E-books
    • Documentation
    • Cheat sheets
    • Architecture center
  • Community

    Get involved

    • Events
    • Live AI events
    • Red Hat Summit
    • Red Hat Accelerators
    • Community discussions

    Follow along

    • Articles & blogs
    • Developer newsletter
    • Videos
    • Github

    Get help

    • Customer service
    • Customer support
    • Regional contacts
    • Find a partner

    Join the Red Hat Developer program

    • Download Red Hat products and project builds, access support documentation, learning content, and more.
    • Explore the benefits

Sparse fine-tuning for accelerating large language models with DeepSparse

October 12, 2023
Robert Shaw Michael Goin
Related topics:
Artificial intelligence
Related products:
Red Hat AI

    The arrival of capable open source large language models (LLMs) like MosaicML’s MPT and Meta’s Llama 2 has made it easier for enterprises to explore generative AI to address their business challenges. Yet, adoption of open-source models for commercial applications is still hampered by two key problems:

    • First, out-of-the-box LLMs often struggle with domain-specific tasks in business settings, especially if proprietary knowledge, that is not available on the Internet, is required.
    • Second, LLMs are, well, large, which make production deployments cumbersome and expensive.

    In our recent paper, Sparse Fine-Tuning for Inference Acceleration of Large Language Models, Neural Magic and the Institute of Science and Technology Austria (ISTA) collaborated to explore how fine-tuning and sparsity can come together to address these issues, to enable accurate models that can be deployed on CPUs.

    Pareto frontier of performance / accuracy trade-off on GSM8k. At 60% Sparse-INT8, we achieve ~7x speedup vs. Dense-FP32 with no accuracy drop.
    8-Core AVX-512 VNNI System

    Experimental setup

    In our experiment, we studied MPT-7B and the GSM8k dataset.

    GSM8k is a dataset of high-quality and diverse grade school math problems that is extremely challenging for LLMs. For instance, in zero-shot mode, the base MPT-7B model completely fails with an accuracy of 0%. While accuracy on grade school math is not a particularly interesting application, GSM is an example of a common problem organizations encounter when they try to adopt LLMs for business applications: the base LLMs often do not know how to solve specialized tasks.

    Question: Natalia sold clips to 48 of her friends in April, and then she sold half as many clips in May. How many clips did Natalia sell altogether in April and May?
    
    Answer: Natalia sold 48/2 = <<48/2=24>>24 clips in May. Natalia sold 48+24 = <<48+24=72>>72 clips altogether in April and May. #### 72
    A training example in GSM8k. The task requires multi-step reasoning.

    Fine-tuning

    Training LLMs consists of two steps. First, the model is pre-trained on a very large corpus of text (typically >1T tokens). Then, the model is adapted for downstream use by continuing training with a much smaller high quality, curated dataset. This second step is called fine-tuning.

    Fine-tuning is useful for two main reasons:

    • It can teach the model how to respond to input (often called instruction tuning).
    • It can teach the model new information (often called domain adaptation).

    In the case of GSM (as well as for many business use cases), domain adaptation is valuable as the baseline model does not know how to solve the problem. By fine-tuning MPT-7B for two epochs on GSM, which contains just ~7k examples, we can dramatically improve the test set accuracy, as illustrated in Figure 2. 

    Sparse fine-tuning

    While fine-tuning helps to solve the issue of poor accuracy with a base model on GSM8K, the resulting dense model is still cumbersome to deploy, requiring GPUs to reach acceptable performance.

    To address this problem, quantization techniques (like GPTQ from ISTA) have been developed to compress weights to 4 bits almost without loss. However, these methods, reach a limit at around 2-3 bits per weight, at which point it is harder to recover accuracy.

    Weight sparsity, which consists of pruning individual weights from a neural network by setting them to zero, can be combined with quantization to compress models even more. In the past, Neural Magic has pruned smaller models like BERT to >90% sparsity, but it had not been confirmed whether these techniques can be applied to the scale of LLMs.

    Our result demonstrates that we can prune MPT-7B during fine-tuning on GSM8k to ~60% sparsity with quantization and 70% sparsity without quantization with no accuracy drop:.

    DeepSparse: Accelerating sparse-quantized LLMs on CPUs

    Neural Magic DeepSparse is a CPU inference runtime that implements optimizations to take advantage of sparsity and quantization to accelerate inference performance. DeepSparse supports a large variety of model architectures including CNNs like YOLO and encoder-only transformers like BERT. Over the past several months we have adapted DeepSparse to support the decoder-only architecture used by popular models like Llama 2 and MPT with specialized infrastructure to handle KV-caching and new sparse math kernels targeted at the key operations underlying decoder models.

    With DeepSparse, we accelerated the 60% sparse-quantized MPT-7B by ~7x relative to the dense baseline, to reach 26 tokens/second with just 8 CPU cores and 4GB of memory.

     

     

    Conclusion

    In summary, Sparse Fine-Tuning in combination with sparsity-aware inference software, like DeepSparse, unlocks ubiquitous CPU hardware as a deployment target for LLM inference. Using these techniques, businesses can adapt open-source models to their specific in-domain tasks and deploy models using hardware they already own and know how to operate.

    What’s next?

    This research is an example of our continued commitment and focus on industry-leading LLM optimization. We will continue to expand this research and deliver value to customers and the community through fast CPU inferencing of LLMs run on DeepSparse.

    We will launch production support for LLMs across the Neural Magic stack in the coming weeks, along with published benchmarks, example usage, and new models in SparseZoo. Three primary focus areas include:

    • Productizing Sparse Fine-Tuning: We are adapting our research code into SparseML to enable external users to apply Sparse Fine-Tuning to their business datasets.
    • Expanding model support (to Llama 2): We will apply Sparse Fine-Tuning to other model architectures such as the popular Llama 2.
    • Pushing to higher sparsity: We continue to improve our pruning algorithms to reach higher levels of sparsity (and therefore achieve more inference acceleration).

    Want to learn more?

    • Check out DeepSparse running GSM8k live on Hugging Face Spaces.
    • Visit our GitHub to try running LLM inference with DeepSparse.
    Last updated: March 26, 2025

    Recent Posts

    • Debugging image mode with Red Hat OpenShift 4.20: A practical guide

    • EvalHub: Because "looks good to me" isn't a benchmark

    • SQL Server HA on RHEL: Meet Pacemaker HA Agent v2 (tech preview)

    • Deploy with confidence: Continuous integration and continuous delivery for agentic AI

    • Every layer counts: Defense in depth for AI agents with Red Hat AI

    Red Hat Developers logo LinkedIn YouTube Twitter Facebook

    Platforms

    • Red Hat AI
    • Red Hat Enterprise Linux
    • Red Hat OpenShift
    • Red Hat Ansible Automation Platform
    • See all products

    Build

    • Developer Sandbox
    • Developer tools
    • Interactive tutorials
    • API catalog

    Quicklinks

    • Learning resources
    • E-books
    • Cheat sheets
    • Blog
    • Events
    • Newsletter

    Communicate

    • About us
    • Contact sales
    • Find a partner
    • Report a website issue
    • Site status dashboard
    • Report a security problem

    RED HAT DEVELOPER

    Build here. Go anywhere.

    We serve the builders. The problem solvers who create careers with code.

    Join us if you’re a developer, software engineer, web designer, front-end designer, UX designer, computer scientist, architect, tester, product manager, project manager or team lead.

    Sign me up

    Red Hat legal and privacy links

    • About Red Hat
    • Jobs
    • Events
    • Locations
    • Contact Red Hat
    • Red Hat Blog
    • Inclusion at Red Hat
    • Cool Stuff Store
    • Red Hat Summit
    © 2026 Red Hat

    Red Hat legal and privacy links

    • Privacy statement
    • Terms of use
    • All policies and guidelines
    • Digital accessibility

    Chat Support

    Please log in with your Red Hat account to access chat support.