Pytorch v0.4.1发布:添加频谱范数,自适应Softmax,优化CPU处理速度,添加异常检测(NaN等)以及支持Python 3.7和CUDA 9.2支持
NaN
等)CPU
操作速度比以前更快torch.stft
已将其签名更改为与librosa
一致#9497
stft(signal, frame_length, hop, fft_size=None, normalized=False, onesided=True, window=None, pad_end=0)
stft(input, n_fft, hop_length=None, win_length=None, window=None, center=True, pad_mode='reflect', normalized=False, onesided=True)
torch.stft
现在也在内部使用FFT
并且速度更快。torch.slice
删除有利于张量切片符号#7924torch.arange
现在做dtype
推论:任何浮点参数都被推断为默认值dtype
; 所有整数参数都被推断为int64
。#7016torch.nn.functional.embedding_bag
不推荐使用旧签名embedding_bag(weight, input, ...)
,而应使用embedding_bag(input, weight, ...)
(与torch.nn.functional.embedding
一致)torch.nn.functional.sigmoid
和torch.nn.functional.tanh
不支持取代torch.sigmoid
和torch.tanh
#8748
[1] x [0]
现在广播到[0]
(以前是[1]
)#92091、神经网络
nn.AdaptiveLogSoftmaxWithLoss
#5287>>> in_features = 1000
>>> n_classes = 200
>>> adaptive_softmax = nn.AdaptiveLogSoftmaxWithLoss(in_features, n_classes, cutoffs=[20, 100, 150])
>>> adaptive_softmax
AdaptiveLogSoftmaxWithLoss(
(head): Linear(in_features=1000, out_features=23, bias=False)
(tail): ModuleList(
(0): Sequential(
(0): Linear(in_features=1000, out_features=250, bias=False)
(1): Linear(in_features=250, out_features=80, bias=False)
)
(1): Sequential(
(0): Linear(in_features=1000, out_features=62, bias=False)
(1): Linear(in_features=62, out_features=50, bias=False)
)
(2): Sequential(
(0): Linear(in_features=1000, out_features=15, bias=False)
(1): Linear(in_features=15, out_features=50, bias=False)
)
)
)
>>> batch = 15
>>> input = torch.randn(batch, in_features)
>>> target = torch.randint(n_classes, (batch,), dtype=torch.long)
>>> # get the log probabilities of target given input, and mean negative log probability loss
>>> adaptive_softmax(input, target)
ASMoutput(output=tensor([-6.8270, -7.9465, -7.3479, -6.8511, -7.5613, -7.1154, -2.9478, -6.9885,
-7.7484, -7.9102, -7.1660, -8.2843, -7.7903, -8.4459, -7.2371],
grad_fn=), loss=tensor(7.2112, grad_fn=))
>>> # get the log probabilities of all targets given input as a (batch x n_classes) tensor
>>> adaptive_softmax.log_prob(input)
tensor([[-2.6533, -3.3957, -2.7069, ..., -6.4749, -5.8867, -6.0611],
[-3.4209, -3.2695, -2.9728, ..., -7.6664, -7.5946, -7.9606],
[-3.6789, -3.6317, -3.2098, ..., -7.3722, -6.9006, -7.4314],
...,
[-3.3150, -4.0957, -3.4335, ..., -7.9572, -8.4603, -8.2080],
[-3.8726, -3.7905, -4.3262, ..., -8.0031, -7.8754, -8.7971],
[-3.6082, -3.1969, -3.2719, ..., -6.9769, -6.3158, -7.0805]],
grad_fn=)
>>> # predit: get the class that maximize log probaility for each input
>>> adaptive_softmax.predict(input)
tensor([ 8, 6, 6, 16, 14, 16, 16, 9, 4, 7, 5, 7, 8, 14, 3])
nn.utils.spectral_norm
#6929>>> # Usage is similar to weight_norm
>>> convT = nn.ConvTranspose2d(3, 64, kernel_size=3, pad=1)
>>> # Can specify number of power iterations applied each time, or use default (1)
>>> convT = nn.utils.spectral_norm(convT, n_power_iterations=2)
>>>
>>> # apply to every conv and conv transpose module in a model
>>> def add_sn(m):
for name, c in m.named_children():
m.add_module(name, add_sn(c))
if isinstance(m, (nn.Conv2d, nn.ConvTranspose2d)):
return nn.utils.spectral_norm(m)
else:
return m
>>> my_model = add_sn(my_model)
nn.ModuleDict
和nn.ParameterDict
容器#8463nn.init.zeros_
和nn.init.ones_
#7488nn.EmbeddingBag
#5725MKLDNN
的深度卷积支持 #8782nn.FeatureAlphaDropout
(特征Alpha Dropout图层)#90732、Operators
>>> input = torch.randint(0, 8, (5,), dtype=torch.int64)
>>> weights = torch.linspace(0, 1, steps=5)
>>> input, weights
(tensor([4, 3, 6, 3, 4]),
tensor([ 0.0000, 0.2500, 0.5000, 0.7500, 1.0000])
>>> torch.bincount(input)
tensor([0, 0, 0, 2, 2, 0, 1])
>>> input.bincount(weights)
tensor([0.0000, 0.0000, 0.0000, 1.0000, 1.0000, 0.0000, 0.5000])
>>> tensor = torch.randn(3, device='cpu', dtype=torch.float32)
>>> torch.as_tensor(tensor) # doesn't copy
>>> torch.as_tensor(tensor, dtype=torch.float64) # copies due to incompatible dtype
>>> torch.as_tensor(tensor, device='cuda') # copies due to incompatible device
>>> array = np.array([3, 4.5])
>>> torch.as_tensor(array) # doesn't copy, sharing memory with the numpy array
>>> torch.as_tensor(array, device='cuda') # copies due to incompatible device
torch.nn.functional.kl_div
中支持目标张量后向 #7839torch.diagonal
,torch.diagflat
采取任意对角线使用numpy
语义#6718tensor.any
和tensor.all
在ByteTensor
现在可以接受dim
和keepdim
参数#46273、Distributions
4、Misc
Autograd
自动异常检测NaN
和向后发生的错误。为此提供了两个函数detect_anomaly
和set_detect_anomaly
。#76775、性能
6、改进
a、打印张量
requires_grad
和grad_fn
信息#8211b、神经网络
NaN
现在通过许多激活函数传播#8033non_blocking
选项到nn.Module.to
#7312c、Operators
torch.einsum
#7173to
方法到PackedSequence
#7319__floordiv__
和__rdiv__
#7245torch.clamp
现在在最小和最大处有次级梯度1 #7049torch.norm
和torch.renorm
中正确支持无限范围 #6969out=
关键字arugment
在torch.dot
和torch.matmul
#6961d、分布
gradlazy_property
#7708e、稀疏张量
log1p
#8969f、数据并行
nn.parallel.parallel_apply
接受list/tuple
张量 #8047g、Misc
torch.Size
现在可以接受PyTorch
标量 #5676torch.utils.data.dataset.random_split
到torch.utils.data.random_split
,并torch.utils.data.dataset.Subset
转至torch.utils.data.Subset
#7816torch.device
添加序列化#7713torch.(int/float/...)*
的copy.deepcopy
对象#7699torch.load
现在可以采取torch.device
map位置#7339
原创文章,转载请注明 :Pytorch v0.4.1发布:添加频谱范数,自适应Softmax,优化CPU处理速度,添加异常检测(NaN等)以及支持Python 3.7和CUDA 9.2支持 - pytorch中文网
原文出处: https://ptorch.com/news/197.html