Open-Weight LLM Deployment: GPU Memory Planning and Inference Framework Selection

    Deploying an open-weight large language model requires more than downloading its weights. This guide covers GPU memory sizing, model provenance and compliance, evaluation baselines, a minimal local inference example, framework selection, and scaling practices for controlling latency and cost.

    Key Takeaways

    Access to complete model weights gives enterprises control over the model—and responsibility for deployment, optimization, and compliance.

    Before going live, confirm three prerequisites:

    • GPU memory can accommodate both model weights and the cache required for concurrent requests.
    • Model provenance and data use meet applicable compliance requirements.
    • An internal evaluation dataset is available to validate performance.

    If any prerequisite is missing, address it before deployment.

    1. Three Prerequisites for Deployment

    GPU Memory Capacity

    GPU memory consumption has two main components: model weights and the inference-time KV cache. Weight memory can be estimated as follows:

    1. Weight memory (GB) ≈ Parameters (billions) × Bytes per parameter

    FP16 uses 2 bytes per parameter, INT8 uses 1 byte, and INT4 uses approximately 0.5 bytes. The table below covers weights only, excluding runtime overhead.

    Model size FP16 INT8 INT4
    7B Approximately 14 GB Approximately 7 GB Approximately 3.5 GB
    13B Approximately 26 GB Approximately 13 GB Approximately 6.5 GB
    70B Approximately 140 GB Approximately 70 GB Approximately 35 GB

    Actual memory consumption is usually higher. The framework, CUDA context, and activations require additional GPU memory. Reserving roughly 20% headroom is a common starting point, but final sizing should be based on measurements under real workloads.

    KV cache size can be estimated using:

    1. KV cache (bytes) ≈ 2 × Number of layers × Number of KV heads
    2. × Head dimension × Bytes per element
    3. × Concurrent requests × Context length

    With long contexts and high concurrency, the KV cache can exceed the size of the model weights. Size the cache for maximum concurrency × maximum context length, rather than selecting hardware based solely on model size.

    INT4 quantization can substantially reduce memory requirements, but its effect on accuracy varies by task. For accuracy-sensitive workloads such as code generation and mathematical reasoning, compare quantized and unquantized results on your own data instead of relying only on general-purpose benchmarks.

    Model Provenance and Compliance

    • Verify the source of the weights. Download from the official repository and check the publisher’s SHA256 checksums to detect tampering or replacement.
    • Review the license. Licenses differ in their restrictions on commercial use, redistribution, and user scale. Legal or compliance staff should review the terms before deployment.
    • Keep sensitive data within the approved environment. Training data and user inputs should remain on the internal network. Avoid logging complete prompts containing personal information, and redact sensitive content where necessary.
    • Use remote code cautiously. Setting trust_remote_code=True allows Python code from the model repository to execute during loading. Pin the model version using revision and review the code before use.

    Evaluation Baseline

    Before launch, build an evaluation dataset that covers real business questions. At a minimum, evaluate answer quality, error rates, refusal behavior, latency, and throughput.

    Whenever you change the quantization method, inference framework, or model version, rerun the same evaluation suite and retain the results for comparison.

    2. A Minimal Local Inference Example

    Required environment: Python 3.10 or later, torch 2.x, transformers 4.x, and accelerate. The device_map="auto" option depends on accelerate and will fail if it is missing.

    1. import torch
    2. from transformers import AutoModelForCausalLM, AutoTokenizer
    3. model_path = "/data/models/open_source_llm"
    4. tokenizer = AutoTokenizer.from_pretrained(model_path, trust_remote_code=True)
    5. if tokenizer.pad_token is None:
    6. tokenizer.pad_token = tokenizer.eos_token
    7. model = AutoModelForCausalLM.from_pretrained(
    8. model_path,
    9. torch_dtype=torch.float16,
    10. device_map="auto", # Distribute the model across GPUs based on available memory
    11. trust_remote_code=True,
    12. )
    13. model.eval()
    14. # With multiple GPUs, layers may reside on different devices.
    15. # Place inputs on the device hosting the embedding layer.
    16. input_device = model.get_input_embeddings().weight.device
    17. @torch.no_grad()
    18. def generate_response(prompt: str) -> str:
    19. inputs = tokenizer(prompt, return_tensors="pt").to(input_device)
    20. outputs = model.generate(
    21. **inputs,
    22. max_new_tokens=512,
    23. temperature=0.7,
    24. do_sample=True,
    25. pad_token_id=tokenizer.pad_token_id,
    26. )
    27. # Decode only newly generated tokens to avoid repeating the prompt
    28. new_tokens = outputs[0][inputs["input_ids"].shape[1]:]
    29. return tokenizer.decode(new_tokens, skip_special_tokens=True)
    30. if __name__ == "__main__":
    31. print(generate_response("Briefly describe the core technical challenges of deploying AI compute infrastructure."))

    Key implementation details:

    • model.eval() disables training-only behavior such as dropout.
    • @torch.no_grad() disables gradient computation. Inference does not require backpropagation, so this reduces memory consumption.
    • Some models do not define a pad_token. Set one explicitly for batched inference to avoid potential errors.
    • In a multi-GPU setup, do not assume the input device should simply be "cuda". Read the device from the model’s parameters.

    3. Choosing an Inference Framework

    Framework Throughput Memory management Deployment complexity Typical use cases
    Native Transformers generate Lower Basic Low Prototyping and small offline batches
    vLLM High PagedAttention reduces memory fragmentation Medium High-concurrency online serving with an OpenAI-style compatible interface
    TGI High Continuous batching and tensor parallelism support Medium Serving deployments integrated with the Hugging Face ecosystem

    Throughput differences depend on the model, hardware, and request characteristics. Use official benchmarks alongside your own load tests rather than applying results from another deployment directly to yours.

    4. Autoscaling and Cost Control

    Cloud GPU capacity can accommodate traffic peaks, but several operational issues need attention in advance.

    1. Cold-start time. Loading tens of gigabytes of weights can take several minutes. Account for this delay in the scaling response budget. Keep some baseline instances running and use elastic capacity for peak demand.
    2. Scaling metrics. Scaling on queries per second (QPS) alone can overlook long requests. More reliable signals include queue length, time to first token (TTFT), and generated tokens per second.
    3. Load-test measurements. Record both P50 and P95 latency and calculate cost per token. Averages alone can hide long-tail latency problems.
    4. Scale-down protection. Confirm that in-flight requests have finished before removing instances; otherwise, users may experience interrupted requests.

    Choose the procurement model according to the workload. Stable, long-running demand is better suited to owned hardware or annual commitments, while highly variable demand is better suited to on-demand capacity.

    5. Industry Context and Limits of Interpretation

    Recent volatility in AI-related stocks reflects a repricing of expectations about the future. Stock-price movements alone do not establish the health of the industry.