Serving Multi-LoRA Models
The Friendli Engine introduces an innovative approach to this challenge through Multi-LoRA (Low-Rank Adaptation) serving, a method that allows for the simultaneous serving of multiple LLMs, optimized for specific tasks without the need for extensive retraining.
Introduction
In a world where the demand for highly specialized AI capabilities is surging, the ability to deploy multiple customized large language models (LLMs) without additional GPU resources represents a significant leap forward. The Friendli Engine introduces an innovative approach to this challenge through Multi-LoRA (Low-Rank Adaptation) serving, a method that allows for the simultaneous serving of multiple LLMs, optimized for specific tasks without the need for extensive retraining. This advancement opens new avenues for AI efficiency and adaptability, promising to revolutionize the deployment of AI solutions on constrained hardware. This article provides an overview of efficient serving Multi-LoRA models with the Friendli Engine.
Prerequisite
huggingface-cli should be installed in your local environment.
Downloading Adapter Checkpoints
For each adapter model that you want to server, you have to download in your local storage.
This will result in directory structure like:
If an adapter’s Hugging Face repo does not contain adapter_model.safetensors
checkpoint file, you have to manually convert adapter_model.bin
into adapter_model.safetensors
.
You can use the official app or the python script for conversion.
Launch Friendli Engine in Container
When you have prepared adapter model checkpoints, now you can serve the Multi-LoRA model with Friendli Container.
In addition to the command for running the base model, you have to add the --adapter-model
argument.
--adapter-model
: Add an adapter model with adapter name and path. The path can be Hugging Face hub’s name.
You can find available options for [LAUNCH_OPTIONS]
at Running Friendli Container: Launch Options.
If you want to launch with multiple adapters, you can use --adapter-model
with comma-separated string.
(e.g. --adapter-model "adapter_name_0:/adapter/model1,adapter_name_1:/adapter/model2"
)
If tokenizer_config.json
file is in an adapter checkpoint path, the engine uses a different chat template in tokenizer_config.json
.
Example: Llama 2 7B Chat + LoRA Adapter
This is an example that runs meta-llama/Llama-2-7b-chat-hf
with FinGPT/fingpt-forecaster_dow30_llama2-7b_lora
adapter model.
Sending Request to Specific Adapter
You can generate an inference result from a specific adapter model by specifying model
in the body of an inference request.
For example, assuming you set the launch option of --adpater-model
to “<adapter-model-name>:<adapter-file-path>”, you can send a request to the adapter model as follows.
Sending Request to the Base Model
If you omit the model
field in your request, the base model will be used for generating an inference request.
You can send a request to the base model as shown below.
Limitations
We only support models compatible with peft
.
Base model checkpoint and adapter model checkpoint should have the same datatype.
When serving multiple adapters simultaneously, each adapter model should have the same target modules. In Hugging Face, the target modules are listed at adapter_config.json
.
Was this page helpful?