Skip to content
← Back to Insights Cybersecurity

Small versus Large Language Models

Gavin Simmons · · 17 min read
Can smaller more specialized models outperform larger ones?

Websites such as Hugging Face and the Ollama model library give anyone access to thousands of language models. Many are small enough to download and run on a well-specified desktop or laptop with a suitable inference engine installed. But is there any point in running such models locally? Cloud-based AI services such as ChatGPT, Microsoft Copilot and Anthropic’s Claude run in data centres with computing resources far beyond anything a home, medium-sized office or factory could install. Their developers rarely publish model sizes, but estimates run to hundreds of billions of parameters, and more than a trillion for GPT-4, against the 4 to 31 billion of the models in this paper’s case study. They are also trained by large teams at a cost few organisations could match. So why run your own AI system?

This paper looks at when it makes sense to build and run your own AI system for a specific purpose. It explains what separates a small language model from a large one, sets out the trade-offs, and then tests them against a demanding use: automated penetration testing. The evidence suggests that a small model fine-tuned for one narrow task can come close to a frontier model at a fraction of the cost. It does not yet show that a small model can carry out a full penetration test on its own.

What Are Language Models?

Artificial intelligence (AI) systems make predictions or decisions that imitate those of a person with expertise in a particular field. To do this reliably, they need a model of the real-world situations relevant to the problem. In machine learning, that model is mathematical: a function whose internal values, called parameters, are adjusted during training until its outputs fit a large body of past data. Once trained, the model can make predictions about new cases, or reach decisions by applying probability thresholds.

Language models apply the same idea to text. They are trained on very large collections of text, typically web pages, books, articles and source code, much of it written by people with expertise in their field. Most are then refined with further training on curated examples and human feedback, so that they answer questions helpfully. A language model generates its response one token (a word or part of a word) at a time, each time predicting the token most likely to follow the question and the text produced so far. Whole paragraphs and pages emerge from repeating that prediction many times.

Small and Large Language Models

Size

The most visible difference between a small language model (SLM) and a large language model (LLM) is size, measured by parameter count. Parameters are the numerical values, learned during training, which determine how the model processes its input, and modern language models have billions of them. There is no agreed threshold at which a model becomes large, and the line moves as hardware becomes more capable. Machine Learning Mastery describes SLMs as having fewer than 10 billion parameters, usually 1 to 7 billion. An Amazon Web Services (AWS) guide puts the limit at typically less than 20 billion and notes that the definition is evolving. Researchers sometimes stretch the term further: the Novee Security study discussed below treats models of up to 31 billion parameters as SLMs. A useful working test is whether a model can run on a single workstation or server. If it needs a data centre, it is large.

On download sites such as Hugging Face, a model’s size is conventionally shown by a suffix in its name. For example, Qwen3.8-27B is a version of the Qwen3.8 model with 27 billion parameters.

Source: https://huggingface.co/models

How small models are built

Size is not the only difference. Many SLMs are built with help from larger models. In knowledge distillation, a small ‘student’ model is trained to reproduce the outputs of a larger ‘teacher’ model. Others are trained partly on synthetic data generated or filtered by larger models: Microsoft’s Phi-3, for example, was trained on carefully filtered, ‘textbook-quality’ synthetic data. These techniques let a small model inherit much of a larger model’s capability without learning directly from noisy raw data. Most SLMs are still general-purpose when released. Their particular strength is that they are cheap enough to specialise, through further training, for one task.

Open weights, closed weights and fine-tuning

Whether a model can be specialised by its user depends on whether its weights are available. Once training is finished, all of a model’s parameters (also called weights) are fixed. An open-weights model is one whose developer publishes those weights for anyone to download, usually under a licence that sets conditions of use. A closed-weights model, such as those behind ChatGPT or Claude, is available only through its developer’s own service, and its weights are never released.

Fine-tuning means continuing to train a finished model on new, task-specific data, adjusting its weights further. With an open-weights model, you can do this on your own hardware and keep the result. With a closed-weights model, you cannot change the weights yourself; at most, some vendors will fine-tune a copy on their own platform, which you can then use only through their service. Small open-weights models are especially well suited to fine-tuning. Techniques such as low-rank adaptation (LoRA), which trains a small set of additional parameters while leaving the original weights untouched, make it affordable on modest hardware.

