Optimizing Local LLMs on Mixed GPU Hardware

Setting up a local large language model often feels like a trade-off between convenience and raw power. Many users start with a single machine, only to find that their hardware limits the model's potential. When you combine resources from multiple machines or deal with fragmented VRAM, the standard setup often falls short.
This guide addresses a common scenario: combining gaming PCs or managing limited VRAM on a single card. By separating the inference engine from the client interface, you can bypass WSL2 GPU passthrough overhead. This approach allows you to utilize full CUDA access on Windows while keeping the Linux environment for smoother gateway operations.
We will cover the technical details of configuring WSL2, CUDA, and GPU passthrough to maximize performance. You will learn how to handle IP changes, manage memory constraints, and choose the right model quantization. The goal is to create a stable, high-performance local AI environment that feels responsive and reliable.
Frequently asked questions
What is WSL2 GPU passthrough?
WSL2 GPU passthrough allows the Windows Subsystem for Linux to access the NVIDIA GPU directly. It enables Linux applications to use CUDA libraries without emulation. However, it introduces some overhead and memory limits that can reduce performance compared to native Windows access.
How does WSL2 differ from native Windows CUDA?
Native Windows CUDA offers full access to the GPU with minimal overhead. WSL2 requires a translation layer, which can limit usable VRAM and add latency. For maximum performance, especially with limited VRAM, running the inference engine on Windows is often superior.
Which is better: Ollama on Windows or WSL2?
For inference speed and VRAM efficiency, Ollama on Windows is generally better. It avoids the passthrough overhead. WSL2 is better for development and gateway services. Running Ollama on Windows and the client in WSL2 provides the best of both worlds.
What is VRAM fragmentation in mixed setups?
VRAM fragmentation occurs when multiple processes compete for limited GPU memory. In mixed hardware setups, this can lead to out-of-memory errors. Managing memory carefully and using efficient quantization helps prevent this issue and ensures stable inference.
How do I handle WSL2 IP changes?
WSL2 IPs can change on restart, breaking connections. You can configure a static IP in the WSL2 network settings or use a local DNS service. Alternatively, run the inference engine on the Windows host IP, which remains constant, and connect from WSL2.
What is the role of CUDA in local LLMs?
CUDA is NVIDIA's parallel computing platform that accelerates AI inference. It allows the GPU to process large matrices of data quickly. Without CUDA, local LLMs would rely on the CPU, which is significantly slower for large models.
How does quantization affect performance?
Quantization reduces the precision of model weights, lowering VRAM usage and increasing speed. Lower quantizations like Q4 or Q5 offer a good balance. Higher quantizations like Q8 provide better quality but require more memory and slower inference speeds.
What is the best way to combine two PCs?
Combine PCs by running the inference engine on the more powerful GPU and the client on the other. Use a local API to connect them. This leverages the combined processing power while avoiding the complexity of distributed training. It is a practical solution for mixed hardware.
Step by step
- Configure WSL2 Network — Set a static IP in WSL2 to ensure consistent connectivity. Edit the /etc/wsl.conf file to define a static IP address. This prevents connection issues when the IP changes on restart.
- Install NVIDIA Drivers — Update your NVIDIA drivers to the latest version. This ensures compatibility with the latest CUDA toolkit and model architectures. Check the NVIDIA website for the latest drivers.
- Deploy Inference Engine — Run the inference engine on the Windows host for full CUDA access. This avoids WSL2 passthrough overhead. Use a tool like Ollama or vLLM for efficient inference.
- Connect Client Interface — Connect your client interface from WSL2 to the Windows inference engine via the local IP. Use the OpenAI-compatible API endpoint for seamless integration.
- Monitor Performance — Use nvidia-smi to monitor GPU usage and memory consumption. Adjust batch size and context window based on performance metrics. Optimize for your specific hardware.
Understanding the Hardware Constraints
When building a local LLM setup, the first step is understanding your hardware limitations. Many users start with gaming PCs that have powerful GPUs but limited VRAM. For example, an RX 6900XT or RX 9060XT with 16GB of VRAM can handle large models, but only if managed correctly. The key is to avoid overcommitting memory, which leads to swapping and slow performance.
Mixed hardware setups often involve combining resources from multiple machines. This can include a Ryzen 5600 CPU with 48GB of DDR4 RAM and multiple NVMe SSDs. The goal is to balance the load between the CPU and GPU. By distributing tasks appropriately, you can achieve better performance than relying on a single machine.
VRAM Management Strategies
VRAM is the most critical resource for local LLMs. To maximize performance, you must monitor memory usage closely. Use tools like nvidia-smi to track VRAM consumption. If you exceed the available memory, the system will start swapping to RAM, which is significantly slower. Always choose a model quantization that fits within your VRAM limits.
CPU and RAM Considerations
While the GPU handles inference, the CPU manages data preprocessing and postprocessing. A powerful CPU like the Ryzen 5600 can help offload some tasks from the GPU. Additionally, having ample RAM, such as 48GB, allows for faster data swapping if needed. Ensure your NVMe SSDs are fast enough to handle large model files without bottlenecks.
Configuring WSL2 for Optimal Performance
WSL2 provides a Linux environment that is ideal for running client applications and gateways. However, GPU passthrough in WSL2 can introduce overhead. To mitigate this, configure WSL2 to use a static IP address. This ensures that your client applications can consistently connect to the inference engine running on the Windows host.
You can also optimize WSL2 by adjusting the memory allocation in the .wslconfig file. Set the memory limit to a reasonable value, such as 16GB, to prevent it from consuming too much system RAM. This leaves more resources available for the Windows host and the GPU inference engine.
Static IP Configuration
A static IP in WSL2 prevents connection issues when the IP changes on restart. Edit the /etc/wsl.conf file to set a static IP address. This is particularly useful when running multiple services that need to communicate with each other. It ensures that your client applications can always find the inference engine.
Memory Allocation Tuning
Tuning memory allocation in WSL2 is crucial for performance. By setting a memory limit in the .wslconfig file, you can prevent WSL2 from consuming too much system RAM. This ensures that the Windows host has enough resources to run the GPU inference engine efficiently. Aim for a balance that suits your specific hardware.

