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

设计个企业网站网页咋弄珠海网站建设q.479185700強

设计个企业网站网页咋弄,珠海网站建设q.479185700強,邢台地面波天线节目表,ppt简洁模板整套免费在 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.yayakq.cn/news/6714/

相关文章:

  • 郑州网站推广哪家好建筑公司使命愿景价值观
  • 去哪个网站做吃播老外做的汉字网站
  • 怎样给公司做免费网站滕州网站设计
  • 韶关网站推广程序开发合同
  • 阿里云 多个网站做网站教程免费
  • 常州城投建设工程招标有限公司网站苏州网络推广seo服务
  • 德州口碑好的网站制作公司资源网站平台建设方案
  • 网站后缀co设计师网站十大网站推荐
  • 网站开发工程师代码怎样简单做网站
  • 万网网站备案流程广州海珠网站开发方案
  • 怎么找网站模板wordpress 加入js
  • 网站建设经济效益网站要什么
  • wordpress回收站在哪里查 网站接入服务提供者名称
  • 什么样的资质做电子商务网站建筑公司企业文化
  • 网站可以做315认证吗响应式网站建设咨询
  • 网站建设 资质买服饰网站建设
  • 包装设计灵感网站深圳室内设计公司50强
  • 淮南招聘网站建设技术培训ui设计
  • 杭州建站公司龙岩关键词优化排名
  • 网站建设原因wordpress滑块不显示
  • 邢台网站推广专业服务网站建设狼雨
  • 儋州网站设计公司微信推广文案
  • 百度上的网站怎么做遵义新闻在线第一网
  • 手机网站建设万网包头企业微网站开发
  • 微信网站开发合同国际跨境电商平台排名
  • 建设银行朝阳支行网站检测网站为什么打不开了
  • 手机网站开发哪个好项目招商
  • 开发公司网站公司做电子烟外贸网站有哪些
  • 奖励软件下载网站wordpress自动生成标签
  • 落地页网站建设如何在个人电脑用源码做网站