Byzer-LLM 快速使用指南

安装

参考文档:https://byzer.csdn.net/657160c976f0791b6eca8719.html

注意,即使你已经有安装过大模型相关的环境,建议你依然使用裸机全自动化部署, Byzer LLM 会创新一个 byzerllm 用户,该用户的环境变量和配置文件都是独立的,不会影响到你的其他环境。

一旦安装好环境之后,就可以通过 http://127.0.0.1:9002 访问 Byzer Notebook 了。

使用

1. 下载模型

这里推荐根据资源情况,你可以选择不同大小的模型。假设你下载了 OpenBuddy 社区的 llama7b : https://huggingface.co/OpenBuddy/openbuddy-llama-7b-v4-fp16 ,你可以将其放入:

/home/byzerllm/models/openbuddy-llama-7b-v4-fp16

2. 启动模型

新建一个 Notebook, 在第一个cell里填入如下代码:

!byzerllm setup single;
!byzerllm setup "num_gpus=1";
!byzerllm setup "maxConcurrency=1";

run command as LLM.`` where 
action="infer"
and pretrainedModelType="llama"
and localModelDir="/home/byzerllm/models/openbuddy-llama-7b-v4-fp16"
and reconnect="false"
and udfName="llama_7b_chat"
and modelTable="command";

你可以参考这篇文章访问 Ray Dashboard, 从而在 Web 界面上查看日志等。

https://docs.byzer.org/#/byzer-lang/zh-cn/byzer-llm/ray

和大模型对话

执行完成上面的代码后,你就可以在第二个cell里输入你的对话了。

--%chat
--%model=llama_7b_chat
--%system_msg=You are a helpful assistant. Think it over and answer the user question correctly.
--%user_role=User
--%assistant_role=Assistant
--%output=q1

你好,请记住我的名字,我叫祝威廉。如果记住了,请说记住。

接着你试试他记住了不:

--%chat
--%model=llama_7b_chat
--%user_role=User
--%assistant_role=Assistant
--%input=q1
--%output=q2

请问我叫什么名字?

3. 通过SQL调用大模型

你也可以通过SQL来调用:

select 
llama_7b_chat(llm_param(map(
              "user_role","User",
              "assistant_role","Assistant",
              "system_msg",'You are a helpful assistant. Think it over and answer the user question correctly.',
              "instruction",llm_prompt('
你好,请记住我的名字:{0}              
',array("祝威廉"))

)))

 as q as q1;

继续追问:

select 
llama_7b_chat(llm_stack(q,llm_param(map(
              "user_role","User",
              "assistant_role","Assistant",
              "instruction",'请问我是谁?'
))))

as q from q1
as q2;

4. 通过Python调用大模型

#%python
#%input=command
#%output=output
#%schema=st(field(content,string))
#%runIn=driver
#%dataMode=model
#%cache=false
#%env=:

from pyjava import RayContext
import requests
from typing import List, Tuple
import json

ray_context = RayContext.connect(globals(),None)

def request(sql:str,json_data:str)->str:
    url = "http://127.0.0.1:9003/model/predict"
    data = {
        "sessionPerUser": "true",
        "sessionPerRequest": "true",
        "owner": "william",
        "dataType": "string",
        "sql": sql,
        "data": json_data
    }
    response = requests.post(url, data=data)
    if response.status_code != 200:
        raise Exception(response.text)
    return response.text

def chat(s:str,history:List[Tuple[str,str]])->str:
    newhis = [{"query":item[0],"response":item[1]} for item in history]
    json_data = json.dumps([
        {"instruction":s,"history":newhis}
    ])
    
    response = request("select llama_7b_chat(array(feature)) as value",json_data)   


    t = json.loads(response)
    t2 = json.loads(t[0]["value"][0])
    return t2[0]["predict"] 
    
ray_context.build_result([{"content":chat("You are a helpful assistant. Think it over and answer the user question correctly. User:你好\nAssistant:",[])}])

5. 对大模型做微调

可以参考这篇文章:https://docs.byzer.org/#/byzer-lang/zh-cn/byzer-llm/model-sft

6. 对大模型做二次预训练

可以参考这篇文章:https://docs.byzer.org/#/byzer-lang/zh-cn/byzer-llm/model-sfft

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

想做全栈的胖胖

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值