I don’t know how to use variable[key.detach()], will look at it later.
If necessary, I can paste my code here.
I google searched the following phrase
assert not ctx.needs_input_grad[1], “MaskedFill can’t differentiate the mask”
which return to page

  
      github.com
  
  
    pytorch/pytorch/blob/master/torch/autograd/_functions/tensor.py 10
from functools import reduce
import torch

from ..function import Function
from ..variable import Variable


class Type(Function):

    @staticmethod
    def forward(ctx, i, dest_type):
        ctx.input_type = type(i)
        ctx.input_device = -1 if not i.is_cuda else i.get_device()
        return i.type(dest_type)

    @staticmethod
    def backward(ctx, grad_output):
        if ctx.input_device == -1:
            return grad_output.type(ctx.input_type), None
        else:


  This file has been truncated. show original

  
  
    
    
  
  


Don’t know if this code changes.
Usually I installed pytorch from source on my machine for both python 2.7 and python 3.5.
My last working version of pytorch for python 3.5 actually was installed about earlier of this Sept.,
which was uninstalled and upgraded to the latest one. My current working version of pytorch for
python 2.7 was installed in this Oct. 6, and I have to keep it NOW.