MCPcopy Index your code
hub / github.com/pytorch/pytorch / _MakeSparseSumOps

Method _MakeSparseSumOps

caffe2/python/core.py:834–884  ·  view source on GitHub ↗
(self, generators, out_base_name)

Source from the content-addressed store, hash-verified

832 return sum_ops, out_base_name
833
834 def _MakeSparseSumOps(self, generators, out_base_name):
835 indices_concat_input = []
836 values_concat_input = []
837 cnt_i = 0
838 cnt_v = 0
839
840 for generator in generators:
841 assert(type(generator) is SparseGradGenMeta)
842 op_i, idx_i, op_v, idx_v, g, _ = generator
843 if op_i:
844 out, cnt_i = self._DisambiguateGradOpOutput(op_i, idx_i, cnt_i)
845 indices_concat_input.append(out)
846 else:
847 self._CheckSumOpsConflict(out_base_name, g.indices)
848 indices_concat_input.append(g.indices)
849 if op_v:
850 out, cnt_v = self._DisambiguateGradOpOutput(op_v, idx_v, cnt_v)
851 values_concat_input.append(out)
852 else:
853 self._CheckSumOpsConflict(out_base_name, g.values)
854 values_concat_input.append(g.values)
855
856 indices_concat_output = out_base_name + '_indices_concat'
857 indices_concat_split = out_base_name + '_indices_concat_split'
858 values_concat_output = out_base_name + '_values_concat'
859 values_concat_split = out_base_name + '_values_concat_split'
860 # Sum the given sparse representations by simply concatenating the
861 # indices (resp. values) tensors together. We don't do any deduplication
862 # of indices at this point. This will be done as needed before the
863 # optimizer is called
864 sum_ops = [
865 CreateOperator(
866 "Concat",
867 [BlobReference(x) for x in indices_concat_input],
868 [BlobReference(x) for x in
869 [indices_concat_output, indices_concat_split]],
870 axis=0
871 ),
872 CreateOperator(
873 "Concat",
874 [BlobReference(x) for x in values_concat_input],
875 [BlobReference(x) for x in
876 [values_concat_output, values_concat_split]],
877 axis=0
878 ),
879 ]
880 sum_op_output = GradientSlice(
881 indices=indices_concat_output,
882 values=values_concat_output,
883 )
884 return sum_ops, sum_op_output
885
886 def _MakeSumOps(self, input_name, input_version):
887 generators = self.gradient_generators[input_name][input_version]

Callers 1

_MakeSumOpsMethod · 0.95

Calls 5

_CheckSumOpsConflictMethod · 0.95
CreateOperatorFunction · 0.85
BlobReferenceClass · 0.85
appendMethod · 0.45

Tested by

no test coverage detected