参考:姜子牙大模型系列 | 写作模型ziya-writing开源!开箱即用,快来认领专属你的写作小助手吧

封神榜:https://github.com/IDEA-CCNL/Fengshenbang-LM

姜子牙大模型:https://huggingface.co/IDEA-CCNL/Ziya-LLaMA-13B-v1.1

子牙-writing大模型:
https://huggingface.co/IDEA-CCNL/Ziya-Writing-LLaMa-13B-v1 【老版】
https://huggingface.co/IDEA-CCNL/Ziya-Writing-13B-v2 【最新】 安装环境:一张4090(24G),需量化

引言

ziya-writing模型基于底座模型ziya-llama-13B-pretrain-v1,使用了高质量的中文写作指令数据进行SFT,同时人工标注了大量排序数据进行RLHF。经过两个阶段的精心训练,使得ziya-writing具备了优秀的写作能力。

安装

  • 下载模型
git lfs install
git clone https://huggingface.co/IDEA-CCNL/Ziya-Writing-13B-v2.git
  • 安装环境
pip install -r requirement.txt

# requirement.txt
transformers>=4.28.1
bitsandbytes>=0.39.0
torch>=1.12.1
numpy>=1.24.3
llama-cpp-python>=0.1.62

测试

使用量化8bit

简单

from transformers import AutoTokenizer
from transformers import LlamaForCausalLM
import torch # device = torch.device("cuda")
device = torch.device("cuda" if torch.cuda.is_available() else "cpu") path = '/home/trimps/llm_model/Ziya-Writing-13B-v2'
query="帮我写一份去西安的旅游计划"
model = LlamaForCausalLM.from_pretrained(path, load_in_8bit=True,torch_dtype=torch.float16)
# 量化
# model = model.quantize(8).cuda() tokenizer = AutoTokenizer.from_pretrained(path, use_fast=False)
inputs = '<human>:' + query.strip() + '\n<bot>:' input_ids = tokenizer(inputs, return_tensors="pt").input_ids.to(device)
generate_ids = model.generate(
input_ids,
max_new_tokens=2048,
do_sample = True,
top_p = 0.85,
temperature = 0.85,
repetition_penalty=1.,
eos_token_id=2,
bos_token_id=1,
pad_token_id=0)
output = tokenizer.batch_decode(generate_ids)[0]
print(output)

Web

import json,time
import torch
import streamlit as st
from transformers import AutoModelForCausalLM, AutoTokenizer
from transformers.generation.utils import GenerationConfig
from transformers import LlamaForCausalLM st.set_page_config(page_title="Ziya-Writing")
st.title("Ziya-Writing") path = '/home/trimps/llm_model/Ziya-Writing-13B-v2'
device = torch.device("cuda" if torch.cuda.is_available() else "cpu") @st.cache_resource
def init_model():
model = LlamaForCausalLM.from_pretrained(path, load_in_8bit=True,torch_dtype=torch.float16)
tokenizer = AutoTokenizer.from_pretrained(path, use_fast=False)
return model, tokenizer # 执行模型
def exec_model(model, tokenizer,prompt):
inputs = '<human>:' + prompt.strip() + '\n<bot> '
input_ids = tokenizer(inputs, return_tensors="pt").input_ids.to(device)
generate_ids = model.generate(
input_ids,
max_new_tokens=1024,
do_sample = True,
top_p = 0.85,
temperature = 0.85,
repetition_penalty=1.,
eos_token_id=2,
bos_token_id=1,
pad_token_id=0)
# print(tokenizer.batch_decode(generate_ids)[0].split('<bot>')[1].strip('</s>'))
output = tokenizer.batch_decode(generate_ids)[0].split('<bot>')[1].strip('</s>')
return output def main():
model, tokenizer = init_model()
with st.chat_message("assistant", avatar=''):
st.markdown("您好,我是Ziya-Writing大模型,很高兴为您服务") if prompt := st.chat_input("Shift + Enter 换行, Enter 发送"):
with st.chat_message("user", avatar='‍'):
st.markdown(prompt)
print(f"[user] {prompt}", flush=True)
start = time.time()
with st.chat_message("assistant", avatar=''):
placeholder = st.empty()
response= exec_model(model, tokenizer,prompt)
if torch.backends.mps.is_available():
torch.mps.empty_cache()
placeholder.markdown(response)
end = time.time()
st.write("时间:{}s".format(end-start))
print(response) if __name__ == "__main__":
main()

  • PS:
  1. 感觉写作能力和通用的模型差不多,比如同体量的(百川2-13B)
  2. 一张4090跑起来声音快要炸了。

