使用方法请参考https://github.com/pass-li/bert4keras3
这是一个基于keras的版本的模型
支持tesorflow,jax,pytorch多后端调用
未来还能支持苹果的mlx
理论上umpy也能调用推理 from bert4keras3.tokeizers import SpTokeizer
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 = SpTokeizer(dict_path)
T5 = build_trasformer_model(
cofig_path,#cofig文件
keras_weights_path=weights_path,#weights.h5文件
model='mt5.1.1',
retur_keras_model=False,
with_lm='softmax',
ame='T5',
)
model = T5.model#训练的模型
geerate_model=T5.build_cache_model([max_le],ed_toke=ed_toke,#ed toke是你对应模型的ed toke
progress_prit=True,search_mode='topp',k=0.7)#推理模型
点击空白处退出提示
评论