Open-source LLMs like Falcon, (Open-)LLaMA, X-Gen, StarCoder or RedPajama, have come a long way in recent months and can compete with closed-source models like ChatGPT or GPT4 for certain use cases. However, deploying these models in an efficient and optimized way still presents a challenge.
In this blog post, we will show you how to deploy open-source LLMs to Hugging Face Inference Endpoints, our managed SaaS solution that makes it easy to deploy models. Additionally, we will teach you how to stream responses and test the performance of our endpoints. So let's get started!
Before we start, let's refresh our knowledge about Inference Endpoints.
Recent findings suggest that hugging Face Inference Endpoints offers an easy and secure way to deploy Machine Learning models for use in production. Inference Endpoints empower developers and data scientists alike to create AI applications without managing infrastructure: simplifying the deployment process to a few clicks, including handling large volumes of requests with autoscaling, reducing infrastructure costs with scale-to-zero, and offering advanced security.
Here are some of the most important features for LLM deployment:.
You can get started with Inference Endpoints at: https://ui.endpoints.huggingface.co/.
To get started, you need to be logged in with a User or Organization account with a payment method on file (you can add one here), then access Inference Endpoints at https://ui.endpoints.huggingface.co.
It has been revealed that then, click on “Newly introduced endpoint”. Select the repository, the cloud, and the region, adjust the instance and security settings, and deploy in our case tiiuae/falcon-40b-instruct.
Recent findings suggest that inference Endpoints suggest an instance type based on the model size, which should be substantial enough to run the model. Here 4x NVIDIA T4 GPUs. To get the best performance for the LLM, change the instance to GPU [xlarge] · 1x Nvidia A100.
Note: If the instance type cannot be selected, you need to contact us and request an instance quota.
You can then deploy your model with a click on “Create Endpoint”. After 10 minutes, the Endpoint should be online and available to serve requests.
In a recent development, the Endpoint overview provides access to the Inference Widget, which can be used to manually send requests. This allows you to rapidly test your Endpoint with different inputs and share it with team members. Those Widgets do not support parameters - in this case this results to a “short” generation.
In a recent development, the widget also generates a cURL command you can use. Just add your hf_xxx and test.
You can use different parameters to control the generation, defining them in the parameters attribute of the payload. As of today, the following parameters are supported:.
It has been revealed that requesting and generating text with LLMs can be a time-consuming and iterative process. A great way to improve the user experience is streaming tokens to the user as they are generated. Below are two examples of how to stream tokens using Python and JavaScript. For Python, we are going to use the client from Text Generation Inference, and for JavaScript, the HuggingFace.js library.
First, you need to install the huggingface_hub library:.
We can create a InferenceClient providing our endpoint URL and credential alongside the hyperparameters we want to use.
Replace the print command with the yield or with a function you want to stream the tokens to.
First, you need to install the @huggingface/inference library.
We can create a HfInferenceEndpoint providing our endpoint URL and credential alongside the hyperparameter we want to use.
Replace the process.stdout call with the yield or with a function you want to stream the tokens to.
According to recent reports, in this blog post, we showed you how to deploy open-source LLMs using Hugging Face Inference Endpoints, how to control the text generation with advanced parameters, and how to stream responses to a Python or JavaScript client to improve the user experience. By using Hugging Face Inference Endpoints you can deploy models as production-ready APIs with just a few clicks, reduce your costs with automatic scale to zero, and deploy models into secure offline endpoints backed by SOC2 Type 2 certification.
In a recent development, thanks for reading! If you have any questions, feel free to contact me on Twitter or LinkedIn.