parameters: (
              self, grad_op_input, g_output, fwd_op_idx, locally_generated_blobs)
docstring: Checks if the gradient operators can be correctly carried out.
docstring_summary: Checks if the gradient operators can be correctly carried out.
docstring_tokens: Checks if the gradient operators can be correctly carried out .
function: def CheckGradientOperatorInput(
              self, grad_op_input, g_output, fwd_op_idx, locally_generated_blobs):
          """Checks if the gradient operators can be correctly carried out."""
          forward_op, in_versions, out_versions = self.ssa[fwd_op_idx]
          original_index = GetIndexFromGradientList(g_output, grad_op_input)
  
          # Functions to generate debug help for version-mismatches
          def versionMismatchInfoOut(name):
              s = "DEBUG HELP:\n"
              s += "Maybe you use same output blob twice for different ops?\n"
              s += "== Version history of blob [{}]\n".format(name)
              for (op, vers) in self.out_version_history[name]:
                  s += "Version (out) {} <-- {}".format(vers, op)
                  s += "\n"
              return s
  
          def versionMismatchInfoIn(name):
              s = "DEBUG HELP:\n"
              s += "Maybe the blob was overwritten by another op?\n"
              s += "== Version history of blob [{}]\n".format(name)
              for (op, vers) in self.in_version_history[name]:
                  s += "version (in) {} <-- {}".format(vers, op)
                  s += "\n"
              return s
  
          # If it is a dense or sparse gradient name, it should match the
          # version of the corresponding output.
          if original_index is not None:
              original_name = forward_op.output[original_index]
              if (out_versions[original_name] !=
                      self.gradient_frontier[original_name]):
                  raise RuntimeError(
                      'Gradient name "%s" is expected to correspond '
                      'to version %d of "%s", but currently we have '
                      'version %d.\n\n' % (
                          grad_op_input, out_versions[original_name],
                          original_name,
                          self.gradient_frontier[original_name]) +
                      versionMismatchInfoOut(original_name))
          # If it is an output name, the current version should match the
          # version when the operator was run.
          elif grad_op_input in out_versions:
              if self.frontier[grad_op_input] != out_versions[grad_op_input]:
                  raise RuntimeError(
                      'Gradient operator needs output "%s" at version'
                      ' %d, but currently we have version %d.\n\n' % (
                          grad_op_input, out_versions[grad_op_input],
                          self.frontier[grad_op_input]
                      ) + versionMismatchInfoOut(grad_op_input)
                  )
          # If it is an input name, the current version should match the
          # version when the operator was run.
          elif grad_op_input in in_versions:
              if (self.frontier[grad_op_input] != in_versions[grad_op_input]):
                  raise RuntimeError(
                      'Gradient operator needs input "%s" at version '
                      '%d, but currently we have version %d.\n\n' % (
                          grad_op_input, in_versions[grad_op_input],
                          self.frontier[grad_op_input]
                      ) + versionMismatchInfoIn(grad_op_input)
                  )
          # If it is none of the above, it should be a blob that is
          # generated locally by one of the previous gradient operators.
          else:
              if grad_op_input not in locally_generated_blobs:
                  raise RuntimeError(
                      'Blob name "%s" not in the scope of operator: '
                      '%s\nand is not generated by any of the local '
                      'gradient operators.' % (grad_op_input, str(forward_op))
                  )
function_tokens: def CheckGradientOperatorInput ( self , grad_op_input , g_output , fwd_op_idx , locally_generated_blobs ) : forward_op , in_versions , out_versions = self . ssa [ fwd_op_idx ] original_index = GetIndexFromGradientList ( g_output , grad_op_input ) # Functions to generate debug help for version-mismatches def versionMismatchInfoOut ( name ) : s = "DEBUG HELP:\n" s += "Maybe you use same output blob twice for different ops?\n" s += "== Version history of blob [{}]\n" . format ( name ) for ( op , vers ) in self . out_version_history [ name ] : s += "Version (out) {} <-- {}" . format ( vers , op ) s += "\n" return s def versionMismatchInfoIn ( name ) : s = "DEBUG HELP:\n" s += "Maybe the blob was overwritten by another op?\n" s += "== Version history of blob [{}]\n" . format ( name ) for ( op , vers ) in self . in_version_history [ name ] : s += "version (in) {} <-- {}" . format ( vers , op ) s += "\n" return s # If it is a dense or sparse gradient name, it should match the # version of the corresponding output. if original_index is not None : original_name = forward_op . output [ original_index ] if ( out_versions [ original_name ] != self . gradient_frontier [ original_name ] ) : raise RuntimeError ( 'Gradient name "%s" is expected to correspond ' 'to version %d of "%s", but currently we have ' 'version %d.\n\n' % ( grad_op_input , out_versions [ original_name ] , original_name , self . gradient_frontier [ original_name ] ) + versionMismatchInfoOut ( original_name ) ) # If it is an output name, the current version should match the # version when the operator was run. elif grad_op_input in out_versions : if self . frontier [ grad_op_input ] != out_versions [ grad_op_input ] : raise RuntimeError ( 'Gradient operator needs output "%s" at version' ' %d, but currently we have version %d.\n\n' % ( grad_op_input , out_versions [ grad_op_input ] , self . frontier [ grad_op_input ] ) + versionMismatchInfoOut ( grad_op_input ) ) # If it is an input name, the current version should match the # version when the operator was run. elif grad_op_input in in_versions : if ( self . frontier [ grad_op_input ] != in_versions [ grad_op_input ] ) : raise RuntimeError ( 'Gradient operator needs input "%s" at version ' '%d, but currently we have version %d.\n\n' % ( grad_op_input , in_versions [ grad_op_input ] , self . frontier [ grad_op_input ] ) + versionMismatchInfoIn ( grad_op_input ) ) # If it is none of the above, it should be a blob that is # generated locally by one of the previous gradient operators. else : if grad_op_input not in locally_generated_blobs : raise RuntimeError ( 'Blob name "%s" not in the scope of operator: ' '%s\nand is not generated by any of the local ' 'gradient operators.' % ( grad_op_input , str ( forward_op ) ) )