【问题标题】:UserWarning: Implicit dimension choice for log_softmax has been deprecated用户警告:log_softmax 的隐式维度选择已被弃用
【发布时间】:2018-08-06 23:42:30
【问题描述】:

我正在使用 Mac OS el capitán,我正在尝试使用 quick start tutorial for OpenNMT pytorch 版本。在训练步骤中,我收到以下警告消息:

OpenNMT-py/onmt/modules/GlobalAttention.py:177: UserWarning: Implicit dimension choice for softmax has been deprecated. Change the call to include dim=X as an argument. 

align_vectors = self.sm(align.view(batch*targetL, sourceL))
/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/torch/nn/modules/container.py:67: UserWarning: Implicit dimension choice for log_softmax has been deprecated. Change the call to include dim=X as an argument.
  input = module(input)

第 1 步:预处理数据(按预期工作)

python preprocess.py -train_src data/src-train.txt -train_tgt data/tgt-train.txt -valid_src data/src-val.txt -valid_tgt data/tgt-val.txt -save_data data/demo

第 2 步:训练模型(产生警告消息)

python train.py -data data/demo -save_model demo-model

有没有人遇到过这个警告或有任何解决方法?

【问题讨论】:

  • 也许this 适用于此。
  • 我认为警告不会停止执行,只是每个时期都需要很长时间:
  • 我最近得到了这个输出,就在警告之后:Epoch 1, 50/ 157; acc:4.21;人:167145.54; 37 src tok/s; 36 tgt tok/s; 2049 秒过去了 Epoch 1, 100/ 157;累积:5.52;人:8718.19; 37 src tok/s; 37 tgt tok/s; 3901 秒过去了

标签: python-3.x macos deep-learning pytorch opennmt


【解决方案1】:

从警告中可以清楚地看出,您必须明确提及维度,因为 softmax 的隐式维度选择已被弃用。

就我而言,我使用的是log_softmax,并且我已经更改了下面的代码行以包含维度。

torch.nn.functional.log_softmax(x) # This throws warning.

改为

torch.nn.functional.log_softmax(x, dim = 1) # This doesn't throw warning.

【讨论】:

    【解决方案2】:

    在计算交叉熵时,几乎总是需要最后一个维度,因此您的线可能如下所示:

    torch.nn.functional.log_softmax(x, -1)
    

    【讨论】:

      猜你喜欢
      • 2021-02-19
      • 1970-01-01
      • 1970-01-01
      • 2020-12-06
      • 2015-03-23
      • 2019-07-09
      相关资源
      最近更新 更多