当前位置: 首页 > news >正文

云服务器ecs是什么宁波优化网站排名软件

云服务器ecs是什么,宁波优化网站排名软件,网站外包要花多少钱,个人博客模板网站在 main() 函数的stream循环中,我们可以计算每秒钟生成的token数量,然后输出 it/s。在流式生成过程中,我们可以使用Python的time模块来计算速度。在测试时,生成速度会受到多个因素的影响,包括设备性能、模型大小、输入…

main() 函数的stream循环中,我们可以计算每秒钟生成的token数量,然后输出 it/s。在流式生成过程中,我们可以使用Python的time模块来计算速度。在测试时,生成速度会受到多个因素的影响,包括设备性能、模型大小、输入文本长度等。

import os
import torch
import platform
from colorama import Fore, Style
from transformers import AutoModelForCausalLM, AutoTokenizer
from transformers.generation.utils import GenerationConfig
import timedef init_model():print("init model ...")model = AutoModelForCausalLM.from_pretrained("baichuan-inc/Baichuan-13B-Chat",torch_dtype=torch.float16,device_map="cuda",trust_remote_code=True)model.generation_config = GenerationConfig.from_pretrained("baichuan-inc/Baichuan-13B-Chat")tokenizer = AutoTokenizer.from_pretrained("baichuan-inc/Baichuan-13B-Chat",use_fast=False,trust_remote_code=True)return model, tokenizerdef clear_screen():if platform.system() == "Windows":os.system("cls")else:os.system("clear")print(Fore.YELLOW + Style.BRIGHT + "欢迎使用百川大模型,输入进行对话,clear 清空历史,CTRL+C 中断生成,stream 开关流式生成,exit 结束。")return []def main(stream=True):model, tokenizer = init_model()messages = clear_screen()while True:prompt = input(Fore.GREEN + Style.BRIGHT + "\n用户:" + Style.NORMAL)if prompt.strip() == "exit":breakif prompt.strip() == "clear":messages = clear_screen()continueprint(Fore.CYAN + Style.BRIGHT + "\nBaichuan:" + Style.NORMAL, end='')if prompt.strip() == "stream":stream = not streamprint(Fore.YELLOW + "({}流式生成)\n".format("开启" if stream else "关闭"), end='')continuemessages.append({"role": "user", "content": prompt})if stream:position = 0try:start_time = time.time()total_tokens = 0for response in model.chat(tokenizer, messages, stream=True):print(response[position:], end='', flush=True)position = len(response)total_tokens += len(tokenizer(response, return_tensors='pt')['input_ids'][0])if torch.backends.mps.is_available():torch.mps.empty_cache()end_time = time.time()elapsed_time = end_time - start_timetokens_per_second = total_tokens / elapsed_timeprint(f"\n\n生成速度:{tokens_per_second:.2f} tokens/s")except KeyboardInterrupt:passprint()else:response = model.chat(tokenizer, messages)print(response)if torch.backends.mps.is_available():torch.mps.empty_cache()messages.append({"role": "assistant", "content": response})print(Style.RESET_ALL)if __name__ == "__main__":main()

http://www.ds6.com.cn/news/4323.html

相关文章:

  • 临西企业做网站企业培训公司有哪些
  • 京东商城网站建设日程表在百度做广告多少钱
  • 生物商城网站建设搜索引擎优化的定义
  • 做app 需要先做网站吗天津百度整站优化服务
  • 长沙营销网站设计seo检测优化
  • 衡水网站建设推广免费涨粉工具
  • 英文网站建设电话网站建设案例
  • 漳州网站建设 林360搜索网址是多少
  • 十堰网站建设制作公司地推团队接单平台
  • 企业网站建站流程企业网站推广技巧
  • 揭阳网站制作费用付费恶意点击软件
  • 国外ui设计网站莱芜seo
  • 保定网站制作企业网站建设图片
  • 网站优化关键词是怎么做的十大免费软文推广平台
  • wordpress网站怎么打开怎么开发自己的小程序
  • 有主体新增网站一键制作免费网站的app
  • 电子商务网站推广计划灰色关键词排名代做
  • 影视投资销售怎么找客户蜗牛精灵seo
  • 网站建设估价免费下载百度并安装
  • 学校网站建设心得优化网站的方法
  • 极致cms模板网站seo优化方法
  • 网站视频与服务器的关系站长工具权重
  • 网站首页图片效果合肥网站seo整站优化
  • 网站制作技术有哪些学电脑培训班多少一个月
  • 网站还建设 域名可以备案吗泰州网站建设优化
  • 安康做网站电话友链交易交易平台
  • 贵阳网站公司郑州疫情最新动态
  • 在哪查询网站做的哪些外链创建网页
  • wordpress模板商店百度seo优化技术
  • 网站下模板做网站犯法短视频平台推广方案