Deploying Open-Source LLMs on a Single 32GB GPU: Conditions, Steps, and Troubleshooting

    This article explains how to deploy open-source large language models on a single consumer-grade GPU with 32GB of VRAM. It covers VRAM estimation, environment preparation, launching inference services using Docker, and troubleshooting common issues like out-of-memory (OOM) errors, compute capability mismatches, and port connectivity problems. It also provides guidelines for measuring performance metrics such as Time To First Token (TTFT) and output throughput.

    Introduction

    The variety of open-source large language models is increasing, but the scale that developers can run locally remains limited by VRAM. For models with tens of billions of parameters, VRAM is the most common bottleneck. Whether a model can boot depends heavily on quantization, context length, and framework version.

    Using a 32GB consumer GPU as an example, this guide explains how to evaluate model feasibility, launch an inference service in a container, call it locally via an SSH tunnel, and troubleshoot OOM, compute incompatibility, and port issues. The commands provided require replacing placeholders with your specific environment details. Fixed throughput numbers are omitted, as explained in Part 4.

    1. VRAM Estimation

    Before downloading a model, estimate its VRAM requirements. A rough formula is as follows:

    1. VRAM Usage ≈ Weights + KV Cache + Framework/CUDA Overhead
    2. Weights ≈ Parameter Count × Bytes per Parameter

    The bytes per parameter depend on precision. FP16 or BF16 is 2 bytes, 8-bit quantization is approximately 1 byte, and 4-bit quantization is about 0.5 bytes. Actual 4-bit weights include metadata like scaling factors, so the real value will be slightly higher than the theoretical one.

    Using this formula, a 30B parameter model in 4-bit requires roughly 15 to 18GB for weights, leaving the remaining VRAM for the KV Cache and framework overhead. A 70B parameter model in 4-bit requires about 35GB for weights alone, exceeding the 32GB limit and making it impossible to load entirely on a single GPU. For such models, there are three common approaches:

    1. Lower quantization (e.g., 3-bit): Lower bit counts usually result in greater quality loss. You must use your own evaluation dataset to confirm if the degradation is acceptable.
    2. Offload layers to CPU RAM: This allows the model to start, but generation speed will drop significantly.
    3. Use multiple GPUs or devices with more VRAM.

    The KV Cache size depends on the context length, concurrent requests, and the model’s layer and head counts. Longer contexts and higher concurrency consume more KV Cache. Therefore, even if the weights fit, long-context services might fail to start or crash under high load due to insufficient VRAM.

    Regarding quantization quality, 4-bit usually causes some quality degradation depending on the model and task. This article does not claim it is “lossless”; it is recommended to compare results before and after quantization using your own task samples.

    2. Environment Preparation and Verification

    Before deployment, verify four things: the GPU driver, Docker, the NVIDIA Container Toolkit, and GPU visibility inside the container. Run the following commands on the host:

    1. nvidia-smi
    2. docker --version
    3. docker info | grep -i runtimes

    nvidia-smi should list the GPU model and VRAM capacity. The output of docker info should include the nvidia runtime. If not, install the NVIDIA Container Toolkit, run sudo nvidia-ctk runtime configure --runtime=docker, and restart the Docker service.

    Next, verify that the container can access the GPU:

    1. docker run --rm --gpus all <image_tag> nvidia-smi

    Replace <image_tag> with the specific image version of your inference framework. It is recommended to use fixed version tags rather than latest, otherwise the same command might pull different images at different times.

    If the container reports could not select device driver "nvidia", the Container Toolkit is likely not installed correctly or Docker was not restarted.

    Then, check the compatibility between the deep learning framework and the GPU’s compute capability:

    1. docker run --rm --gpus all <image_tag> python3 -c "import torch; print(torch.__version__, torch.version.cuda); print(torch.cuda.get_device_name(0), torch.cuda.get_device_capability(0)); print(torch.cuda.get_arch_list())"

    The get_device_capability in the output indicates the GPU’s compute capability. For instance, the RTX 5090 with 32GB of VRAM uses the newer Blackwell architecture with a compute capability of 12.0, corresponding to the kernel identifier sm_120. The result of get_arch_list() must include sm_120; otherwise, the framework has not compiled kernels for this GPU. Common fixes for this issue include: switching to an image that supports the architecture, installing a PyTorch build that supports it (usually requiring CUDA 12.8 or higher), or compiling from source.

    If the compute capability list does not match, you might encounter “illegal memory access” or “operator not supported” errors during inference. These errors do not necessarily appear at startup but may surface during the first generation request, so the initial request should always be treated as a verification step.

    3. Launching the Inference Service

    Once the environment is verified, you can start the model service. The following command uses the SGLang image as an example, with a default service port of 30000:

    1. mkdir -p /root/hf-cache
    2. docker run -d --name llm-server --gpus all \
    3. --ipc=host \
    4. -p 127.0.0.1:30000:30000 \
    5. -v /root/hf-cache:/root/.cache/huggingface \
    6. <image_tag> \
    7. python3 -m sglang.launch_server \
    8. --model-path <quantized_model_ID_or_local_path> \
    9. --host 0.0.0.0 \
    10. --port 30000 \
    11. --context-length 8192 \
    12. --mem-fraction-static 0.85

    The roles of the parameters are as follows:

    • --gpus all: Passes all host GPUs to the container. In a single-GPU setup, you can also use --gpus device=0 to specify a particular device.
    • --ipc=host: The container directly uses the host’s IPC namespace and shared memory. When this option is used, --shm-size no longer takes effect, so you must choose one or the other. If you want the container to have independent shared memory, remove --ipc=host and add --shm-size 16g or a larger value. --ipc=host exposes the host’s shared memory to the container, so ensure no untrusted processes are running on the host.
    • -p 127.0.0.1:30000:30000: Maps the container’s port 30000 to the host’s loopback address. Docker defaults to binding to 0.0.0.0, which would expose the service to the LAN or public internet. Binding to 127.0.0.1 ensures that only the server itself and subsequent SSH tunnels can access it.
    • --host 0.0.0.0: This is the listening address inside the container. If the service only listens on 127.0.0.1 inside the container, the port mapping will not be accessible from the host.
    • -v /root/hf-cache:/root/.cache/huggingface: Places the model cache in a host directory. Downloaded model files are preserved even after the container is deleted, preventing re-downloads on restart.
    • --context-length & --mem-fraction-static: These limit the context length and the static VRAM fraction reserved by the framework, respectively. When VRAM is tight, lower these two values first.

    For the first startup, it is recommended to use only the basic parameters above to confirm that the model loads and generates correctly, then gradually enable other optimization options. Change one parameter at a time to make troubleshooting easier.

    After starting, check the status with the following commands:

    1. docker logs -f llm-server
    2. curl -s http://127.0.0.1:30000/health
    3. curl -s http://127.0.0.1:30000/v1/models

    If the logs show out of memory or OutOfMemoryError, VRAM is insufficient. The troubleshooting order can be: lower --context-length, reduce --mem-fraction-static to around 0.75, switch to a smaller model or lower quantization, and use nvidia-smi to ensure no other processes are consuming VRAM.

    4. Testing and Performance Measurement

    A service that can respond to requests only proves it is running, not that it performs well. Performance conclusions must include measurement conditions; otherwise, readers cannot reproduce or compare the results.

    For each test, record the following information: GPU model and driver version, model name, parameter count, and quantization method, inference framework and image version, input and output token lengths, concurrency or batch size, and measurement method.

    Two common metrics are Time To First Token (TTFT) and output throughput (tokens/s). The former reflects the user’s wait time for the first token, while the latter reflects the generation speed. During testing, fix the input and output lengths, repeat the same batch of requests at least 5 times, and report the median and 90th percentile rather than just a single best result.

    Since these numbers depend heavily on the model, quantization method, context length, and concurrency, this article does not provide fixed throughput values. Rely on your own test results.

    To test a simple chat request, you can use the following command, replacing <model_name> with your actual model name:

    1. curl -s http://127.0.0.1:30000/v1/chat/completions \
    2. -H "Content-Type: application/json" \
    3. -d '{
    4. "model": "<model_name>",
    5. "messages": [{"role": "user", "content": "Hello!"}]
    6. }'