Skip to main content
LoRA (Low-Rank Adaptation) is a parameter-efficient fine-tuning technique that enables adapting large language models to specific tasks without modifying the original model weights. Instead of fine-tuning all parameters, LoRA introduces small trainable rank decomposition matrices that are added to existing weights during inference.

What is LoRA?

LoRA decomposes weight updates into low-rank matrices:
Where:
  • W is the original pre-trained weight matrix
  • B and A are low-rank matrices (rank r << min(d_in, d_out))
  • Only B and A are trained and stored (massive parameter reduction)
For a 7B parameter model, a LoRA adapter with rank 8 typically adds only ~8-16M parameters (0.1-0.2% of original model size).

Quick Start

Single LoRA Adapter

Multi-LoRA Support

Serve multiple LoRA adapters simultaneously:

Configuration Options

LoraConfig Parameters

max_cpu_loras should be >= max_loras. The system maintains a cache in CPU memory and swaps LoRAs to GPU as needed.

Advanced Usage

LoRA with Quantization

LoRA works seamlessly with quantized models:
LoRA adapters are applied in full precision (FP16/BF16) even when the base model is quantized. This preserves adapter quality while maintaining memory savings from quantization.

NeMo LoRA Format

Support for NeMo-format LoRA checkpoints:

Cache Management

Fine-tune LoRA cache sizes for optimal performance:
Controls CPU memory allocated for caching inactive LoRA adapters. Larger values allow more adapters to be cached, reducing load time when switching between adapters.
Percentage of free GPU memory dedicated to the LoRA adapter cache. Higher values allow more adapters to be active simultaneously but reduce memory available for KV cache.

Serving with trtllm-serve

YAML Configuration

Create a config.yaml file:

Starting the Server

Client Usage

Send requests with LoRA adapters:

Benchmarking with trtllm-bench

YAML Configuration

Run Benchmark

Target Modules

Commonly used LoRA target modules:
  • Lightweight adaptation
  • Good for task-specific tuning
  • Minimal memory overhead
Module names may vary by model architecture. Use trtllm_modules_to_hf_modules to map TRT-LLM names to HuggingFace names if needed.

Performance Considerations

Lower ranks (4-8):
  • Faster inference
  • Smaller adapter files
  • Sufficient for most tasks
Higher ranks (16-64):
  • Better adaptation capacity
  • Slower inference
  • Use for complex domain adaptation
  • max_loras controls GPU memory usage
  • More active LoRAs → less memory for KV cache
  • Start with 4-8 and tune based on workload
  • Use max_cpu_loras for larger adapter pools
  • Increase host_cache_size if frequently switching adapters
  • Increase device_cache_percent if many adapters are used concurrently
  • Monitor adapter swap times and adjust accordingly

Best Practices

1

Start with attention-only modules

Begin with ['attn_q', 'attn_k', 'attn_v'] for most tasks. This provides good adaptation with minimal overhead.
2

Use rank 8 as baseline

Rank 8 offers a good balance between adaptation capacity and inference speed for most use cases.
3

Configure cache sizes appropriately

Set max_cpu_loras to 2-4x your max_loras to allow efficient adapter swapping.
4

Combine with quantization

Use FP8 or INT4 quantization for the base model to maximize memory savings while maintaining LoRA quality.
5

Monitor adapter usage

Track which adapters are most frequently used and prioritize keeping them in GPU memory.

Limitations

  • LoRA adapters must have rank ≤ max_lora_rank configured at model load time
  • All adapters must target the same modules specified in lora_target_modules
  • Adapter switching has a small overhead (loading from CPU/disk to GPU)
  • Maximum number of simultaneously active adapters is limited by GPU memory

Additional Resources

LoRA Paper

Original LoRA: Low-Rank Adaptation of Large Language Models

HuggingFace PEFT

Training LoRA adapters with PEFT library

LoRA Adapters Hub

Browse pre-trained LoRA adapters