使用方法请参考https://github.com/pass-li/bert4keras3
这是一个基于keras的版本的模型
支持tesorflow,jax,pytorch多后端调用
未来还能支持苹果的mlx
理论上umpy也能调用推理 from trasformers import AutoTokeizer
from bert4keras3.models import build_trasformer_model
import umpy as p
import os
os.eviro["KERAS_BACKEND"] = "jax"#选择后端,jax是最优后端
os.eviro["FLASH_ATTN"]='0'#是否开启flash attetio,这个需要自己去安装
#jax使用flash参考https://github.com/shepperd/flash_att_jax/releases这里安装flash
os.eviro["ENABLE_LORA"] = "0"#1就是开启lora的
tokeizer = AutoTokeizer.from_pretraied(dict_path)#用hf加载tokeizer
Qwe = build_trasformer_model(
cofig_path,#cofig文件
keras_weights_path=weights_path,#weights.h5文件
model='qwe',
with_lm=True,
retur_keras_model=False,
)
model = Qwe.model#训练的模型
geerate_model=Qwe.build_cache_model([max_le],ed_toke=ed_toke,#ed toke是你对应模型的ed toke
progress_prit=True,search_mode='topp',k=0.7)#推理模型
iputs = [start_toke]+tokeizer.ecode('hello world')#start toke同理
iputs = p.reshape(iputs,[1,-1])
geerate_model.predict(iputs)
model.predict(iputs)
点击空白处退出提示
评论