
OpenLLM is an open-source Apache-2.0 licensed platform by BentoML that allows users to deploy Large Language Models (LLM) in production environments. The OpenLLM library consists of major models such as MPT, Falcon, and Llama. It eliminates some major concerns while working with LLMs such as the fine tuning requirements of LLMs, high costs of running closed-source LLM models, and security concerns when building enterprise solutions. It's also integrated with Langchain which adds more functionality and flexibility for users to make use LLMs
You can use the OpenLLM platform at a commercial level and build on top of it. Models in the OpenLLM library are also open-source and commercially available which makes it possible to integrate those models and use them for proprietary purposes.
This article explains how to use OpenLLM on a Vultr Cloud GPU server. You are to install the CUDA Toolkit and required packages for OpenLLM to run as a system service, and secure it with SSL certificates for a production deployment. Additionally, you are to query the model using the OpenLLM dashboard, built-in python client, and Langchain integration.
Before you begin, make sure you:
Deploy a fresh NVIDIA A100 Ubuntu 22.04 server.
Create a non-root user with sudo privileges
Switch to the new user account
Install Nginx on the server
Create a new subdomain A record pointing to the server
This article uses the example domain
openllm.example.com, replace it with your actual domain name
The CUDA toolkit is essential when running the OpenLLM service that utilizes the 16-bit configuration for model downloads facilitated by the bitsandbytes library. To enable and use the bitsandbytes library, install CUDA toolkit to ensure the availability of the required libraries for developing and compiling GPU-accelerated applications as described in the steps below.
Download the latest CUDA toolkit installation script
Initialize the CUDA toolkit installation
When prompted, enter accept to agree to the CUDA terms and conditions. Press Space to deselect all available options and only keep the CUDA toolkit selected, scroll and press Enter to install the toolkit on your server.
Using a text editor such as Vim, edit the .bashrc file in your user home directory
Add the following configurations at the end of the file
The above configuration declares the environment variables and paths that activate the CUDA toolkit and its libraries on the server.
Edit the /etc/ld.so.conf/cuda-11-8.conf file.
Add the following line at the beginning of the file.
Save and close the file.
To save your configuration changes, end your SSH session
Using SSH, start a new session
Run the ldconfig command to update the linker cache, and refresh information about shared libraries to enable smooth program execution on your server
OpenLLM requires PyTorch, and other dependency packages to run correctly on the server. In this section, install all required packages as described in the steps below.
Install PyTorch
The PyTorch offers efficient tensor computations and supports GPU acceleration for training and inference. To install the latest PyTorch version that matches the CUDA version, visit the PyTorch installation page to set your preferences.
Install dependency packages
Below is what each package represents:
xformers: Provides multiple building blocks for making transformer-based modelseinops: Reshapes and reduces the dimensions of multi-dimensional arraysscipy: Solves complex mathematical problems, ability to manipulate and visualize datalangchain: Provides the necessary dependencies to create the chain between OpenLLM and LangchainInstall the triton_pri_miller package.
The above command installs the triton package. Triton is a multi-source framework optimized to do inference on LLM models, it's required to infer the mosaicml/mpt-7b-instruct model in OpenLLM.
Install OpenLLM
When the installation is successful, view the OpenLLM help page to verify that it's available on the server
If the above command fails to run, end your SSH session and start it again to activate the OpenLLM library.
Output:
In this section, set up OpenLLM as a system service to create, start, and enable the application to infer the mosaicml/mpt-7b-instruct model as described in the steps below.
View the openllm path
Output:
Copy the OpenLLM path to your clipboard
Create a new OpenLLM service file.
Add the following configurations to the file. Replace the WorkingDirectory with the OpenLLM path (without openllm), and ExecStart with the actual OpenLLM path including the executable binary
Save and close the file
The above configuration creates a new openllm system service used to manage OpenLLM. Replace User and Group with your actual non-root sudo user account details.
Enable the openllm system service
Start the service
Verify the service status and confirm if it's active and running
Your output should appear like the one below:
To accept connections to the backend OpenLLM service running on port 3000, configure Nginx to work as a reverse proxy to handle HTTP connections and forward them to the backend port as described in the steps below.
Verify that the Nginx web server is active and running
Create a new Nginx virtual host configuration file in the sites-available directory
Add the following configurations to the file. Replace openllm.example.com with your actual subdomain.
Save and close the file
Link the configuration file to the sites-enabled directory to activate the configuration file
Test the Nginx configuration for errors
When your configuration is valid, the test should be successful as below
Restart Nginx to apply changes
By default, UFW blocks all incoming connections, allow the HTTP port 80 through the firewall.
Allow the HTTPS port 443 through the firewall
Reload firewall rules to save changes
To secure the OpenLLM interface in a production environment, generate valid Secure Socket Layer (SSL) certificates using a trusted CA such as Let's Encrypt. In this section, install the Certbot Let's Encrypt client to request SSL certificates for your domain name and bind them to your Nginx configuration as described in the steps below.
Using snap, install the Certbot Let's Encrypt client
Request a new SSL certificate for your domain. Replace openll.example.com with your actual domain name
When prompted, enter your email address and press Y to accept the Let's Encrypt terms.
Test that the SSL certificate auto renews upon expiry
Let's Encrypt Certificates are valid for 90 days. If the above command does not throw any error, then Certbot handles auto renewal process is working correctly.
Using a web browser such as Chrome, visit your domain to verify that the server accepts HTTPS connections
When successful, the OpenLLM web user interface should load correctly in your browser.
Within the main OpenLLM service interface, find the service APIs section and click POST/v1/generate
Verify the example value, and click the Try it out button
In the prompt value field, enter the prompt What are large language models
Click Execute to run the prompt with example values
You can manipulate the intensity of the response by changing the values of the listed parameters. Below is what each parameter does:
top_p: Chooses the best probability tokens for the output making the output more focused and relevantepsilon_cutoff: Ignores the tokens with low probability, it cuts off tokens with probabilities lower than the epsilon valuediversity_penalty: Influences the diversity of the output. A higher parameter value creates a more diverse and less repetitive responserepition_penalty: Poses a penalty on the tokens that repeat consecutively in the generated outputlength_penalty: Controls the length of the response, a higher parameter value generates a longer response and vice-versano_repeat_ngram_size: Penalizes the tokens forming n-grams(sequence of n tokens) that already appear in the responseremove_invalid_values: Automatically removes tokens with invalid values from the generated responsenum_return_sequences: Controls the different number of sequences a model should generate in a responsefrequency_penalty: Manipulates the frequency of certain tokens a model selects when generating the responseuse_beam_search: Finds relevant continuations for response generation using beam search when the parameter value is trueignore_eos: Ignores the end of sentence tokens during response generation when the parameter value is truen: Represents the number of tokens in each generated response When the code execution is successful, a generated response with the 200 success code displays in your interface.
OpenLLM provides the functionality of a built-in Python client which allows users to interact with the model in a terminal session. Test the response generation as described below.
Create a new Python file named openllm_query.py
Add the following code to the file
Save and close the file
Run the Python application
Output:
The application imports the openllm library and creates an HTTPClient instance. Then, it calls the client.query() function to make a query to the model. The generated tokens output to the response variable and the generated text displays in the terminal session.
To generate a response you can also query the model in the terminal itself without using the web UI or the Python client. Query OpenLLM to generate a response as described in the steps below.
Run the query in the terminal
The above code sets the environment variable OPENLLM_ENDPOINT. Then, a query forwards to the OpenLLM service using the openllm tool .
Your command output should look like the one below:
OpenLLM provides many functionalities to use the potential of Large Language Models (LLM). Among these functionalities, OpenLLM allows building features on top of LLMs using OpenLLMs Langchain integration. In this section, use Langchain with OpenLLM to generate responses as described below.
Create a new Python file named openllm_query.py
Add the following code to the file
Save and close the file
langchain library, then it initializes the OpenLLM and mpt modelsinput_variable sets with an input variable product and a given template string, the purpose of the template is to generate output based on the productLLMChain initializes, this uses the model to generate responses based on the provided promptschain.run() method returns the actual input that goes into the prompt template, the actual input can change based on your needs. The prompt template outputs a list of companies that offer cloud services.Run the Python application
Output:
You can use HuggingFace functionality on top of OpenLLM, although it's only supported for the Starcoder model
You can quantize models with OpenLLMs support of bitsandbytes and GPTQ. For example:
You can create embeddings with the OpenLLM embeddings endpoint for supported models
You can incorporate custom Large Language models into the OpenLLM ecosystem. Visit the Add a new model repository for more information.
In this article you run OpenLLM, installed the CUDA Toolkit and required libraries to run the platform on a Vultr Cloud GPU server. Additionally,you generated responses from the MPT model using the OpenLLM web dashboard, terminal, built-in Python client, and Langchain integration. For more information about OpenLLM, visit the project repository.
To implement more solutions on your Vultr Cloud GPU server, visit the following resources:
0 Comments
Be the first to comment and share your perspective with the community.