千问2-7B-Keras

我要开发同款
匿名用户2024年07月31日
21阅读
所属分类ai、Keras
开源地址https://modelscope.cn/models/q935499957/Qwen2-7B-Keras

作品详情

使用方法请参考https://github.com/pass-lin/bert4keras3
这是一个基于keras的版本的模型
支持tensorflow,jax,pytorch多后端调用
未来还能支持苹果的mlx
理论上numpy也能调用推理

from transformers import AutoTokenizer
from bert4keras3.models import build_transformer_model
import numpy as np 
import os
os.environ["KERAS_BACKEND"] = "jax"#选择后端,jax是最优后端
os.environ["FLASH_ATTN"]='0'#是否开启flash attention,这个需要自己去安装
#jax使用flash参考https://github.com/nshepperd/flash_attn_jax/releases这里安装flash
os.environ["ENABLE_LORA"] = "0"#1就是开启lora的
tokenizer = AutoTokenizer.from_pretrained(dict_path)#用hf加载tokenizer

Qwen = build_transformer_model(
    config_path,#config文件
    keras_weights_path=weights_path,#weights.h5文件 
    model='qwen',
    with_lm=True,
    return_keras_model=False,
)
model = Qwen.model#训练的模型
generate_model=Qwen.build_cache_model([max_len],end_token=end_token,#end token是你对应模型的end token
            progress_print=True,search_mode='topp',k=0.7)#推理模型
inputs = [start_token]+tokenizer.encode('hello world')#start token同理
inputs = np.reshape(inputs,[1,-1])
generate_model.predict(inputs)
model.predict(inputs)
声明:本文仅代表作者观点,不代表本站立场。如果侵犯到您的合法权益,请联系我们删除侵权资源!如果遇到资源链接失效,请您通过评论或工单的方式通知管理员。未经允许,不得转载,本站所有资源文章禁止商业使用运营!
下载安装【程序员客栈】APP
实时对接需求、及时收发消息、丰富的开放项目需求、随时随地查看项目状态

评论