Here is an example:

  
      github.com
  
  
    Zhaoyi-Yan/Shift-Net_pytorch/blob/master/models/shift_net/InnerShiftTriple.py#L34 3

    cur_device = torch.cuda.current_device()
    self.cur_mask = self.mask_all[cur_device*cur_bsize:(cur_device+1)*cur_bsize, :, :, :]


# If mask changes, then need to set cal_fix_flag true each iteration.
def forward(self, input):
    self.bz, self.c, self.h, self.w = input.size()
    self._split_mask(self.bz)
    self.flag = util.cal_flag_given_mask_thred(self.cur_mask, self.shift_sz, self.stride, self.mask_thred)
    final_out = InnerShiftTripleFunction.apply(input, self.shift_sz, self.stride, self.triple_weight, self.flag, self.show_flow)
    if self.show_flow:
        self.flow_srcs = InnerShiftTripleFunction.get_flow_src()
    return final_out


def get_flow(self):
    return self.flow_srcs


def set_flow_true(self):
    self.show_flow = True


def set_flow_false(self):
    self.show_flow = False