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

制作梦核的网站小程序云开发收费

制作梦核的网站,小程序云开发收费,设置网关,网站推广运营公司文章目录 前言代码 前言 当我们需要对大规模的数据向量化以存到向量数据库中时,且服务器上有多个GPU可以支配,我们希望同时利用所有的GPU来并行这一过程,加速向量化。 代码 就几行代码,不废话了 from sentence_transformers i…

文章目录

  • 前言
  • 代码


前言

当我们需要对大规模的数据向量化以存到向量数据库中时,且服务器上有多个GPU可以支配,我们希望同时利用所有的GPU来并行这一过程,加速向量化。

代码

就几行代码,不废话了

from sentence_transformers import SentenceTransformer#Important, you need to shield your code with if __name__. Otherwise, CUDA runs into issues when spawning new processes.
if __name__ == '__main__':#Create a large list of 100k sentencessentences = ["This is sentence {}".format(i) for i in range(100000)]#Define the modelmodel = SentenceTransformer('all-MiniLM-L6-v2')#Start the multi-process pool on all available CUDA devicespool = model.start_multi_process_pool()#Compute the embeddings using the multi-process poolemb = model.encode_multi_process(sentences, pool)print("Embeddings computed. Shape:", emb.shape)#Optional: Stop the proccesses in the poolmodel.stop_multi_process_pool(pool)

注意:一定要加if __name__ == '__main__':这一句,不然报如下错:

RuntimeError: An attempt has been made to start a new process before thecurrent process has finished its bootstrapping phase.This probably means that you are not using fork to start yourchild processes and you have forgotten to use the proper idiomin the main module:if __name__ == '__main__':freeze_support()...The "freeze_support()" line can be omitted if the programis not going to be frozen to produce an executable.

其实官方已经给出代码啦,我只不过复制粘贴了一下,代码位置:computing_embeddings_multi_gpu.py

官方还给出了流式encode的例子,也是多GPU并行的,如下:

from sentence_transformers import SentenceTransformer, LoggingHandler
import logging
from datasets import load_dataset
from torch.utils.data import DataLoader
from tqdm import tqdmlogging.basicConfig(format='%(asctime)s - %(message)s',datefmt='%Y-%m-%d %H:%M:%S',level=logging.INFO,handlers=[LoggingHandler()])#Important, you need to shield your code with if __name__. Otherwise, CUDA runs into issues when spawning new processes.
if __name__ == '__main__':#Set paramsdata_stream_size = 16384  #Size of the data that is loaded into memory at oncechunk_size = 1024  #Size of the chunks that are sent to each processencode_batch_size = 128  #Batch size of the model#Load a large dataset in streaming mode. more info: https://huggingface.co/docs/datasets/streamdataset = load_dataset('yahoo_answers_topics', split='train', streaming=True)dataloader = DataLoader(dataset.with_format("torch"), batch_size=data_stream_size)#Define the modelmodel = SentenceTransformer('all-MiniLM-L6-v2')#Start the multi-process pool on all available CUDA devicespool = model.start_multi_process_pool()for i, batch in enumerate(tqdm(dataloader)):#Compute the embeddings using the multi-process poolsentences = batch['best_answer']batch_emb = model.encode_multi_process(sentences, pool, chunk_size=chunk_size, batch_size=encode_batch_size)print("Embeddings computed for 1 batch. Shape:", batch_emb.shape)#Optional: Stop the proccesses in the poolmodel.stop_multi_process_pool(pool)

官方案例:computing_embeddings_streaming.py