Relative Advantages and Disadvantages

Size, openness and cost lead to a set of trade-offs. The first table shows where SLMs have the advantage; the second shows where LLMs do.

Where SLMs have the advantage

SLMsLLMs
Can run on a local or smaller device, such as a laptop, desktop, on-premises server or mobile device.Needs far more computing resources: graphics processing units (GPUs), memory and storage. Frontier models generally run on clusters of GPUs in data centres, and closed-weights models are available only as a cloud service.
Generates responses faster on the same hardware, with lower latency and lower running costs.More parameters make each response slower and more expensive to generate on comparable hardware.
When run locally, keeps sensitive data in-house, which helps to meet data-residency and information security requirements, and can even work offline.Using a cloud-hosted LLM means sending prompts and data to the provider. Contract terms and data-residency options vary, and the organisation has less direct control over where its data is processed and stored.
Practical to fine-tune for a specialised task.Broad, general-purpose capability across many fields without task-specific training.

Where LLMs have the advantage

SLMsLLMs
Generally less capable and less accurate, because fewer parameters can capture fewer of the patterns in the training data.Generally more capable and more accurate: more parameters, trained on far more data, can represent more knowledge and finer distinctions.
Tend to lose track of the goal in long conversations or multi-step tasks, and need frequent guidance and refocusing.Better able to keep the end goal in view over a long sequence of exchanges or decisions, helped by larger context windows.

For most general business use, these trade-offs favour the cloud-hosted LLM. The case for an SLM is strongest where the task is narrow, the data is sensitive and a cloud provider’s restrictions get in the way. Penetration testing meets all three conditions, which makes it a useful test case.

Case Study: Agentic AI for Penetration Testing

Agentic AI

In mid-2026, reports emerged of AI models from Anthropic and OpenAI that, during testing, took unauthorised actions on the live internet, including hacking into real websites and services. The UK AI Security Institute recorded 19 such actions across 122 test runs; both companies said the incidents happened under deliberately loosened test conditions. These reports raise an obvious question: how might such AI systems be put to legitimate use in authorised offensive security testing?

This kind of AI goes beyond answering questions in a chat window. The language model, running on an inference engine, is the decision-making ‘brain’ of the system. To act on its decisions without a human carrying out each step, it is placed inside an agent: software that runs the model in a loop, lets it choose actions, calls tools on its behalf (for example a port scanner, a web proxy or a command shell) and feeds the results back so that the model can decide the next step. The tools can run on the same machine or on remote hosts. The Model Context Protocol (MCP) is a widely used open standard for connecting models to tools: an MCP server exposes a set of tools that any compatible agent can call. Using AI in this way is known as agentic AI.

Why build your own system

There are good reasons to build your own AI system for penetration testing. The first is guardrails. Publicly available AI services are designed to refuse requests that look malicious, and a penetration test can look exactly like that: it is an authorised, simulated attack that uses the same tools and techniques as a real attacker, including exploiting weaknesses and bypassing security controls. In Hack The Box’s 2026 benchmark of commercial models on web security challenges, some models’ built-in guardrails ‘occasionally made them hesitate or sanitize their actions’. If you download and adapt your own open-weights model, you can choose one without such restrictions, although the responsibility for keeping its use authorised and in scope then rests entirely with the tester. The second reason is confidentiality: findings, credentials and details of a client’s systems stay on infrastructure you control.

Local SLMs without fine-tuning

At Security Fest 2025 in Gothenburg, Sweden, Thomas Olofsson presented a talk on using local language models to automate red teaming and penetration testing. He demonstrated an MCP server that let agents, driven by a locally hosted SLM, carry out red-teaming tasks. His proof of concept was far from a fully automated penetration test, and human intervention was frequently needed. He described the Python scripts generated by the local models as often very poor, and compared the agents to ‘a bunch of kids running around trying to do stuff’, adding: ‘so you have to still guide the kids in the right way because they’re never doing exactly the right thing.’ He saw the value of AI agents as team members who extend a human team’s capabilities.

Olofsson considered only locally hosted SLMs, specifically the Qwen 3 series, and did not compare them with LLMs. His talk shows the limits of an unaided SLM, but it says nothing about whether a larger model would have been more successful at exploiting a vulnerable server or web application.

