Skip to main content

A high-throughput and memory-efficient inference and serving engine for LLMs

Project description

nm-vllm

Overview

vLLM is a fast and easy-to-use library for LLM inference that Neural Magic regularly contributes upstream improvements to. This fork, nm-vllm is our opinionated focus on incorporating the latest LLM optimizations like quantization and sparsity for enhanced performance.

Installation

The nm-vllm PyPi package includes pre-compiled binaries for CUDA (version 12.1) kernels, streamlining the setup process. For other PyTorch or CUDA versions, please compile the package from source.

Install it using pip:

pip install nm-vllm

For utilizing weight-sparsity kernels, such as through sparsity="sparse_w16a16", you can extend the installation with the sparsity extras:

pip install nm-vllm[sparse]

You can also build and install nm-vllm from source (this will take ~10 minutes):

git clone https://github.com/neuralmagic/nm-vllm.git
cd nm-vllm
pip install -e .

Quickstart

Neural Magic maintains a variety of sparse models on our Hugging Face organization profiles, neuralmagic and nm-testing.

A collection of ready-to-use SparseGPT and GPTQ models in inference optimized marlin format are available on Hugging Face

Model Inference with Marlin (4-bit Quantization)

Marlin is an extremely optimized FP16xINT4 matmul kernel aimed at LLM inference that can deliver close to ideal (4x) speedups up to batchsizes of 16-32 tokens. To use Marlin within nm-vllm, simply pass the Marlin quantized directly to the engine. It will detect the quantization from the model's config.

Here is a demonstraiton with a 4-bit quantized OpenHermes Mistral model:

from vllm import LLM, SamplingParams
from transformers import AutoTokenizer

model_id = "neuralmagic/OpenHermes-2.5-Mistral-7B-marlin"
model = LLM(model_id, max_model_len=4096)
tokenizer = AutoTokenizer.from_pretrained(model_id)
sampling_params = SamplingParams(max_tokens=100, temperature=0.8, top_p=0.95)

messages = [
    {"role": "user", "content": "What is synthetic data in machine learning?"},
]
formatted_prompt =  tokenizer.apply_chat_template(messages, tokenize=False, add_generation_prompt=True)
outputs = model.generate(formatted_prompt, sampling_params=sampling_params)
print(outputs[0].outputs[0].text)

Model Inference with Weight Sparsity

For a quick demonstration, here's how to run a small 50% sparse llama2-110M model trained on storytelling:

from vllm import LLM, SamplingParams

model = LLM(
    "neuralmagic/llama2.c-stories110M-pruned50",
    sparsity="sparse_w16a16",   # If left off, model will be loaded as dense
)

sampling_params = SamplingParams(max_tokens=100, temperature=0)
outputs = model.generate("Hello my name is", sampling_params=sampling_params)
print(outputs[0].outputs[0].text)

Here is a more realistic example of running a 50% sparse OpenHermes 2.5 Mistral 7B model finetuned for instruction-following:

from vllm import LLM, SamplingParams
from transformers import AutoTokenizer

model_id = "neuralmagic/OpenHermes-2.5-Mistral-7B-pruned50"
model = LLM(model_id, sparsity="sparse_w16a16", max_model_len=4096)
tokenizer = AutoTokenizer.from_pretrained(model_id)
sampling_params = SamplingParams(max_tokens=100, temperature=0.8, top_p=0.95)

messages = [
    {"role": "user", "content": "What is sparsity in deep learning?"},
]
formatted_prompt =  tokenizer.apply_chat_template(messages, tokenize=False, add_generation_prompt=True)
outputs = model.generate(formatted_prompt, sampling_params=sampling_params)
print(outputs[0].outputs[0].text)

There is also support for semi-structured 2:4 sparsity using the sparsity="semi_structured_sparse_w16a16" argument:

from vllm import LLM, SamplingParams

model = LLM("neuralmagic/llama2.c-stories110M-pruned2.4", sparsity="semi_structured_sparse_w16a16")
sampling_params = SamplingParams(max_tokens=100, temperature=0)
outputs = model.generate("Once upon a time, ", sampling_params=sampling_params)
print(outputs[0].outputs[0].text)

Integration with OpenAI-Compatible Server

You can also quickly use the same flow with an OpenAI-compatible model server:

python -m vllm.entrypoints.openai.api_server \
    --model neuralmagic/OpenHermes-2.5-Mistral-7B-pruned50 \
    --sparsity sparse_w16a16 \
    --max-model-len 4096

Quantized Inference Performance

Developed in collaboration with IST-Austria, GPTQ is the leading quantization algorithm for LLMs, which enables compressing the model weights from 16 bits to 4 bits with limited impact on accuracy. nm-vllm includes support for the recently-developed Marlin kernels for accelerating GPTQ models. Prior to Marlin, the existing kernels for INT4 inference failed to scale in scenarios with multiple concurrent users.

Marlin Performance

Sparse Inference Performance

Developed in collaboration with IST-Austria, SparseGPT and Sparse Fine-tuning are the leading algorithms for pruning LLMs, which enables removing at least half of model weights with limited impact on accuracy.

nm-vllm includes support for newly-developed sparse inference kernels, which provides both memory reduction and acceleration of sparse models leveraging sparsity.

Sparse Memory Compression Sparse Inference Performance

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

nm-vllm-0.2.0.tar.gz (457.9 kB view details)

Uploaded Source

Built Distributions

If you're not sure about the file name format, learn more about wheel file names.

nm_vllm-0.2.0-cp311-cp311-manylinux_2_17_x86_64.whl (97.7 MB view details)

