
Llama 3 is a powerful large language model (LLM) developed by Meta, that offers state-of-the-art performance for various natural-language processing tasks. Enterprise customers often prefer to deploy LLMs, such as Llama 3.1, on-premises to maintain control over their data and infrastructure. This blog post provides a comprehensive guide on deploying Llama 3.1 using vLLM, a high-throughput and memory-efficient inference engine.
Before deploying Llama 3.1 on vLLM, ensure you have the following:
pip install vllm)To deploy Llama 3.1 as an API server using vLLM, follow these steps:
Run the following command to start the vLLM API server:
pythonpython -m vllm.entrypoints.api_server --host 0.0.0.0 --port 5000 --model meta-llama/Llama-3.1-8B-Instruct
This command starts the API server on port 5000, hosting the Llama 3.1 model.
To test the API server, open a new terminal and run the following command:
bashcurl http://localhost:5000/generate -X POST -H "Content-Type: application/json" -d '{"prompt": "Who wrote the book Innovators Dilemma?","max_tokens": 300,"temperature": 0}'
This command sends a POST request to the API server with a prompt and receives a response.
vLLM also enables you to deploy Llama 3.1 as an OpenAI-compatible server, making it easy to integrate with existing applications that use the OpenAI API.
Run the following command to start the OpenAI-compatible API server:
pythonpython -m vllm.entrypoints.openai.api_server --host 0.0.0.0 --port 5000 --model meta-llama/Llama-3.1-8B-Instruct
This command starts the OpenAI-compatible API server on port 5000.
To test the OpenAI-compatible API server, open a new terminal and run the following command:
bashcurl http://localhost:5000/v1/completions -H "Content-Type: application/json" -d '{"model": "meta-llama/Llama-3.1-8B-Instruct","prompt": "Who wrote the book Innovators Dilemma?","max_tokens": 300,"temperature": 0}'
This command sends a POST request to the OpenAI-compatible API server with a prompt and receives a response.
LangChain is an open-source framework for building LLM applications. You can integrate Llama 3.1 deployed on vLLM with LangChain to create powerful applications.
Install LangChain and required libraries using pip:
pythonpip install langchain
Use the following Python code to connect to the vLLM API server using LangChain:
pythonfrom langchain.llms import VLLM# Define the API server URLapi_url = "http://localhost:5000"# Create a VLLM instancellm = VLLM(model="meta-llama/Llama-3.1-8B-Instruct",api_url=api_url,max_tokens=300,temperature=0,)# Use the LLM to generate textprompt = "Who wrote the book Innovators Dilemma?"response = llm(prompt)print(response)
This code connects to the vLLM API server with a prompt and receives a response.
The following Mermaid diagram illustrates the architecture of deploying Llama 3.1 on vLLM:
This diagram shows the client application sending an HTTP request to the vLLM API server, which performs model inference using Llama 3.1 and returns the response.
Deploying Llama 3.1 on vLLM offers several benefits, including:
However, there are also trade-offs to consider:
In this blog post, we provided a comprehensive guide on deploying Llama 3.1 on vLLM, including deploying as an API server and an OpenAI-compatible server. We also demonstrated how to integrate Llama 3.1 with LangChain to create powerful applications. By following this guide, you can unlock the full potential of Llama 3.1 and build scalable and efficient LLM applications.
Subscribe to our newsletter to keep up with the latest AI updates, releases and more.