parameters: (self, ys)
return_statement: return all_gradient_ops, all_input_to_grad_out
docstring: Gets the backward pass that computes the derivatives of given blobs.
  
          Inputs:
            ys: a list or a dictionary specifying what blobs we want to compute
                derivatives of. If the input is a list, we will automatically
                generate their gradients with all-one values; if the input is a
                dictionary, for any dictionary entries that are not None, we will
                take the corresponding blobs as their gradients; for all those
                that are None, we will auto-fill them with 1.
docstring_summary: Gets the backward pass that computes the derivatives of given blobs.
docstring_tokens: Gets the backward pass that computes the derivatives of given blobs .
function: def GetBackwardPass(self, ys):
          """Gets the backward pass that computes the derivatives of given blobs.
  
          Inputs:
            ys: a list or a dictionary specifying what blobs we want to compute
                derivatives of. If the input is a list, we will automatically
                generate their gradients with all-one values; if the input is a
                dictionary, for any dictionary entries that are not None, we will
                take the corresponding blobs as their gradients; for all those
                that are None, we will auto-fill them with 1.
          """
          if isinstance(ys, list):
              ys = dict((y, None) for y in ys)
          elif not isinstance(ys, dict):
              raise TypeError("ys should either be a list or a dict.")
  
          # Set the gradient frontier with the initialized external
          # gradients.
          for y in viewkeys(ys):
              self.gradient_frontier[y] = self.frontier[y]
              self.input_usages[str(y)][self.frontier[str(y)]].append(
                  len(self.ssa))
  
          all_input_to_grad, all_gradient_ops = self._GetInitGradients(ys)
  
          # (2) Now, after having the virtual play above, we now play the ops
          # backwards, creating the gradients along the path. Note that although
          # we are playing it backwards, we cannot refer to variables that are
          # at a version older than current_versions because it is already been
          # overwritten.
          for forward_op_idx in reversed(range(len(self.ssa))):
              input_to_grad, gradient_ops = self._GenerateGradientsForForwardOp(
                  forward_op_idx, all_input_to_grad)
              all_input_to_grad.update(input_to_grad)
              all_gradient_ops += gradient_ops
  
              # If there are multiple use blobs, do gradient accumulation.
              additional_sum_ops, grad_map = self.DoGradientAccumulation(
                  forward_op_idx)
              # This line is so that if in an accumulation some of the operators
              # have not produced gradients, they still do not overwrite the
              # general all_input_to_grad map.
              all_input_to_grad.update(grad_map)
              all_gradient_ops += additional_sum_ops
  
          # (3) Post-processing.
          # After we have done computation for each op, we now have the gradient
          # operators ready. For the output map, we will convert everything to
          # BlobReferences for easier handling in python.
          all_input_to_grad_out = {}
          for key, val in viewitems(all_input_to_grad):
              if val is not None:
                  if (isinstance(val, string_types) or
                          isinstance(val, binary_type)):
                      grad_out = BlobReference(val)
                  else:
                      grad_out = GradientSlice(BlobReference(val[0]),
                                               BlobReference(val[1]))
                  all_input_to_grad_out[BlobReference(key)] = grad_out
          return all_gradient_ops, all_input_to_grad_out
function_tokens: def GetBackwardPass ( self , ys ) : if isinstance ( ys , list ) : ys = dict ( ( y , None ) for y in ys ) elif not isinstance ( ys , dict ) : raise TypeError ( "ys should either be a list or a dict." ) # Set the gradient frontier with the initialized external # gradients. for y in viewkeys ( ys ) : self . gradient_frontier [ y ] = self . frontier [ y ] self . input_usages [ str ( y ) ] [ self . frontier [ str ( y ) ] ] . append ( len ( self . ssa ) ) all_input_to_grad , all_gradient_ops = self . _GetInitGradients ( ys ) # (2) Now, after having the virtual play above, we now play the ops # backwards, creating the gradients along the path. Note that although # we are playing it backwards, we cannot refer to variables that are # at a version older than current_versions because it is already been # overwritten. for forward_op_idx in reversed ( range ( len ( self . ssa ) ) ) : input_to_grad , gradient_ops = self . _GenerateGradientsForForwardOp ( forward_op_idx , all_input_to_grad ) all_input_to_grad . update ( input_to_grad ) all_gradient_ops += gradient_ops # If there are multiple use blobs, do gradient accumulation. additional_sum_ops , grad_map = self . DoGradientAccumulation ( forward_op_idx ) # This line is so that if in an accumulation some of the operators # have not produced gradients, they still do not overwrite the # general all_input_to_grad map. all_input_to_grad . update ( grad_map ) all_gradient_ops += additional_sum_ops # (3) Post-processing. # After we have done computation for each op, we now have the gradient # operators ready. For the output map, we will convert everything to # BlobReferences for easier handling in python. all_input_to_grad_out = { } for key , val in viewitems ( all_input_to_grad ) : if val is not None : if ( isinstance ( val , string_types ) or isinstance ( val , binary_type ) ) : grad_out = BlobReference ( val ) else : grad_out = GradientSlice ( BlobReference ( val [ 0 ] ) , BlobReference ( val [ 1 ] ) ) all_input_to_grad_out [ BlobReference ( key ) ] = grad_out return all_gradient_ops , all_input_to_grad_out