Uploaded CPython 3.11manylinux: glibc 2.17+ x86-64

nm_vllm-0.2.0-cp310-cp310-manylinux_2_17_x86_64.whl (97.7 MB view details)

Uploaded CPython 3.10manylinux: glibc 2.17+ x86-64

nm_vllm-0.2.0-cp39-cp39-manylinux_2_17_x86_64.whl (97.7 MB view details)

Uploaded CPython 3.9manylinux: glibc 2.17+ x86-64

nm_vllm-0.2.0-cp38-cp38-manylinux_2_17_x86_64.whl (97.7 MB view details)

Uploaded CPython 3.8manylinux: glibc 2.17+ x86-64

File details

Details for the file nm-vllm-0.2.0.tar.gz.

File metadata

  • Download URL: nm-vllm-0.2.0.tar.gz
  • Upload date:
  • Size: 457.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.3.0 pkginfo/1.7.0 requests/2.25.1 setuptools/39.0.1 requests-toolbelt/0.9.1 tqdm/4.56.0 CPython/3.6.9

File hashes

Hashes for nm-vllm-0.2.0.tar.gz
Algorithm Hash digest
SHA256 d636d74d1315b88e9b2a5683df3bf29922a93c6c3d4fbf3a03150065b0129dd2
MD5 68bc697ef4e0dbc0566d770257f6a0e3
BLAKE2b-256 29b247bc8586802f790959a6e089e0f810d45d0658208e3ca1917245f2398439

See more details on using hashes here.

File details

Details for the file nm_vllm-0.2.0-cp311-cp311-manylinux_2_17_x86_64.whl.

File metadata

  • Download URL: nm_vllm-0.2.0-cp311-cp311-manylinux_2_17_x86_64.whl
  • Upload date:
  • Size: 97.7 MB
  • Tags: CPython 3.11, manylinux: glibc 2.17+ x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.3.0 pkginfo/1.7.0 requests/2.25.1 setuptools/39.0.1 requests-toolbelt/0.9.1 tqdm/4.56.0 CPython/3.6.9

File hashes

Hashes for nm_vllm-0.2.0-cp311-cp311-manylinux_2_17_x86_64.whl
Algorithm Hash digest
SHA256 29914efa4b874acd151e8ea91d9a75bfcba1a3b082d6bab138f41f9956d09ed7
MD5 76c3f979fe01f0429372ec23243ac16b
BLAKE2b-256 18fb57af2592be3fca01ff3b4f9fcdfc881df56d95a6df9e6091a5329e863260

See more details on using hashes here.

File details

Details for the file nm_vllm-0.2.0-cp310-cp310-manylinux_2_17_x86_64.whl.

File metadata

  • Download URL: nm_vllm-0.2.0-cp310-cp310-manylinux_2_17_x86_64.whl
  • Upload date:
  • Size: 97.7 MB
  • Tags: CPython 3.10, manylinux: glibc 2.17+ x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.3.0 pkginfo/1.7.0 requests/2.25.1 setuptools/39.0.1 requests-toolbelt/0.9.1 tqdm/4.56.0 CPython/3.6.9

File hashes

Hashes for nm_vllm-0.2.0-cp310-cp310-manylinux_2_17_x86_64.whl
Algorithm Hash digest
SHA256 0a0318cdda2f1f3d9d41ca10e1808384368afb08769476159f45e7159559d8de
MD5 ce7b5e105279e7a5dcfdd525fcef3585
BLAKE2b-256 bcf70fc494096b207ef6a94e949682b8d17ba8eb279db21a65121b9abd725e4a

See more details on using hashes here.

File details

Details for the file nm_vllm-0.2.0-cp39-cp39-manylinux_2_17_x86_64.whl.

File metadata

  • Download URL: nm_vllm-0.2.0-cp39-cp39-manylinux_2_17_x86_64.whl
  • Upload date:
  • Size: 97.7 MB
  • Tags: CPython 3.9, manylinux: glibc 2.17+ x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.3.0 pkginfo/1.7.0 requests/2.25.1 setuptools/39.0.1 requests-toolbelt/0.9.1 tqdm/4.56.0 CPython/3.6.9

File hashes

Hashes for nm_vllm-0.2.0-cp39-cp39-manylinux_2_17_x86_64.whl
Algorithm Hash digest
SHA256 a3b316636157cd598bb499c4c9f6bb93347e4a89e68bc2b46d57b50110646f23
MD5 44a2b954039dc0894149395ed4d337b8
BLAKE2b-256 e6d82ebf6ba02f95c57703ad612452aae0f9dca06cbdb4c1942a44ad61eaa710

See more details on using hashes here.

File details

Details for the file nm_vllm-0.2.0-cp38-cp38-manylinux_2_17_x86_64.whl.

File metadata

  • Download URL: nm_vllm-0.2.0-cp38-cp38-manylinux_2_17_x86_64.whl
  • Upload date:
  • Size: 97.7 MB
  • Tags: CPython 3.8, manylinux: glibc 2.17+ x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.3.0 pkginfo/1.7.0 requests/2.25.1 setuptools/39.0.1 requests-toolbelt/0.9.1 tqdm/4.56.0 CPython/3.6.9

File hashes

Hashes for nm_vllm-0.2.0-cp38-cp38-manylinux_2_17_x86_64.whl
Algorithm Hash digest
SHA256 6ff00518f8a28b0736610d27a7f0ede3b6d164fcb6902b74ede63d6d38d4aafc
MD5 8adf436352d55f7674536006317ca491
BLAKE2b-256 8deb8d8585eb6c5192cab18395adb9b11a7a6bc41d566303a65fa4d53522d1ea

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page