liveBook · Manning

What you will learn in Domain-Specific Small Language Models

Efficient AI for local deployment

by Guglielmo Iozzia
Foreword by Matthew R. Versaggi

Chapter by chapter

Chapter 1: Small language models

The introduction explains why LLM hype makes it important to assess models against real capabilities, risks, and business needs rather than expectations.

1.1 What are small language models? · 1.2 The Transformer architecture · 1.3 Areas of application · 1.4 The open source revolution · 1.5 Risks and challenges with generalist LLMs · 1.6 Domain-specific vs. generalist LLMs for business value · 1.7 Summary

What you learn in chapter 1 →

Chapter 2: Tuning for a specific domain

This chapter introduction previews customizing open source foundation models with your own data and notes that most of the book focuses on inference rather than tuning.

2.1 Data preparation · 2.1.1 Data preparation for BERT fine-tuning · 2.1.2 Data preparation for GPT fine-tuning · 2.1.3 Data preparation for RAG · 2.2 Retrieval-augmented generation · 2.3 Fine-tuning · 2.4 LoRA · 2.5 RAG or fine-tuning? · 2.6 Summary

What you learn in chapter 2 →

Chapter 3: End-to-end transformer fine-tuning

The chapter introduces an end-to-end GPT-2 small fine-tuning example for generating Manim code and previews tuning and evaluation.

3.1 Data preparation · 3.2 Fine-tuning · 3.3 Testing the fine-tuned model · 3.4 Domain-specific evaluation · 3.5 Summary

What you learn in chapter 3 →

Chapter 4: Running inference

This chapter introduction previews content generation with SLMs, inference cost estimation, and performance and cost improvements.

4.1 How to generate content · 4.1.1 Text completion · 4.1.2 Few-shot learning · 4.1.3 Code generation · 4.1.4 Evaluating the generated content · 4.2 Calculating inference cost · 4.3 Areas for improvement (cost savings and performance) · 4.3.1 Getting the most from your GPU · 4.3.2 Batching · 4.3.3 Estimating the generation time · 4.3.4 Optimizing GPU use with DeepSpeed · 4.4 Summary

What you learn in chapter 4 →

Chapter 5: Exploring ONNX

Introduces ONNX as a framework relevant to model optimization, quantization, and portability.

5.1 The ONNX format · 5.2 ONNX operators and types · 5.3 The ONNX runtime · 5.4 ONNX runtime providers · 5.5 ONNX for LLMs on CPU · 5.6 ONNX for LLMs on GPU · 5.6.1 ONNX for GPT on GPU · 5.6.2 I/O binding · 5.7 Summary

What you learn in chapter 5 →

Chapter 6: Quantizing for your production environment

The introduction identifies model quantization as important to LLM inference performance and introduces it as the chapter’s focus.

6.1 Transformers precision formats · 6.2 8-bit quantization · 6.2.1 Hands-on 8-bit quantization · 6.2.2 LLM.int8() and quantization · 6.3 8-bit quantization with ONNX · 6.4 4-bit quantization · 6.4.1 4-bit quantization with GPTQ · 6.4.2 4-bit quantization with ggml · 6.5 Summary

What you learn in chapter 6 →

Chapter 7: Generating Python code

The chapter introduces Python code generation as a way to examine specialized open-source LLMs and judge their outputs.

7.1 Using Transformers to generate code · 7.2 Generating Python code with a Transformer architecture · 7.2.1 Python code generation with CodeGen · 7.2.2 Using ONNX with models not supported by Optimum · 7.2.3 Model evaluation · 7.2.4 Python code generation with better models · 7.3 Coding assistance on commodity hardware · 7.4 Summary

What you learn in chapter 7 →

Chapter 8: Generating protein structures

This introduction previews examples of specialized small language models for drug R&D and chemistry, including structure generation and inference optimization.

8.1 Applying Transformers in chemistry · 8.2 From natural language to protein structures · 8.3 Antibody generation with an SLM · 8.4 From CIF files to crystal structures · 8.5 Summary

What you learn in chapter 8 →

Chapter 9: Advanced quantization techniques

The introduction explains why specialized language models can exceed available inference hardware capacity even after quantization, motivating the chapter’s advanced techniques.

9.1 FlexGen · 9.2 SmoothQuant · 9.3 BitNet · 9.4 BitNet and Python · 9.5 Summary

What you learn in chapter 9 →

Chapter 10: Profiling insights

This introduction previews profiling ONNX-ported LLMs, turning profiling data into insights, and optimizing ONNX graphs.

10.1 Profiling ONNX-ported LLMs · 10.2 Transforming raw ONNX profiling data into insights · 10.3 Optimization of ONNX graphs for LLMs · 10.4 Summary

What you learn in chapter 10 →

Chapter 11: Deployment and serving

The chapter introduces a selective survey of popular tools and environments for deploying and serving small, customized language models.

11.1 vLLM · 11.1.1 Offline serving · 11.1.2 Online serving · 11.2 FastAPI · 11.2.1 Benchmarking various models · 11.2.2 Deploying the best-performing model with FastAPI · 11.3 MLC LLM · 11.4 Deployment and inference on Android devices · 11.4.1 MLC LLM framework · 11.4.2 MLLM framework · 11.4.3 Hugging Face Transformers · 11.5 Summary

What you learn in chapter 11 →

Chapter 12: Running on your laptop

Introduces the chapter’s focus on running personal SLM-based assistants directly on a laptop, including offline use.

12.1 Why use a personal local assistant · 12.2 Running an LLM locally with Ollama · 12.2.1 Importing a custom model into Ollama · 12.2.2 User privacy in Ollama · 12.3 Running an LLM locally with LM Studio · 12.4 The LM Studio Python SDK · 12.5 Running an LLM locally with Jan · 12.6 The Cortex local LLM engine · 12.7 Summary

What you learn in chapter 12 →

Chapter 13: Creating end-to-end LLM applications

The chapter introduction contrasts standalone SLM use with larger language-model systems and states why those systems will use domain-specific small models.

13.1 Why LLMs alone aren’t enough · 13.2 Combining a domain-specific SLM with RAG · 13.3 Using a vector database · 13.4 Building an agent · 13.5 Summary

What you learn in chapter 13 →

Chapter 14: Advanced components for LLM applications

This introduction previews chapter 14’s extensions to RAG and agents, building on the systems introduced in chapter 13.

14.1 GraphRAG · 14.1.1 Microsoft’s open source GraphRAG capabilities · 14.1.2 Evaluation metrics · 14.2 RAG + Agentic AI · 14.3 Long- and short-term memory management · 14.4 Summary

What you learn in chapter 14 →

Chapter 15: Test-time compute and small language models

The chapter introduction previews test-time compute, inference tools, and a commodity-hardware example of specializing an SLM with GRPO.

15.1 Test-time compute · 15.2 The OptiLLM inference proxy · 15.3 SLMs with embedded test-time compute · 15.4 Building a reasoning domain-specific SLM · 15.5 Summary

What you learn in chapter 15 →

Concepts explained in this book

These guides are generated from the text of Manning books by Manning's knowledge graph and link to the sections they draw on. The full books are available on liveBook and at manning.com.