22using System . Linq ;
33using Tensorflow . Gradients ;
44using static Tensorflow . Binding ;
5- using static Tensorflow . tensorflow ;
65
76namespace Tensorflow . Eager
87{
@@ -14,18 +13,7 @@ public bool RecordGradient(string op_name,
1413 Tensor [ ] results ,
1514 Func < BackwardFunction > getBackwardFunction = null )
1615 {
17- var input_ids = MakeTensorIDList ( inputs ) ;
18- var input_dtypes = MakeTensorDtypeList ( inputs ) ;
19-
20- bool should_record = false ;
21- foreach ( var tape in tf . GetTapeSet ( ) )
22- {
23- if ( tape . ShouldRecord ( input_ids , input_dtypes ) )
24- {
25- should_record = true ;
26- break ;
27- }
28- }
16+ bool should_record = ShouldRecord ( inputs ) ;
2917
3018 if ( ! should_record )
3119 {
@@ -43,35 +31,27 @@ public bool RecordGradient(string op_name,
4331 tf . Logger . Debug ( $ "RecordGradient: op_name={ op_name } ") ;
4432
4533 Tensor [ ] op_outputs ;
46- #pragma warning disable CS0219 // Variable is assigned but its value is never used
47- bool op_outputs_tuple_created = false ;
48- #pragma warning restore CS0219 // Variable is assigned but its value is never used
4934 var unused_output_indices = gradient_exclustions . OpGradientUnusedOutputIndices ( op_name ) ;
5035 if ( unused_output_indices != null )
5136 {
5237 if ( unused_output_indices . Length == 0 )
5338 op_outputs = new Tensor [ 0 ] ;
5439 else
5540 {
56- op_outputs_tuple_created = true ;
5741 // op_outputs = CopySequenceSettingIndicesToNull(results, *unused_output_indices);
5842 }
5943 }
6044 else
6145 op_outputs = results ;
6246
6347 Tensor [ ] op_inputs ;
64- #pragma warning disable CS0219 // Variable is assigned but its value is never used
65- bool op_inputs_tuple_created = false ;
66- #pragma warning restore CS0219 // Variable is assigned but its value is never used
6748 var unused_input_indices = gradient_exclustions . OpGradientUnusedInputIndices ( op_name ) ;
6849 if ( unused_input_indices != null )
6950 {
7051 if ( unused_input_indices . Length == 0 )
7152 op_inputs = new Tensor [ 0 ] ;
7253 else
7354 {
74- op_inputs_tuple_created = true ;
7555 // op_inputs = CopySequenceSettingIndicesToNull(inputs, *unused_input_indices);
7656 }
7757 }
@@ -125,11 +105,6 @@ bool CouldBackprop()
125105 return HasGradientTape ( ) ;
126106 }
127107
128- long [ ] MakeTensorIDList ( Tensor [ ] tensors )
129- {
130- return tensors . Select ( x => x . Id ) . ToArray ( ) ;
131- }
132-
133108 TF_DataType [ ] MakeTensorDtypeList ( Tensor [ ] tensors )
134109 {
135110 return tensors . Select ( x => x . dtype ) . ToArray ( ) ;
0 commit comments