class_docstr: Calculate loss in multiple-GPUs, which balance the memory usage for
  Semantic Segmentation.
  
  The targets are splitted across the specified devices by chunking in
  the batch dimension. Please use together with :class:`encoding.parallel.DataParallelModel`.
  
  Reference:
      Hang Zhang, Kristin Dana, Jianping Shi, Zhongyue Zhang, Xiaogang Wang, Ambrish Tyagi,
      Amit Agrawal. “Context Encoding for Semantic Segmentation.
      *The IEEE Conference on Computer Vision and Pattern Recognition (CVPR) 2018*
  
  Example::
  
      >>> net = encoding.nn.DataParallelModel(model, device_ids=[0, 1, 2])
      >>> criterion = encoding.nn.DataParallelCriterion(criterion, device_ids=[0, 1, 2])
      >>> y = net(x)
      >>> loss = criterion(y, target)
class_docstr_tok: ["Calculate","loss","in","multiple-GPUs",",","which","balance","the","memory","usage","for","Semantic","Segmentation",".","The","targets","are","splitted","across","the","specified","devices","by","chunking","in","the","batch","dimension",".","Please","use","together","with",":","class",":","`","encoding.parallel.DataParallelModel","`",".","Reference",":","Hang","Zhang",",","Kristin","Dana",",","Jianping","Shi",",","Zhongyue","Zhang",",","Xiaogang","Wang",",","Ambrish","Tyagi",",","Amit","Agrawal",".","\u201c","Context","Encoding","for","Semantic","Segmentation",".","*","The","IEEE","Conference","on","Computer","Vision","and","Pattern","Recognition","(","CVPR",")","2018","*","Example",":",":",">",">",">","net","=","encoding.nn.DataParallelModel","(","model",",","device_ids=","[","0",",","1",",","2","]",")",">",">",">","criterion","=","encoding.nn.DataParallelCriterion","(","criterion",",","device_ids=","[","0",",","1",",","2","]",")",">",">",">","y","=","net","(","x",")",">",">",">","loss","=","criterion","(","y",",","target",")"]
code: def forward(self, inputs, *targets, **kwargs):
      # input should be already scatterd
      # scattering the targets instead
      if not self.device_ids:
          return self.module(inputs, *targets, **kwargs)
      targets, kwargs = self.scatter(targets, kwargs, self.device_ids)
      if len(self.device_ids) == 1:
          return self.module(inputs, *targets[0], **kwargs[0])
      replicas = self.replicate(
          self.module, self.device_ids[: len(inputs)]
      )
      outputs = _criterion_parallel_apply(
          replicas, inputs, targets, kwargs
      )
      return Reduce.apply(*outputs) / len(outputs)
  
imports: from __future__ import absolute_import
  from __future__ import division
  from __future__ import print_function
  import functools
  import threading
  import torch
  import torch.cuda.comm
  from torch.autograd import Variable, Function
  from torch.nn.parallel.data_parallel import DataParallel
  from torch.nn.parallel.parallel_apply import get_a_var
  from torch.nn.parallel._functions import ReduceAddCoalesced, Broadcast
label_desc: Use image node_id 1 for calling the DataParallelCriterion obj's underlying member method code with example usage: obj.forward(inputs) and returns: unknown, self, self