【问题标题】:pysyft torrch.jit. script RuntimeError: undefined value _Reductionpysyft torch.jit.脚本 RuntimeError:未定义的值 _Reduction
【发布时间】:2020-04-02 00:31:20
【问题描述】:

我试图从其高级示例中重现 Pysyft Asynchronous-federated-learning-on-MNIST。其中@torch.jit.script 在损失函数之前使用。我收到了这个错误,不知道这是怎么回事

RuntimeError: undefined value _Reduction: at /home/ab/.virtualenvs/aic/lib/python3.6/site-packages/syft/generic/frameworks/hook/hook.py:1829:20

reduction = _Reduction.legacy_get_string(size_average, reduce)


其实是这几行造成的

@torch.jit.script
def loss_fn(pred, target):
    return F.nll_loss(input=pred, target=target)

train_config = sy.TrainConfig(
        model=traced_model,
        loss_fn=loss_fn,
        batch_size=batch_size,
        shuffle=True,
        max_nr_batches=max_nr_batches,
        epochs=1,
        optimizer="SGD",
        optimizer_args={"lr": lr},
    )

【问题讨论】:

    标签: python pytorch jit pysyft


    【解决方案1】:

    编写答案以便对其他人有所帮助。事实证明,@torch.jit.script 需要位于文件的顶部(导入后),而我在两个函数定义之后才拥有它。

    将它移到顶部工作

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2011-08-11
      • 1970-01-01
      • 1970-01-01
      • 2019-06-12
      • 1970-01-01
      • 2014-10-22
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多