Glossary term
LLM Stack
What is the LLM stack?
The LLM stack is the set of layers that make up a production large language model application: the data that feeds it, the model itself, the deployment infrastructure that serves it, and the interface through which it interacts with users or other systems.
B2C products often require a more complex LLM stack to handle the high volume and diversity of user interactions. In contrast, B2B products may prioritize a streamlined stack for efficient, specialized professional workflows.
The LLM stack consists of several layers, each contributing to the overall functionality and performance of the application. Here are the key layers:
-
Data Layer — This layer is responsible for the featurization, storage, and retrieval of relevant information for the model to respond to user queries. It ensures that the model does not have access to data it shouldn't.
-
Model Layer — This layer contains the LLM itself, which is responsible for understanding and generating text based on the input it receives. The model can be trained from scratch, fine-tuned from an open-source model, or accessed via a hosted API.
-
Deployment Layer — This layer handles the challenges of bringing LLM features to production. It includes aspects like security, governance, and orchestration of various components of the LLM infrastructure. Companies operating in this space are often referred to as "LLMOps".
-
Interface Layer — This layer is where the LLM interacts with the world. It's not just about generating text but also about taking actions based on the generated text. For example, an LLM personal assistant might book dinner reservations, or an LLM security analyst might fix permissions on a misconfigured cloud instance.
In addition to these, some sources also mention a Personalization Layer as the highest layer in the language model stack. In this layer, prompt engineering and language model manipulation are used to customize the output and develop a personalized user experience.
Each of these layers interacts with the others, and optimizing the performance of an LLM application involves considering all of these layers together.
How is LLM performance optimized across the stack?
Optimizing LLM performance across the stack means making improvements at every level, from data handling to user interaction, so that each layer works together more efficiently. Common techniques include:
Model Optimization Techniques
- Model Pruning — Trim unnecessary parts of the model to reduce size without significantly impacting performance.
- Quantization — Convert model weights to lower precision formats (e.g., from float32 to bfloat16 or int8) to reduce memory requirements and potentially increase speed.
- Model Distillation — Train a smaller model to mimic the behavior of a larger one, preserving performance while reducing size.
- Parallel Processing — Utilize multi-threading or distributed computing to process data in parallel, speeding up inference times.
- Subword Tokenization — Use efficient tokenization methods to reduce the number of input tokens, which can speed up processing.
Inference Time Reduction
- Batch Processing — Process multiple samples concurrently to make better use of hardware capabilities.
- Lower Precision — Operate at reduced numerical precision to decrease memory demands and potentially speed up computations.
- Memory Optimization — Implement techniques like tensor sharding and mixed precision training to reduce memory consumption.
Retrieval and Prompt Engineering
- Retrieval-Augmented Generation (RAG) — Provide the LLM with access to relevant, domain-specific content to improve context understanding.
- Prompt Engineering — Iteratively experiment with prompts to guide the LLM towards more accurate and relevant outputs.
Fine-Tuning and Iterative Improvement
- Fine-Tuning — Adjust the LLM parameters on a specific dataset to improve performance on tasks relevant to your application.
- Consistent Evaluation — Use consistent metrics to evaluate changes and guide the optimization process.
Hardware and Software Considerations
- GPU and CPU Optimization — Use GPU-accelerated libraries and data preprocessing for GPU efficiency, and employ compiler flags, caching, and distributed computing for CPU performance.
- Use of Accelerators — Leverage GPUs, TPUs, and other accelerators, ensuring you're using the best available algorithms and architectures.
Application-Specific Strategies
- Understand Your Use Case — Different applications may require unique optimization strategies, so tailor your approach to the specific needs of your LLM deployment.
Tools and Libraries
- Inference Libraries — Serving frameworks such as vLLM, TensorRT-LLM, and Text Generation Inference (TGI) provide optimized batching, caching, and kernel implementations for faster inference.
- CPU and GPU Vendor Toolkits — Hardware vendors publish framework extensions tuned for their own chips, such as Intel Extension for PyTorch on CPUs and NVIDIA's cuDNN/TensorRT libraries on GPUs, that can improve performance on the corresponding hardware.
These strategies are applied iteratively: teams typically re-measure performance after each change and adjust based on the results, since optimizations at one layer can shift bottlenecks to another.
How is performance measured across those layers?
Measuring performance across the model, inference, retrieval, prompt, fine-tuning, and hardware dimensions requires a set of metrics and testing procedures tailored to each area.
Model
- Accuracy Metrics — Use standard metrics like precision, recall, F1 score, or BLEU score for language tasks to measure the model's output quality.
- Model Size — Measure the model's storage footprint, typically in megabytes or gigabytes.
- Complexity — Evaluate the number of operations (FLOPs) required for a forward pass.
Inference
- Latency — Measure the time taken for a single input to pass through the model and return a result.
- Throughput — Assess how many inputs the model can process per unit of time.
- Resource Utilization — Monitor CPU and GPU utilization during inference.
Retrieval
- Response Relevance — Evaluate the relevance of retrieved information to the query or task.
- Retrieval Time — Time the retrieval process separately from the overall inference.
Prompts
- Prompt Efficacy — Test different prompts and measure the quality of responses using qualitative analysis or user studies.
- Prompt Consistency — Check the consistency of responses to the same prompt over multiple iterations.
Fine-tuning
- Performance Improvement — Compare the metrics pre and post fine-tuning to assess improvements.
- Data Efficiency — Evaluate how the model performs with varying amounts of fine-tuning data.
Hardware
- Inference Speed — Benchmark the model on different hardware to measure inference speed.
- Energy Consumption — Measure the power usage during model operation to assess efficiency.
- Scalability — Test how well the model scales with increased hardware resources.
Comprehensive evaluation typically uses an automated testing suite that runs the model across several inputs, prompts, and hardware configurations and records the relevant metrics for each test. Tools such as TensorBoard, MLflow, or Comet ML are commonly used to track and visualize these metrics over time.
These metrics often trade off against each other — for example, reducing model size can increase inference speed while decreasing accuracy — so optimization priorities depend on the requirements of the specific application.
More terms
Continue exploring the glossary.
Glossary term
What is Semantic Web?
It's time to build
Collaborate with your team on reliable Generative AI features.
Want expert guidance? Book a 1:1 onboarding session from your dashboard.