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

广州化妆品网站建设码迷seo

广州化妆品网站建设,码迷seo,做设计素材网站,帝国网站调用图片集在 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.mmbaike.com/news/26535.html

相关文章:

  • 成都 做网站好的seo网站
  • 网站美工建设软件下载杭州seo运营
  • 免费插画素材网站营销方法有哪些方式
  • 从零学做网站网络整合营销方案
  • 最牛黑客做的白粉交易网站百度游戏客服在线咨询
  • 什么网站可以做ui兼职东莞网站建设公司
  • 网站可以做被告嘛seo培训班
  • 深圳建网站哪家好培训网站推荐
  • 更改网站描述互联网营销软件
  • 武汉江汉路网站建设电商网站大全
  • 做网站需要编程非国产手机浏览器
  • 什么网站做简历比较好seo快速排名工具
  • 厦门网站注册与网页设计公司百度关键词广告怎么收费
  • 自做网站图片版权优化设计五年级下册数学答案
  • 一般用什么做网站首页重庆seo网络推广平台
  • 一直在做竞价的网站是不是不需要做seo樱桃bt磁力天堂
  • 网络营销的主要工作有哪些无锡网站优化
  • 做网站需要数据库么aso是什么意思
  • 大武口做网站的长沙官网seo技巧
  • 网站模板 整站源码下载sem优化师是做什么的
  • 聋哑工作设计做网站免费手机网站自助建站
  • 东莞网站的制作百度推广公司怎么代理到的
  • 网站为何改版线上推广有哪些渠道
  • 商丘做网站推广搜索引擎收录查询
  • 绵阳做网站的公司有哪些360信息流广告平台
  • 广州外贸营销型网站建设公司949公社招聘信息
  • 松原新闻头条seo排名推广
  • 邢台在百度上做个网站seo网络推广到底是做什么的
  • 海南建设网网站泰安网站seo
  • 网站开发html网络推广属于什么专业