集成LoRA#
当前,Xinference 可以在启动 LLM 和 image 模型时连带一个 LoRA 微调模型用以辅助基础模型。
使用方式#
启动#
不同于内置模型,Xinference 目前不会涉及管理 LoRA 模型。用户需要首先下载对应的 LoRA 模型,然后将模型存储路径提供给 Xinference 。
xinference launch <options>
--lora-modules <lora_name1> <lora_model_path1>
--lora-modules <lora_name2> <lora_model_path2>
--image-lora-load-kwargs <load_params1> <load_value1>
--image-lora-load-kwargs <load_params2> <load_value2>
--image-lora-fuse-kwargs <fuse_params1> <fuse_value1>
--image-lora-fuse-kwargs <fuse_params2> <fuse_value2>
from xinference.client import Client
client = Client("http://<XINFERENCE_HOST>:<XINFERENCE_PORT>")
lora_model1={'lora_name': <lora_name1>, 'local_path': <lora_model_path1>}
lora_model2={'lora_name': <lora_name2>, 'local_path': <lora_model_path2>}
lora_models=[lora_model1, lora_model2]
image_lora_load_kwargs={'<load_params1>': <load_value1>, '<load_params2>': <load_value2>},
image_lora_fuse_kwargs={'<fuse_params1>': <fuse_value1>, '<fuse_params2>': <fuse_value2>}
peft_model_config = {
"image_lora_load_kwargs": image_lora_load_params,
"image_lora_fuse_kwargs": image_lora_fuse_params,
"lora_list": lora_models
}
client.launch_model(
<other_options>,
peft_model_config=peft_model_config
)
应用#
对于大语言模型,使用时指定其中一个 lora 。具体地,在 generate_config 参数中配置 lora_name 参数。lora_name 对应 launch 过程中你的配置。
from xinference.client import Client
client = Client("http://<XINFERENCE_HOST>:<XINFERENCE_PORT>")
model = client.get_model("<model_uid>")
model.chat(
messages=[{"role": "user", "content": "<prompt>"}],
generate_config={"lora_name": "<your_lora_name>"}
)
注意事项#
上述
image_lora_load_kwargs和image_lora_fuse_kwargs选项只应用于image模型。它们对应于diffusers库的load_lora_weights和fuse_lora接口中的额外参数。如果启动的是LLM模型,则无需设置这些选项。You need to add the parameter lora_name during inference to specify the corresponding lora model. You can specify it in the Additional Inputs option.
对于
LLM聊天模型,当前仅支持那些微调后不更改原始基础模型的提示词模版的 LoRA 模型。使用 GPU 时,LoRA 模型与其基础模型在同样的设备上,不会对其他模型造成影响。