Leveraging CUDA for Inference
CUDA is the backbone of GPU acceleration for local LLMs. It allows the GPU to process large matrices of data quickly, enabling real-time inference. To leverage CUDA effectively, ensure that your NVIDIA drivers are up to date. This ensures compatibility with the latest model architectures and optimization techniques.
Running the inference engine on the Windows host provides full CUDA access without the overhead of WSL2 passthrough. This is particularly beneficial for models with large context windows or high token generation rates. By keeping the inference engine on Windows, you can maximize the utilization of your GPU's VRAM.
Driver Updates and Compatibility
Keeping your NVIDIA drivers up to date is essential for optimal CUDA performance. New drivers often include optimizations for the latest models and hardware. Check the NVIDIA website regularly for updates. This ensures that you are using the most efficient version of the CUDA toolkit for your specific GPU.
Inference Engine Placement
Placing the inference engine on the Windows host allows for full CUDA access. This avoids the overhead associated with WSL2 GPU passthrough. It is particularly important for models that require large amounts of VRAM. By running the engine on Windows, you can ensure that all available VRAM is used for inference.
Handling GPU Passthrough Overhead
GPU passthrough in WSL2 can introduce overhead, especially when dealing with large models. This overhead can manifest as increased latency or reduced throughput. To minimize this, consider running the inference engine on the Windows host and using WSL2 only for the client interface.
Another strategy is to use a local API to connect the WSL2 client to the Windows inference engine. This allows you to take advantage of the Linux environment for development while still benefiting from the raw power of the GPU on Windows. It is a practical solution for mixed hardware setups.
Latency Reduction Techniques
To reduce latency caused by GPU passthrough, minimize the amount of data transferred between WSL2 and the Windows host. Use efficient data formats and compress data where possible. Additionally, ensure that your network connection between the two environments is fast and stable.
Throughput Optimization
Optimizing throughput involves maximizing the utilization of the GPU. This can be achieved by using efficient model architectures and quantization techniques. Additionally, ensure that your inference engine is configured to use all available GPU resources. This includes setting the correct batch size and context window.