+-----------------------------------------------------------------------------+
| NVIDIA-SMI 515.105.01   Driver Version: 515.105.01   CUDA Version: 11.7     |
|-------------------------------+----------------------+----------------------+
| GPU  Name        Persistence-M| Bus-Id        Disp.A | Volatile Uncorr. ECC |
| Fan  Temp  Perf  Pwr:Usage/Cap|         Memory-Usage | GPU-Util  Compute M. |
|                               |                      |               MIG M. |
|===============================+======================+======================|
|   0  NVIDIA A800-SXM...  On   | 00000000:23:00.0 Off |                    0 |
| N/A   58C    P0   297W / 400W |  75340MiB / 81920MiB |    100%      Default |
|                               |                      |             Disabled |
+-------------------------------+----------------------+----------------------+
|   1  NVIDIA A800-SXM...  On   | 00000000:29:00.0 Off |                    0 |
| N/A   71C    P0   352W / 400W |  80672MiB / 81920MiB |    100%      Default |
|                               |                      |             Disabled |
+-------------------------------+----------------------+----------------------+
|   2  NVIDIA A800-SXM...  On   | 00000000:52:00.0 Off |                    0 |
| N/A   68C    P0   398W / 400W |  75756MiB / 81920MiB |    100%      Default |
|                               |                      |             Disabled |
+-------------------------------+----------------------+----------------------+
|   3  NVIDIA A800-SXM...  On   | 00000000:57:00.0 Off |                    0 |
| N/A   58C    P0   341W / 400W |  75994MiB / 81920MiB |    100%      Default |
|                               |                      |             Disabled |
+-------------------------------+----------------------+----------------------+
|   4  NVIDIA A800-SXM...  On   | 00000000:8D:00.0 Off |                    0 |
| N/A   56C    P0   319W / 400W |  70084MiB / 81920MiB |    100%      Default |
|                               |                      |             Disabled |
+-------------------------------+----------------------+----------------------+
|   5  NVIDIA A800-SXM...  On   | 00000000:92:00.0 Off |                    0 |
| N/A   70C    P0   354W / 400W |  76314MiB / 81920MiB |    100%      Default |
|                               |                      |             Disabled |
+-------------------------------+----------------------+----------------------+
|   6  NVIDIA A800-SXM...  On   | 00000000:BF:00.0 Off |                    0 |
| N/A   73C    P0   360W / 400W |  75876MiB / 81920MiB |    100%      Default |
|                               |                      |             Disabled |
+-------------------------------+----------------------+----------------------+
|   7  NVIDIA A800-SXM...  On   | 00000000:C5:00.0 Off |                    0 |
| N/A   57C    P0   364W / 400W |  80404MiB / 81920MiB |    100%      Default |
|                               |                      |             Disabled |
+-------------------------------+----------------------+----------------------+

嘎嘎快啊

http://www.yayakq.cn/news/655084/

相关文章:

  • 免费私人网站网站建设宣传ppt模板
  • 服务好的网站开发宁波网站建设公司优选亿企邦
  • 郑州网站设计有哪些如何入侵自己做的网站
  • 专业外贸网站建设公司排名wordpress安全更改
  • 建设银陕西省分行网站网络域名费用多少钱
  • 贵阳网站建设策划方案可口可乐网络营销推广方案
  • 本地门户网站系统上海建站哪家好
  • 做网站的毕设用什么软件音乐网站答辩
  • 展馆设计网站wordpress增强自带搜索
  • 怎么用手机制作手机网站如何修改网站后台时间
  • 北京城乡建设网站企业网站设计推荐
  • 全景校园网站开发浙江新华建设有限公司官方网站
  • 网站产品链接怎么做女人与狗做视频网站
  • 怎样做企业的网站首页外贸网站模板 免费
  • 平凉热度网站建设电脑在哪网站接做扇子单
  • 优购物官方网站 商城如何下载网页在线视频
  • 网站做百度推广吗网络直播网站建设
  • 网站建设咨询有客诚信网站建设咨询seo关键词优化排名
  • 延庆精神文明建设的门户网站网站漂浮图片
  • 企业网站备案管理系统集美网站建设
  • 如何做一个企业网站网站 绝对路径
  • 烟台建设集团 招聘信息网站做动态文字的网站
  • 个人做游戏下载网站侵权吗专业客户管理系统
  • 做企业网站需要准备什么河北建设集团官网
  • 中山祥云网站建设西安网站制作工商
  • 网站建设规划申请网站建设前分析
  • 中英文企业网站模板公司网站后台登陆
  • 网站设计报告成都微信微网站建设
  • 个体工商户做网站做软件与做网站建设有什么区别
  • 网站安全风险提示单百度找不到 网站