专栏名称: 新智元
智能+中国主平台,致力于推动中国从互联网+迈向智能+新纪元。重点关注人工智能、机器人等前沿领域发展,关注人机融合、人工智能和机器人革命对人类社会与文明进化的影响,领航中国新智能时代。
目录
相关文章推荐
机器之心  ·  淘宝卖DeepSeek安装包一月赚数十万?? ... ·  15 小时前  
量子位  ·  推理成本比MoE直降83%!字节最新大模型架 ... ·  18 小时前  
爱可可-爱生活  ·  本文提出的 ... ·  20 小时前  
爱可可-爱生活  ·  【[76星]Direct3D:将2D图像直接 ... ·  昨天  
51好读  ›  专栏  ›  新智元

PyTorch 最新版发布:API 变动,增加新特征,多项运算和加载速度提升

新智元  · 公众号  · AI  · 2017-05-04 14:44

正文

新智元编译

来源: github.com

编译:刘小芹

新智元启动 2017 最新一轮大招聘: COO、总编、主笔、运营总监、视觉总监等8大职位全面开放

新智元为COO和执行总编提供最高超百万的年薪激励;为骨干员工提供最完整的培训体系、 高于业界平均水平的工资和奖金。 加盟新智元,与人工智能业界领袖携手改变世界。

简历投递:j [email protected] HR 微信: 13552313024


【新智元导读】 PyTorch 发布了最新版,API 有一些变动,增加了一系列新的特征,多项运算或加载速度提升,而且修改了大量bug。官方文档也提供了一些示例。



API 改变


  • torch.range 已被弃用,取代的是 torch.arange ,这与 numpy 和 python 范围一致。

  • 在稀疏张量上, contiguous 被重命名为 coalesce coalesce 已经不合适。(注意 Sparse API 仍然是实验性而且在演变中,所以我们不提供向后兼容性)。


新的特征


新的层和函数


  • torch.topk 现在支持所有 CUDA 类型,不仅是 torch.cuda.FloatTensor

  • 增加了一个 三路排序损失:nn.TripletMarginLoss

  • 增加了每个实例的归一化层:nn.InstanceNorm1d, nn.InstanceNorm2d, nn.InstanceNorm3d

    每个通道都被作为一个实例进行归一化处理,并进行均值消减和标准差。这在处理需要类似 BatchNorm 效果的较大的图像和较小的 mini-batches 时很有用。

  • 增加了 nn.ZeroPad2d nn.ConstantPad2d

  • 增加了 nn.Bilinear ,计算 Y = X1 * W * X2 + b


支持所有函数的负维


使用维度参数的每个函数也允许采取负维(negative dimensions)。 负维将索引上个维度的张量。


例如:



这里,由于 x 具有3维,并且 dim = -1 ,因此最后一个维度,即 dim = 3 被采用来得到平均值。


具有维度参数的函数有:



CUDA 支持稀疏张量,更快的 CPU sparse


新版本中 torch.sparse API 的一部分也支持 torch.cuda.sparse。* Tensor


CUDA 支持的函数有:



利用这些稀疏函数, nn.Embedding 现在也在 CUDA 上支持 sparse(使用 sparse = True 标志)。


一种新的混合矩阵乘法 hspmm ,将稀疏矩阵与密集矩阵相乘,并以混合张量的形式(即1个稀疏维度,1个密集维度)返回1个矩阵。


几个CPU稀疏函数具有更高效的实现。


这里有一个嵌入式分类器训练脚本,作者是@martinraison,我们可以对比 CUDA sparse 和 CUDA dense 的表现。( http ://t.cn/RaZcltA



named_parameters 过滤特定的参数类型


假设你想为模型除 biases 外的所有参数增加权重衰减(weight decay),怎样只获得模型的 biases?


这里我们引入了 nn.Module.named_parameters,它结合 named_children named_modules 来帮助过滤模型的特定属性。


例子:过滤一个模型的 biases, weight_decay 为0




性能提升



  • 在适当的情况下,通过使用一些 thrust primitives, cumsum cumprod 在GPU上显着加快了。

  • 通过一个 fused kernel, LSTMCell GRUCELL 在GPU上显着加快了。

  • CuDNN 的默认算法更改为 PRECOMP_GEMM ,这是一个更快的算法,需要的工作空间很小。这个之前是 IMPLICIT_GEMM ,占用的工作空间为0,但是慢很多。

  • 通过将 batches 直接整到共享内存中,数据加载速度提升了 5%~10%。

  • 通过分治法(sgesdd)在 GPU 上计算 SVD,加速了2~5倍。

  • 常用的函数 expand 移到 C,在较小的模型中具有更好的性能。


Bug 修复


  • Added contiguous checks on weight and bias for a large range of THNN functions

  • make the range of random_ correct when both lower and upper bound are specified

  • parallel_apply now can take arguments that are unhashable

  • Reshape grad correctly in the Dot function (inputs don't have to be 1D vectors...)

  • Added Variable.type_as

  • Unify argument names of norm and renorm to have p=norm_type , dim=dim

  • btrisolve works on CPU doubles

  • ipython autocomplete for torch.nn.Module fixed via implementing __dir__

  • device_ids can now be None again in F.data_parallel and will use all available GPUs

  • workaround cudnn bugs in BatchNorm (

  • Padding bugfix in Conv1d CPU

  • remainder and cremainder are fixed for integer types

  • fix memory leak in btrisolve and getri

  • If nn.Module's source cant be retrieved because of any exception,

  • handle serialization to be non-fatal

  • collate_fn now retains the type of the numpy array

  • is_tensor and is_storage are now fixed for old-style Python classes

  • torch.cat now supports keyword arguments

  • CUDA collectives supported coalescing, but the inputs were all assumed

  • to be of the same Tensor type. This is fixed.

  • Fix a deadlock bug in autograd because of an underlying glibc bug in specific

  • linux distros (ArchLinux in particular)

  • abs is now fixed for char and short cuda types

  • fix torch.diag autograd when giving a dimension argument

  • fix grouped convolution on CPU when bias=False

  • expose dilated convolutions for ConvTranspose*d

  • Fix a bug in HingeEmbeddingLoss where margin can now be specified via kwargs



下载源码: https://github.com/pytorch/pytorch/releases





新智元招聘


新智元日前宣布,获6家顶级机构总额达数千万元的PreA轮融资,蓝驰创投领投,红杉资本中国基金、高瓴智成、蓝湖资本 、蓝象资本跟投。本轮融资将用于新智元团队规模扩充并增加新产品服务线,目标打造 To B 的人工智能全产业链服务平台。


职位:客户经理


职位年薪:12 - 25万 (工资+奖金)







请到「今天看啥」查看全文