A benchmark published by TrustedSec in April 2026 reached a similar conclusion with newer models. Brandon McGrath tested six self-hosted models, from 24 to about 87 billion parameters, against web application challenges including SQL injection, path traversal and authentication bypass. The best, Gemma 4 31B, passed 98.5% of its runs, and every model passed at least 85%. McGrath concluded that local models ‘demonstrate reliable capability at single-step exploit validation’ but ‘fail on multi-step exploitation’: challenges that required extracting data through UNION-based or blind SQL injection scored 0% across hundreds of runs. Like Olofsson, he did not test frontier models.

Fine-tuned SLMs against a frontier model

One study that did compare SLMs directly with a frontier LLM was published by Novee Security in July 2026. Novee tested five open-weights SLMs (Gemma 4 31B and 12B, and Qwen 3.5 27B, 9B and 4B) against a closed-weights frontier model, Claude Opus 4.8. The test set was 100 confirmed cross-site scripting (XSS) vulnerabilities in web applications. For each one, the model had to produce a working proof-of-concept exploit, which an automated validator then replayed. Novee then fine-tuned the three Qwen 3.5 models and tested them again.

Results are reported as pass@3: the probability that at least one of three attempts produces a successful exploit, estimated statistically from the success rate observed over repeated attempts. Figure 1 shows the models before fine-tuning.

Bar chart of pass@3 on 100 XSS targets before fine-tuning. Source: Novee Security

Figure 1. Pass@3 on 100 XSS targets before fine-tuning.

Before fine-tuning, only the two largest SLMs came anywhere near the frontier model, and both still fell well short: Gemma 4 31B and Qwen 3.5 27B each scored 55%, against 99% for Claude Opus 4.8. The 12B and 9B models scored 23% and 10%, and the 4B model 2%.

Novee fine-tuned the three Qwen models by distillation. It collected about 2,000 successful exploit attempts from a stronger teacher model and trained the SLMs on them using LoRA. Figure 2 compares each model before and after fine-tuning.

Bar chart of pass@3 for three Qwen 3.5 models before and after fine-tuning. Source: Novee Security

Figure 2. Pass@3 for the three Qwen 3.5 models before (base) and after fine-tuning.

Fine-tuning improved all three models substantially. The 4B model rose from 2% to 51%, the 9B from 10% to 56% and the 27B from 55% to 82%. Measured over two attempts, Novee reports its fine-tuned 27B model reached about 80% of the frontier model’s exploit rate (78% against 98%) at a cost 6.5 times lower: about US$16 against US$105 for the whole test set, on Novee’s cost assumptions.

Conclusion

An SLM used straight off the shelf is not yet a realistic way to drive agents through an automated penetration test. Olofsson’s demonstration shows how much guidance an unaided local model needs, and that guidance brings little productive benefit if the human tester must always stay one step ahead of the AI. TrustedSec’s results show local models handling single-step exploits reliably but failing at multi-step exploitation, which is where much of a real penetration test lies.

Frontier LLMs are considerably more capable, as Claude Opus 4.8’s 99% pass rate in Novee’s study shows, but they are not yet reliable autonomous testers either. In Hack The Box’s benchmark, every model’s performance fell sharply at medium difficulty, and only two models solved any of the hardest challenges. Frontier models also bring practical drawbacks. They are too large to run in-house and are usually available only as closed-weights cloud services, so details of a client’s systems, vulnerabilities and credentials pass to a third-party provider, whose guardrails may also block legitimate testing.

A higher-end open-weights SLM, fine-tuned for penetration testing, currently looks like the best balance between the limitations of SLMs and the cost and data exposure of a cloud-hosted LLM. Novee’s fine-tuned 27B model reached about 80% of the frontier model’s exploit rate at a cost 6.5 times lower, on infrastructure the organisation controls. Two caveats apply. Novee sells AI-driven penetration testing, so this is a vendor’s own evaluation. More importantly, every task in its test set was a single cross-site scripting exploit. Whether such a model could attack vulnerable hosts autonomously, for example by chaining several vulnerabilities to take complete control of a host as in a capture-the-flag exercise, is considerably more doubtful, and TrustedSec’s multi-step results suggest that it remains out of reach for now.

Glossary

