Nano-vLLM

repository·main·Indexed 12 days ago

https://github.com/geeeekexplorer/nano-vllm

A lightweight, high-performance implementation of the vLLM inference engine built from scratch in Python. Version 0.2.0 features optimizations such as prefix caching, tensor parallelism, and CUDA graphs for fast offline inference, providing an API that mirrors the original vLLM interface.

Tokens
679
Snippets
3
Records
5
Agent score
47%

What's inside Nano-vLLM

  1. Quick Start with Nano-vLLM

    main

    Nano-vLLM provides an API that mirrors vLLM's interface. You can perform offline inference by initializing the LLM class and using the generate method. Note that the LLM.generate method signature may have minor differences compared to the original vLLM.

    from nanovllm import LLM, SamplingParams
    
    # Initialize the LLM engine
    # enforce_eager: boolean to control eager mode
    # tensor_parallel_size: number of GPUs for tensor parallelism
    llm = LLM("/YOUR/MODEL/PATH", enforce_eager=True, tensor_parallel_size=1)
    
    # Configure sampling parameters
    sampling_params = SamplingParams(temperature=0.6, max_tokens=256)
    
    # Define prompts and generate outputs
    prompts = ["Hello, Nano-vLLM."]
    outputs = llm.generate(prompts, sampling_params)
    
    # Access the generated text
    print(outputs[0]["text"])
  2. Download model weights manually

    main

    If you need to download model weights manually before using Nano-vLLM, use the huggingface-cli. For example, to download Qwen/Qwen3-0.6B to a specific local directory:

    huggingface-cli download --resume-download Qwen/Qwen3-0.6B \
      --local-dir ~/huggingface/Qwen3-0.6B/ \
      --local-dir-use-symlinks False
  3. LLM Class API Reference

    main

    The LLM class is the primary entry point for inference.

    Initialization Parameters:

    • model_path (str): Path to the model weights.
    • enforce_eager (bool): Whether to use eager mode.
    • tensor_parallel_size (int): The number of GPUs to use for tensor parallelism.

    Methods:

    • generate(prompts, sampling_params): Takes a list of prompt strings and a SamplingParams object. Returns a list of outputs where each output is a dictionary containing the generated "text".