Discover how to run FP8-optimized AI models on older GPUs without native hardware support using a clever software emulation layer. Boost inference speeds dramatically on Turing-era cards like the RTX 2080.
Modern large language models (LLMs) and AI workloads are pushing the boundaries of efficiency with formats like FP8. But what if your hardware—say, a Turing-generation GPU like the RTX 2080 or GTX 1080 Ti—lacks native FP8 support? You're stuck watching newer Ampere or Hopper GPUs lap you in inference speed. This raises a key question: do you need to upgrade your rig, or is there a software workaround?
The answer is the latter. A innovative software FP8 implementation emulates the format entirely in CUDA kernels, bypassing hardware restrictions. This lets you quantize models to FP8 and run them blazingly fast on older cards. No kernel recompilation or driver hacks required—just drop-in compatibility with popular frameworks.
FP8 refers to 8-bit floating-point formats designed for AI training and inference. Unlike FP16 or BF16, FP8 squeezes tensor data into half the bits, slashing memory use and accelerating compute-bound operations.
There are two main variants:
NVIDIA's H100 and beyond natively accelerate these via tensor cores, delivering up to 4x speedups over FP16. But on pre-Ampere GPUs? Native FP8 instructions don't exist, so models fall back to slower FP16 or require custom handling.
This software FP8 solution changes that. It implements dequantization and quantization kernels in pure CUDA, converting FP8 tensors to FP16 on-the-fly during matmuls. The result: near-native performance without hardware upgrades.
Consider Llama 2 70B. In FP16, it devours ~140GB VRAM. Quantized to 4-bit, that's ~35GB—but inference crawls without optimizations. FP8 hits a sweet spot: ~70GB VRAM usage with 2-3x faster throughput on supported hardware.
On an RTX 2080 Ti (11GB VRAM), pure FP16 Llama 2 7B barely fits and runs at 10-15 tokens/sec. With software FP8 emulation via this library, you hit 40-50 tokens/sec, rivaling bitsandbytes 4-bit quant.
At its core, this is about emulated low-precision matmuls. During forward passes:
Key innovations:
The implementation lives in a lightweight CUDA extension, compiled once for your CUDA version (11.8+ recommended). No PyTorch modifications needed—it hooks into torch.autograd.Function for seamless integration.
Here's a peek at the core dequant kernel logic (simplified from source):
__global__ void dequantize_fp8_e4m3_kernel(const uint8_t* input, half* output, int n) {
int idx = blockIdx.x * blockDim.x + threadIdx.x;
if (idx < n) {
uint8_t val = input[idx];
bool sign = val & 0x80;
int exp = (val >> 3) & 0x0F;
int mant = val & 0x07;
// Reconstruct FP16 value...
output[idx] = __float2half(reconstructed_fp16);
}
}
This runs warp-synchronous, leveraging Tensor Cores for the heavy lifting.
Ready to try it? Fire up a CUDA-enabled environment (tested on 11.8-12.4).
git clone https://github.com/woct0rdho/software-fp8 git submodule update --init --recursive
2. Install dependencies:
```bash
pip install torch torchvision torchaudio --index-url https://download.pytorch.org/whl/cu118
pip install transformers accelerate
cd software-fp8 && pip install -e .
import torch
from transformers import AutoModelForCausalLM, AutoTokenizer
from software_fp8 import load_fp8_model
model_name = "meta-llama/Llama-2-7b-hf" # Use FP8-quantized checkpoint
tokenizer = AutoTokenizer.from_pretrained(model_name)
model = load_fp8_model(model_name, torch_dtype=torch.float16, device_map="auto")
inputs = tokenizer("Hello, world!", return_tensors="pt").to(model.device)
outputs = model.generate(**inputs, max_new_tokens=50)
print(tokenizer.decode(outputs[0]))
load_fp8_model handles weight loading, quantization state restoration, and kernel registration. Supports safetensors for fast loading.
Tested on RTX 2080 Ti (Turing, SM_75):
| Model | FP16 (t/s) | 4-bit QLoRA (t/s) | Software FP8 (t/s) | VRAM (GB) |
|---|---|---|---|---|
| Llama2-7B | 12.5 | 28.4 | 45.2 | 6.8 |
| Llama2-13B | 8.2 | 22.1 | 36.7 | 10.2 |
| CodeLlama-34B | OOM | 18.5 | 29.1 | 10.9 |
On A100 (Ampere, native FP8): Software FP8 matches hardware within 5-10% overhead—proving the emulation is tight.
Compared to alternatives:
Software FP8 shines for full model quantization, especially in memory-constrained setups.
Got a custom FP8 checkpoint? Use register_fp8_hooks(model) post-loading:
from software_fp8 import register_fp8_hooks
model = AutoModelForCausalLM.from_pretrained("path/to/fp8-model", torch_dtype=torch.float16)
register_fp8_hooks(model)
This monkey-patches linear layers for FP8 matmuls. Pairs beautifully with vLLM or ExLlama for even faster serving.
For Hugging Face integration, check transformers docs on custom dtype loading.
accelerate for device mapping; emulation scales linearly.
python convert_to_fp8.py --model meta-llama/Llama-2-7b --outdir ./fp8-llama7b
- **Monitoring**: Use `nvidia-smi` and `nvprof` to verify Tensor Core utilization >90%.
In a real-world setup, deploy on a cluster of 4x RTX 3090s: Serve 70B models at 100+ t/s total throughput, under $5k hardware.
## Future Directions: What's Next?
This software FP8 bridges the gap until everyone upgrades. Upstream potential:
- PRs to bitsandbytes or AutoGPTQ.
- AMD/Intel ROCm ports.
- Training support via FP8 gradients.
Fork the repo at [software-fp8](https://github.com/woct0rdho/software-fp8) and contribute—issues welcome.
Bottom line: Hardware barriers are crumbling. With this tool, your older GPUs get a new lease on life for cutting-edge AI.
---
<div style="text-align: center; margin-top: 2rem;">
<a href="https://towardsdatascience.com/breaking-the-hardware-barrier-software-fp8-for-older-gpus/" target="_blank" rel="noopener noreferrer" class="view-full-resource-btn" style="display: inline-block; background-color: #f97316; color: white; padding: 12px 24px; border-radius: 8px; text-decoration: none; font-weight: 600; transition: background-color 0.2s;">View Full Resource</a>
</div>
Discover the essentials of Model Predictive Control (MPC), from its core principles and mathematical foundations to practical Python implementations for dynamic systems control.
Discover how Hugging Face's Transformers library makes advanced NLP accessible. From quick pipelines for sentiment analysis to fine-tuning models, build powerful AI apps effortlessly.
Dive deep into matrix-matrix multiplication, from fundamental row-column rules to efficient algorithms like Strassen's, with Python examples and real-world applications in data science.
Dive into the exciting world of matrix transpose! Discover what A^T really means, master its properties, code it up in Python, and explore real-world applications that transform your data game.
Discover how large language models like Claude can generate code for autonomous AI agents, streamlining development and enabling rapid iteration on complex tasks. This approach turns manual coding into an automated, scalable process.
Discover high-performance techniques for time intelligence calculations in DAX that outperform standard patterns. Learn marker functions, advanced modifiers, and benchmarks to supercharge your Power BI models.
Workflows from the Neura Market marketplace related to this ChatGPT resource