PyTorch 0.4.1 リリースノート (翻訳)
翻訳 : (株)クラスキャット セールスインフォメーション
日時 : 07/27/2018
* 本ページは github PyTorch の releases の PyTorch 0.4.1 リリースノートに相当する、
“Spectral Norm, Adaptive Softmax, faster CPU ops, anomaly detection (NaNs, etc.), Lots of bug fixes, Python 3.7 and CUDA 9.2 support” を翻訳したものです:
互換性に影響する変更
- torch.stft は librosa と一致するためにそのシグネチャを変更しました。 #9497
- Before: stft(signal, frame_length, hop, fft_size=None, normalized=False, onesided=True, window=None, pad_end=0)
- After: 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 は tensor スライシング記法を支持して除去されました。 #7924
- torch.arange は今では dtype 推定を行ないます: 任意の浮動小数点引数はデフォルト dtype として推論されます; 総ての整数引数は int64 と推定されます。 #7016
- torch.nn.functional.embedding_bag の古いシグネチャ embedding_bag(weight, input, …) は今では deprecated で、代わりに embedding_bag(input, weight, …) (torch.nn.functional.embedding と一致) が使用されるべきです。
- torch.nn.functional.sigmoid と torch.nn.functional.tanh は torch.sigmoid と torch.tanh のために deprecated です。#8748
- Broadcast の挙動は (非常に稀な) エッジケースで変更されました: [1] x [0] は今では [0] にブロードキャストされます (以前は [1] でした)。 #9209
新しい特徴
ニューラルネットワーク
- Adaptive Softmax 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]) - スペクトル正規化 (= spectral normalization) 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 コンテナ #8463
- nn.init.zeros_ と nn.init.ones_ を追加します。 #7488
- 事前訓練された埋め込みに sparse gradient オプションを追加します。 #7492
- nn.EmbeddingBag に max pooling サポートを追加します。 #5725
- MKLDNN に対する depthwise convolution サポート。 #8782
- nn.FeatureAlphaDropout (featurewise Alpha Dropout 層) を追加します。 #9073
演算子
- torch.bincount (integral tensor の各値の count frequency) #6688
>>> 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])
- torch.as_tensor (torch.tensor と同様ですが必要な場合以外は決してコピーしません) #7109
>>> 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
- CUDA tensor のための torch.randperm #7606
- CUDA tensor のための nn.HardShrink #8117
- torch.flip (指定された dims に沿って tensor をフリップします) #7873
- torch.flatten (dims の連続的な範囲を flatten します) #8578
- torch.pinverse (svd ベースの pseudo-inverse を計算します) #9052
- torch.meshgrid #8581
- CUDA tensor のための torch.unique #8899
- torch.erfc (補足的なエラー関数) https://github.com/pytorch/pytorch/pull/9366/files
- torch.isinf と torch.isfinite #9169 #9487
- torch.reshape_as #9452
- torch.nn.functional.kl_div の target tensor のための後方サポート #7839
- torch.logsumexp #7254
- torch.gesv にバッチ化された linear solver を追加します #6100
- torch.sum は今では多次元に渡る総計をサポートします。
https://github.com/pytorch/pytorch/pull/6152/files - numpy セマンティクスを持つ任意の対角を取るための torch.diagonal torch.diagflat #6718
- ByteTensor 上の tensor.any と tensor.all は今では dim と keepdim 引数を取ります。 #4627
分布
- 半コーシー (Half Cauchy) と半正規 (Half Normal) #8411
- CUDA tensor のためのガンマ (分布) サンプリング #6855
- 二項分布のベクトル化されたカウントを可能にします #6720
Misc
- NaN と backward で発生するエラーのための Autograd 自動異常検知 #7677
- reversed(torch.Tensor) をサポートします #9216
- Support hash(torch.device) をサポートします #9246
- torch.load の gzip をサポートします #6490
パフォーマンス
- CPU 上のベルヌーイ数生成を高速化します #7171
- cuFFT plan キャッシングを有効にします (特定のケースでは 80% スピードアップ) #8344
- bernoulli_ における不要なコピーを修正 #8682
- broadcast における不要なコピーを修正 #8222
- 多次元 sum のスピードアップ (特定のケースでは 2x~6x スピードアップ) #8992
- CPU sigmoid のベクトル化 (殆どのケースで >3x スピードアップ) #8612
- CPU nn.LeakyReLU と nn.PReLU を最適化します (2x スピードアップ) #9206
- softmax and logsoftmax をベクトル化 (シングルコア上で 4.5x そして 10 スレッド上で 1.8x スピードアップ) #7375
- nn.init.sparse のスピードアップ (10-20x スピードアップ) #6899
改良
Tensor プリンティング
- Tensor printing は今では requires_grad と grad_fn 情報を含みます #8211
- tensor print における数字フォーマッティングの改良 #7632
- 幾つかの tensor をプリントするときスケールを修正 #7189
- 巨大な tensor のプリントをスピードアップ #6876
ニューラルネットワーク
- NaN は今では多くの活性化関数を通して伝播されます #8033
- nn.Module.to に non_blocking オプションを追加します #7312
- Loss モジュールは今では target に勾配を要求することを可能にします #8460
- nn.BCEWithLogitsLoss に pos_weight 引数を追加します #6856
- 異なるデバイス上のパラメータのために grad_clip をサポートします #9302
- pad_sequence への入力シークエンスはソートされていなければならないという要件を除去します #7928
- max_unpool1d, max_unpool2d, max_unpool3d のための stride 引数は今では kernel_size をデフォルトとします #7388
- grad mode コンテキスト・マネージャ (e.g., torch.no_grad, torch.enable_grad) を decorator として呼び出すことを可能にします #7737
- torch.optim.lr_scheduler._LRSchedulers __getstate__ は optimizer 情報を含みます #7757
- clip_grad_* 関数で入力として Tensor を取るためのサポートを追加します #7769
- NaN 入力に対して max_pool/adaptive_max_pool で NaN を返します #7670
- nn.EmbeddingBag は今では空のバッグを処理できます #7389
- torch.optim.lr_scheduler.ReduceLROnPlateau は今ではシリアライズ可能です #7201
- 浮動小数点 dtype の tensor だけに勾配を要求することを可能にします #7034 と #7185
- BatchNorm 実行状態と累積する移動平均のリセットを可能にします #5766
- p の power への総ての入力要素の総計がゼロである場合 LP-Pooling の勾配をゼロに設定します #6766
演算子
- torch.einsum に ellipsis (‘…’) と diagonal (e.g. ‘ii→i’) を追加します #7173
- PackedSequence のためのメソッドを追加 #7319
- integral tensor のための __floordiv__ と __rdiv__ のサポートを追加します #7245
- torch.clamp は今では min と max で劣勾配 (= subgradient) 1 を持ちます #7049
- torch.arange は今では Numpy スタイルの型推論を使用します : #7016
- torch.norm と torch.renorm の infinity norm を正しくサポートします #6969
- torch.dot と torch.matmul において out= キーワード引数を通して出力 tensor を渡すことを可能にします #6961
分布
- lazy_property を計算するとき grad を常に有効にします。 #7708
スパース Tensor
データ並列
- nn.DataParallel でスカラーを返すモジュールを可能にします #7973
- nn.parallel.parallel_apply が tensor のリスト/タプルを取ることを可能にします #8047
Misc
- torch.Size は今では PyTorch スカラーを受け取れます #5676
- torch.utils.data.dataset.random_split を torch.utils.data.random_split に、そして torch.utils.data.dataset.Subset を torch.utils.data.Subset に移動します #7816
- torch.device のためのシリアライゼーションを追加します #7713
- torch.(int/float/…)* dtype オブジェクトの copy.deepcopy を可能にします #7699
- torch.load は今では torch.device を map location として取ります #7339
バグ修正 & ドキュメント
※ 訳注: 原文 を参照してください。
以上