Choosing the Right Model Quantization
Model quantization is a critical factor in determining the performance of your local LLM. Quantization reduces the precision of the model weights, which lowers VRAM usage and increases inference speed. However, it can also affect the quality of the output. It is important to find the right balance between speed and accuracy.
For most users, a Q4 or Q5 quantization offers a good balance. These quantizations provide sufficient accuracy for most tasks while fitting within the VRAM limits of most GPUs. If you have more VRAM available, you can try Q8 quantization for better quality. However, this will require more memory and may slow down inference.
Q4 vs Q5 Quantization
Q4 and Q5 quantizations are popular choices for local LLMs. Q4 reduces the precision to 4 bits, which significantly lowers VRAM usage. Q5 uses 5 bits, offering a slightly better quality at the cost of more memory. Both are suitable for most use cases and provide a good balance between performance and accuracy.
Q8 Quantization for High Quality
Q8 quantization uses 8 bits per weight, providing higher quality output. This is ideal for users with ample VRAM who prioritize accuracy over speed. However, it requires more memory and may slow down inference. If you have a powerful GPU with 16GB or more VRAM, Q8 is a viable option.
Integrating with Free API Services
While local LLMs offer privacy and control, they can be resource-intensive. For users who want a simpler setup, integrating with a free API service like LLMAPIFree can be a great option. LLMAPIFree provides an OpenAI-compatible API with no account or key required. It is ideal for testing and lightweight applications.
You can use LLMAPIFree as a fallback when your local setup is under heavy load. It allows you to offload some requests to a remote server, reducing the burden on your local hardware. This is particularly useful for users with limited VRAM or older GPUs.
API Integration Basics
Integrating with LLMAPIFree is straightforward. Simply point your application to the base URL https://api.llmapifree.com/v1 and use the model name 'free-ai'. The API is compatible with the OpenAI SDK, making it easy to switch between local and remote models. This flexibility allows you to choose the best option for each task.
When to Use Remote APIs
Remote APIs like LLMAPIFree are useful when you need to handle a high volume of requests or when your local hardware is limited. They provide a reliable fallback and can handle spikes in traffic without requiring additional local resources. Use them in conjunction with your local setup for optimal performance.

Monitoring and Debugging Your Setup
Monitoring your local LLM setup is essential for identifying performance bottlenecks. Use tools like nvidia-smi to track GPU usage, memory consumption, and temperature. These metrics provide valuable insights into how your hardware is performing under load. Regular monitoring helps you detect issues before they become critical.
Debugging involves analyzing logs and error messages. Most inference engines provide detailed logs that can help you identify problems. Look for signs of memory exhaustion, high latency, or connection timeouts. By addressing these issues promptly, you can ensure a smooth and reliable experience.
Using nvidia-smi for Monitoring
nvidia-smi is a powerful tool for monitoring NVIDIA GPUs. It provides real-time information about GPU usage, memory consumption, and temperature. Use it to track the performance of your inference engine and identify any anomalies. Regular monitoring helps you optimize your setup and prevent issues.
Analyzing Logs for Errors
Logs are a valuable resource for debugging. Most inference engines provide detailed logs that include information about errors, warnings, and performance metrics. Review these logs regularly to identify potential issues. Look for patterns that indicate problems, such as repeated memory errors or high latency.
Advanced Tuning for Mixed Hardware
For users with mixed hardware, advanced tuning can yield significant performance improvements. This includes optimizing the batch size, context window, and quantization settings. Experiment with different configurations to find the optimal balance for your specific setup. Remember that the best configuration depends on your hardware and use case.
Consider using a combination of local and remote models. Run resource-intensive tasks locally and offload simpler tasks to a remote API like LLMAPIFree. This approach allows you to leverage the strengths of both environments. It also provides flexibility and reliability, ensuring that your AI applications run smoothly.
Batch Size Optimization
The batch size determines how many requests are processed simultaneously. A larger batch size can improve throughput but may increase latency. Experiment with different batch sizes to find the optimal value for your hardware. Start with a small batch size and gradually increase it until you see diminishing returns.
Context Window Tuning
The context window affects the amount of memory required for inference. A larger context window allows for more detailed responses but consumes more VRAM. Adjust the context window based on your needs and available resources. If you run out of memory, reduce the context window to improve performance.

Test our unfiltered 35B model right now with no key, no account, and no limits.
Home →