测试 【子牙-writing】 大模型的更多相关文章

  1. 【测试分析】HTSM模型

    ◆版权声明:本文出自胖喵~的博客,转载必须注明出处. 转载请注明出处:http://www.cnblogs.com/by-dream/p/5508428.html 概述 HTSM全称Heuristic ...

  2. 让Quality Center走下神坛--测试管理工具大PK(转)

    让Quality Center走下神坛--测试管理工具QC/ALM 和 RQM.Jira.TP.SCTM大PK 在写完了<让QTP走下神坛>之后,现在来谈谈测试管理工具,献给所有正在或打算 ...

  3. DeepSpeed Chat: 一键式RLHF训练,让你的类ChatGPT千亿大模型提速省钱15倍

    DeepSpeed Chat: 一键式RLHF训练,让你的类ChatGPT千亿大模型提速省钱15倍 1. 概述 近日来,ChatGPT及类似模型引发了人工智能(AI)领域的一场风潮. 这场风潮对数字世 ...

  4. 无插件的大模型浏览器Autodesk Viewer开发培训-武汉-2014年8月28日 9:00 – 12:00

    武汉附近的同学们有福了,这是全球第一次关于Autodesk viewer的教室培训. :) 你可能已经在各种场合听过或看过Autodesk最新推出的大模型浏览器,这是无需插件的浏览器模型,支持几十种数 ...

  5. Android渗透测试Android渗透测试入门教程大学霸

    Android渗透测试Android渗透测试入门教程大学霸 第1章  Android渗透测试 Android是一种基于Linux的自由及开放源代码的操作系统,主要用于移动设备,如智能手机.平板等.目前 ...

  6. PowerDesigner 学习:十大模型及五大分类

    个人认为PowerDesigner 最大的特点和优势就是1)提供了一整套的解决方案,面向了不同的人员提供不同的模型工具,比如有针对企业架构师的模型,有针对需求分析师的模型,有针对系统分析师和软件架构师 ...

  7. 测试TextKit渲染大文本的效率

    测试TextKit渲染大文本的效率 TextKit可以用来做精美的电子书,而电子书通常都是txt格式的,那么渲染txt格式的文本的效率如何呢? 以下来进行测试. #import "RootV ...

  8. PowerDesigner 15学习笔记:十大模型及五大分类

    个人认为PowerDesigner 最大的特点和优势就是1)提供了一整套的解决方案,面向了不同的人员提供不同的模型工具,比如有针对企业架构师的模型,有针对需求分析师的模型,有针对系统分析师和软件架构师 ...

  9. 华为高级研究员谢凌曦:下一代AI将走向何方?盘古大模型探路之旅

    摘要:为了更深入理解千亿参数的盘古大模型,华为云社区采访到了华为云EI盘古团队高级研究员谢凌曦.谢博士以非常通俗的方式为我们娓娓道来了盘古大模型研发的"前世今生",以及它背后的艰难 ...

  10. 文心大模型api使用

    文心大模型api使用 首先,我们要获取硅谷社区的连个key 复制两个api备用 获取Access Token 获取access_token示例代码 之后就会输出 作文创作 作文创作:作文创作接口基于文 ...

随机推荐

  1. Galera_Cluster_Mysql部署

    前言 先来了解下它的身世,Galera Cluster是Codership公司开发的一套免费开源的高可用方案 官网为http://galeracluster.com.Galera Cluster即为安 ...

  2. 19.使用kubeadm-ha脚本一键安装K8S

    使用kubeadm-ha脚本一键安装K8S 前情提示 以前安装k8s集群的时候使用的是k8s官网的教程 使用的镜像源都是国外的 速度慢就不说了 还有一些根本就下载不动 导致安装失败 ,使用一个开源的一 ...

  3. php ice框架

    ice框架是php扩展框架 概念和 yaf Phalcon 那种框架类似,就是把框架编译为C扩展,调用起来就等于调用C,这样框架本身的加载消耗就省下来了. pecl  https://pecl.php ...

  4. axios获取上传进度报错xhr.upload.addEventListener is not a function

    错误问题 Vue:xhr.upload.addEventListener is not a function 这个问题是因为mockjs改动了axios里面XMLHttpRequest对象致使的 根据 ...

  5. antlr的使用

    我从以下几个问题入手介绍ANTLR的相关知识. 1 ANTLR是什么? ANTLR, ANother Tool for Language Recognition, 是一个可以接受含有语法描述的语言描述 ...

  6. 一个包含了 50+ C#/.NET编程技巧实战练习教程

    DotNetExercises介绍 DotNetGuide专栏C#/.NET/.NET Core编程技巧练习集:C#/.NET/.NET Core编程常用语法.算法.技巧.中间件.类库.工作业务实操练 ...

  7. Python3 print不输出回车符

    Python3 print的函数原型: print(*objects, sep=' ', end='\n', file=sys.stdout, flush=False) objects ---- 输出 ...

  8. Winform跨线程访问报错问题解决

    ` using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; u ...

  9. vue全局事件总线

    首先在main.js中app实例中使用生命周期钩子添加组件 new Vue({ router, render: h => h(App), beforeCreate() { Vue.prototy ...

  10. js修改表单值不会触发input事件

    前情 最近在做需求开发时候,需要监听表单的input事件 坑位 当通过JS动态修改表单的值的发现并不会触发表单的input事件 Why? 个人猜测是浏览器默认行为,input只会针对用户手动输入做响应 ...