您现在的位置是:热点 >>正文
动态计算图和GPU支持操作
热点9258998人已围观
简介...
动态计算图
在深度学习中使用 PyTorch 的主要原因之一,是我们可以自动获得定义的函数的梯度/导数。
当我们操作我们的输入时,会自动创建一个计算图。该图显示了如何从输入到输出的动态计算过程。
为了熟悉计算图的概念,下面将动态为以下函数创建一个:
这里的 是我们的参数,我们想要优化(最大化或最小化)输出 . 为此,我们想要获得梯度.
在下面的代码中,我将使用[1,2,3]作输入。
# 只有浮动张量有梯度 x =&计算nbsp;torch.arange(1,4, dtype=torch.float32, requires_grad=True) print("X", x) 图和 # X tensor([1., 2., 3.], requires_grad=True)
现在让我来一步一步地构建计算图,了解每个操作是到底是如何添加GP到计算图中的。
a = x + 2 b = a ** 2 c = b +&nbU支sp;3 y = c.mean() print("Y", y) # Y tensor(19.6667, grad_fn=)&nbs持操p;
使用上面的语句,我们创建了一个类似于下图的计算图(通过tensorboard )查看:
我们计算 a 基于输入x 和常数2, b是 a平方等等操作。计算图通常以相反的方向可视化(箭头从结果指向输入)。
我们可以通过backward()动态在最后一个输出上调用函数来对计算图执行反向传播,这样可以,计算了每个具有属性的张量的梯度requires_grad=True:
y.backward()
最后打印x.grad就可以查看对应梯度。
GPU计算支持操作
在Pytorch中GPU 可以并行执行数以千计的小运算,因此非常适合在神经网络中执行大型矩阵运算。
「CPU 与 GPU的区别」
PyTorch 使用GPU,需要搭建NVIDIA 的CUDA和cuDNN。
下面代码,检查是否有可图和用的 GPU:
gpu_avail = torch.cuda.is_available() print("Is the GPU available? %GPs" % str(gpu_avail))
现在创建一个张量并将其推送到GPU设备:
device = torch.device("cuda") if&nU支bsp;torch.cuda.is_available() else torch.device("cpu") print("Device", device) x&nb持操sp;= x.to(device) print("X", x) # Device cuda # X tensor([1.,动态 1., 1.], device='cuda:0')
cuda 旁边的零表示这是计算机上的第0个 GPU 设备。因此,PyTorch 还支持多 GPU 系统,
下面将CPU 上的大型矩阵乘法的运行时间计算与 GPU 上的运算进行比较:
根据系统中的配置而定,GPU加速提高模型的训练速度。
Tags:
相关文章
面试 | 不可不知的十大 Hive 调优技巧优秀实践
热点Apache Hive是建立在Apache Hadoop之上的数据仓库软件项目,用于提供数据查询和分析。Hive是Hadoop在HDFS上的SQL接口,它提供了类似于SQL的接口来查询存储在与Hado...
【热点】
阅读更多云安全日报210930:红帽OpenShift云应用平台发现重要漏洞,需要尽快升级
热点Red Hat OpenShift Container Platform(红帽OpenShift容器平台)是红帽(Red Hat)公司的一套可帮助企业在物理、虚拟和公共云基础架构之间开发、部署和管理现...
【热点】
阅读更多Perplexity 大胆收购 Chrome!AI 浏览器大战一触即发!
热点在硅谷,关于谷歌和 AI 浏览器的热议已经开始升温。8 月中旬,AI 搜索公司 Perplexity 宣布计划以 345 亿美元收购谷歌的 Chrome 浏览器,这一报价几乎是 Perplexity...
【热点】
阅读更多
热门文章
最新文章
友情链接
- 标签: 康师傅
- https://www.londontheatredirect.com/search/谷歌快排【tg:seogoogle987】,n84
- https://www.terramania.nl/catalogsearch/result/index/?q=谷歌快排【tg:seogoogle987】,LYE
- https://www.remit.co.jp/en/?s=谷歌快排【tg:seogoogle987】,9NU
- https://www.sportbiketracktime.com/index.php?route=product/search&tag=谷歌快排【tg:seogoogle987】,LV4
- https://www.mynextmove.org/find/search?s=谷歌快排【tg:seogoogle987】,UcN
- https://www.temu.com/search_result.html?search_key=谷歌快排【tg:seogoogle987】Uvb
- https://www.teamlab.art/it/?submit=谷歌快排【tg:seogoogle987】,Mu0
- https://www.u-bourgogne.fr/?cat=117&s=谷歌快排【tg:seogoogle987】,w2h
- https://www.vfw.org/search-results?q=谷歌快排【tg:seogoogle987】,EyA
- https://www.sebson.de/en/search?query=谷歌快排【tg:seogoogle987】,028
- https://www.kaiyueleather.com/search/谷歌快排【tg:seogoogle987】,Zwu
- https://yokohama-oht.com/?action=CHECK&s=谷歌快排【tg:seogoogle987】,jkd
- https://www.nctsn.org/search?cat=191&query=谷歌快排【tg:seogoogle987】,2AY
- https://www.pmindia.gov.in/en/?s=谷歌快排【tg:seogoogle987】,egZ
- https://www.qwant.com/?q=谷歌快排【tg:seogoogle987】,nqG
- https://zhidao.baidu.com/index/?action=QUERY&word=谷歌快排【tg:seogoogle987】,B85
- https://www.luxurysociety.com/en/search?q=谷歌快排【tg:seogoogle987】,l5B
- https://www.samen-maier.at/search/谷歌快排【tg:seogoogle987】,3X2
- https://www.kawainter.com/catalogsearch/result/?q=谷歌快排【tg:seogoogle987】,eEU
- https://www.le-trend.com/en/search/=谷歌快排【tg:seogoogle987】,BQl
- https://www.pearlstonecenter.org/search/谷歌快排【tg:seogoogle987】,cx0
- https://www.nyif.com/catalogsearch/result/?q=谷歌快排【tg:seogoogle987】,MBv
- https://www.mexperience.com/?T=1686132112324&s=谷歌快排【tg:seogoogle987】,qYv
- https://www.smics.com/tc/site/search?token=谷歌快排【tg:seogoogle987】,vGx
- https://www.goodreads.com/quotes/tag/谷歌快排【tg:seogoogle987】a0O
- https://www.tarleton.edu/news/search/谷歌快排【tg:seogoogle987】,J8B
- https://www.youm7.com/Home/Search?allwords=谷歌快排【tg:seogoogle987】,j0s
- https://www.miamiopenmri.com/?action=CHECK&s=谷歌快排【tg:seogoogle987】,GTn
- https://www.tumblr.com/tagged/谷歌快排【tg:seogoogle987】,Woy
- https://www.shacknews.com/editorial-search?q=谷歌快排【tg:seogoogle987】,KAo
- https://www.tombow.com/search/谷歌快排【tg:seogoogle987】,6xL
- https://www.synonyms.com/antonyms/谷歌快排【tg:seogoogle987】,U7w
- https://www.paxnet.co.kr/search/jongmok?kwd=谷歌快排【tg:seogoogle987】ocA
- https://www.resilienz-akademie.com/?cat=71&s=谷歌快排【tg:seogoogle987】,y0O
- https://www.world-architects.com/en/search?term=谷歌快排【tg:seogoogle987】,Oa3
- https://www.takachi-enclosure.com/search?eqYB=gnI31Ou&text=谷歌快排【tg:seogoogle987】,oiI
- https://www.universal-music.co.jp/search/?q=谷歌快排【tg:seogoogle987】,tnf
- https://www.libros.unam.mx/catalogsearch/result/?cat=37&dir=asc&format=20&lit=20&manufacturer=3230&mode=list&order=year_edition&q=谷歌快排【tg:seogoogle987】,qaU
- https://www.partilerdunyasi.com/index.php?route=product/search&tag=谷歌快排【tg:seogoogle987】,Lli
- https://search.danawa.com/dsearch.php?query=谷歌快排【tg:seogoogle987】VB5
- https://www.mdbg.net/chinese/dictionary?page=worddict&wdrst=0&wdqb=谷歌快排【tg:seogoogle987】,Pns
- https://nicolazzi.it/en/?s=谷歌快排【tg:seogoogle987】,F3z
- https://www.lneg.pt/en/?s=谷歌快排【tg:seogoogle987】,uaX
- https://www.tahiti-infos.com/search/谷歌快排【tg:seogoogle987】,dBY
- https://www.remit.co.jp/ne/?s=谷歌快排【tg:seogoogle987】,4ah
- https://www.tombow.com/en/search/谷歌快排【tg:seogoogle987】,2N3
- https://www.nissin.com/jp/search/?cat=105&q=谷歌快排【tg:seogoogle987】,Mzx
- https://www.unclefossil.com/search/谷歌快排【tg:seogoogle987】gad_source=1&gclid=Cj0KCQjw_-GxBhC1ARIsADGgDjsNKplUXa2F6YGlHBK2sHDQ88cgsJBb05DyO99TV9jNq_cT0kGMqyQaAgHQEALw_wcB
- https://www.toy-people.com/?s=谷歌快排【tg:seogoogle987】,iKs
- https://www.kores.com/?s=谷歌快排【tg:seogoogle987】,EvC