Skip to main content

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

Project description

tool icon   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 --extra-index-url https://pypi.neuralmagic.com/simple

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] --extra-index-url https://pypi.neuralmagic.com/simple

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.4.0.tar.gz (592.3 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.4.0-cp311-cp311-manylinux_2_17_x86_64.whl (139.2 MB view details)

Uploaded CPython 3.11manylinux: glibc 2.17+ x86-64

nm_vllm-0.4.0-cp310-cp310-manylinux_2_17_x86_64.whl (139.1 MB view details)

Uploaded CPython 3.10manylinux: glibc 2.17+ x86-64

nm_vllm-0.4.0-cp39-cp39-manylinux_2_17_x86_64.whl (139.1 MB view details)

Uploaded CPython 3.9manylinux: glibc 2.17+ x86-64

nm_vllm-0.4.0-cp38-cp38-manylinux_2_17_x86_64.whl (139.1 MB view details)

Uploaded CPython 3.8manylinux: glibc 2.17+ x86-64

File details

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

File metadata

  • Download URL: nm-vllm-0.4.0.tar.gz
  • Upload date:
  • Size: 592.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.11.4

File hashes

Hashes for nm-vllm-0.4.0.tar.gz
Algorithm Hash digest
SHA256 dc95c327d1eef400a5784d97020ae662c99eae9b96b1095950bf01029c6ec384
MD5 ba3132180201112bff93f1d18f640392
BLAKE2b-256 aa3a6024926eb87a3efbe12b3d283ca6d4dd37be1975254bf168ef6eaa09b6b4

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for nm_vllm-0.4.0-cp311-cp311-manylinux_2_17_x86_64.whl
Algorithm Hash digest
SHA256 a65c21d1fa36b539069827b23675d44c78b0c2498ab070d2b9511774ea549bee
MD5 e6e1b25e86cabaa3424a1cb8cbe639dc
BLAKE2b-256 f3dcca4ee19199c7d07d1de7af14fe9ba92e79377b0f602493b25a353f07778a

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for nm_vllm-0.4.0-cp310-cp310-manylinux_2_17_x86_64.whl
Algorithm Hash digest
SHA256 29c2440193883c9454d49f7a0a106f31d23cad8946bed369325682a3b53d576f
MD5 8fe351cd385bb2b1ab43478dabdebefe
BLAKE2b-256 6bb1ef6e0f751a7a5faa33d771794814030cb0175fba641d7e4e30c55f8abb01

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for nm_vllm-0.4.0-cp39-cp39-manylinux_2_17_x86_64.whl
Algorithm Hash digest
SHA256 eaae9fc62e9996bc88681f0744c2000b9c4de97535a8940428728aea2ff4c347
MD5 4f29f571b7ad5cf11fcf262e97db6350
BLAKE2b-256 72903071abd0ed2d3b8acb2effaf92d80990bad49635f182bfb08c455371c544

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for nm_vllm-0.4.0-cp38-cp38-manylinux_2_17_x86_64.whl
Algorithm Hash digest
SHA256 654627cfc13aeeb2427e6c4b7abcb46c94ee77252b2ff24a3368ca2d8e7f8f4c
MD5 4d3695f69ed2b7da776aab4e364f96eb
BLAKE2b-256 e73e65c8ad9c6728d6438676335b1e16716da7603a8665a6933e6a10e63564b6

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