Agent (“AI Agent”): Software that runs a language model in a loop, letting it choose actions, call tools (such as a scanner or command shell) and act on the results, so that it can complete a multi-step task with little or no human input. This is different from an “endpoint agent” in cybersecurity, which is nothing more than a running piece of software that listens for commands sent to it remotely, executes them and reports back information it has gathered.

Agentic AI: The use of AI agents to take actions in the real world. A chatbot only answers questions or generates text.

Benchmark: A standard set of tasks used to measure and compare the performance of different models.

Closed-weights model: A model whose trained weights are kept private by its developer. It can be used only through the developer’s own service or API, and users cannot run or retrain it themselves.

Context window: The maximum amount of text, measured in tokens, that a model can take into account at one time, including the conversation so far.

Distillation (knowledge distillation): A training method in which a smaller ‘student’ model learns to reproduce the outputs of a larger ‘teacher’ model.

Fine-tuning: Further training of an already trained model on task-specific data, adjusting its weights to improve its performance on that task.

Frontier model: One of the most capable models available at a given time, usually a very large, closed-weights LLM from a major developer.

Graphics processing unit (GPU): A processor designed for large numbers of parallel calculations. GPUs are the main hardware used to train and run language models.

Guardrails: Controls built into a model or service that make it refuse, or limit its response to, requests its developer considers harmful.

Inference: Using a trained model to produce an output, such as a response to a prompt. Inference does not change the model’s weights.

Inference engine: Software that loads a trained model and runs inference on it. Ollama and vLLM are examples.

Large language model (LLM): A language model with a very large number of parameters, commonly taken to mean tens or hundreds of billions or more, that usually needs data-centre hardware to run.

Low-rank adaptation (LoRA): A fine-tuning technique that leaves a model’s original weights unchanged and trains a small set of additional parameters, which greatly reduces the hardware needed.

Machine learning: The branch of AI in which systems learn patterns from data instead of following rules written by a programmer.

MCP server: A program that uses the Model Context Protocol to make a set of tools or data sources available to any compatible AI agent.

Model Context Protocol (MCP): An open standard that defines how AI models and agents connect to external tools and data sources.

Open-weights model: A model whose trained weights are published for anyone to download, run and fine-tune, usually under a licence that sets conditions of use. Open weights do not necessarily include the training data or training code.

Parameter (weight): One of the numerical values inside a model, learned during training, that together determine how the model turns its input into an output.

Pass@k: The probability that at least one of k attempts by a model succeeds at a task, estimated statistically from repeated trials.

Small language model (SLM): A language model with relatively few parameters, commonly taken to mean up to about 10 to 30 billion, that can run on a single workstation, server or smaller device.

Synthetic data: Training data generated by another model, as opposed to data collected from real-world sources.

Token: The unit of text a language model reads and writes: a word, part of a word or a punctuation mark.

Training: The process of adjusting a model’s parameters so that its outputs fit a large body of example data.

Sources

  • Benchmarking LLMs for Cybersecurity: Inside HTB AI Range’s First Evaluation (b3rt0ll0, 12 February 2026) — Hack The Box
  • Evaluating Large Language Models Trained on Code (Mark Chen and others, 2021) — arXiv 2107.03374
  • Introduction to Small Language Models: The Complete Guide for 2026 (n.d.) — Machine Learning Mastery
  • Small Language Models for Offensive Security (Noam Kasten and others, 31 July 2026) — Novee
  • Running and Optimizing Small Language Models On-Premises and at the Edge (Chris McEvilly, Fernando Galves and Guy Ben Baruch, 23 June 2025) — AWS Compute Blog
  • Benchmarking Self-Hosted LLMs for Offensive Security (Brandon McGrath, 14 April 2026) — TrustedSec
  • Once Again, OpenAI and Anthropic AI Models Are Going Rogue and Hacking Services (Pranob Mehrotra, 4 August 2026) — Digital Trends
  • Hack in a Box: Local Language Models for Automating Red Teaming and Penetration Testing (Thomas Olofsson, Security Fest, Gothenburg, 2025) — YouTube video recording
GS

Written by

Gavin Simmons, Network Penetration Tester

small language modelslarge language modelspenetration testingagentic aifine-tuning
Related solution SysGuard: Continuous Threat Validation

Want to discuss this topic?

Our team is happy to talk through what this means for your organisation.

Speak to a Specialist