| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent 2ef9a51 commit aee6cd6
19 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -11,7 +11,7 @@ public bool RecordGradient(string op_name, | |||
| 11 | 11 | Tensor[] inputs, | |
| 12 | 12 | object[] attrs, | |
| 13 | 13 | Tensor[] results, | |
| 14 | - Func<BackwardFunction> getBackwardFunction = null) | ||
| 14 | + BackwardFunction backwardFunction = null) | ||
| 15 | 15 | { | |
| 16 | 16 | bool should_record = ShouldRecord(inputs); | |
| 17 | 17 | ||
@@ -28,9 +28,9 @@ public bool RecordGradient(string op_name, | |||
| 28 | 28 | } | |
| 29 | 29 | ||
| 30 | 30 | if (!should_record) return should_record; | |
| 31 | - tf.Logger.Debug($"RecordGradient: op_name={op_name}"); | ||
| 31 | + // tf.Logger.Debug($"RecordGradient: op_name={op_name}"); | ||
| 32 | 32 | ||
| 33 | - Tensor[] op_outputs; | ||
| 33 | + /*Tensor[] op_outputs = null; | ||
| 34 | 34 | var unused_output_indices = gradient_exclustions.OpGradientUnusedOutputIndices(op_name); | |
| 35 | 35 | if (unused_output_indices != null) | |
| 36 | 36 | { | |
@@ -44,7 +44,7 @@ public bool RecordGradient(string op_name, | |||
| 44 | 44 | else | |
| 45 | 45 | op_outputs = results; | |
| 46 | 46 | ||
| 47 | - Tensor[] op_inputs; | ||
| 47 | + Tensor[] op_inputs = null; | ||
| 48 | 48 | var unused_input_indices = gradient_exclustions.OpGradientUnusedInputIndices(op_name); | |
| 49 | 49 | if (unused_input_indices != null) | |
| 50 | 50 | { | |
@@ -56,22 +56,14 @@ public bool RecordGradient(string op_name, | |||
| 56 | 56 | } | |
| 57 | 57 | } | |
| 58 | 58 | else | |
| 59 | - op_inputs = inputs; | ||
| 59 | + op_inputs = inputs;*/ | ||
| 60 | 60 | ||
| 61 | - TapeSetRecordOperation(op_name, inputs, results, | ||
| 62 | - getBackwardFunction ?? GetBackwradFunction(op_name, inputs, attrs, results)); | ||
| 61 | + backwardFunction = backwardFunction ?? GetGradientFunction(op_name, inputs, attrs, results); | ||
| 62 | + TapeSetRecordOperation(op_name, inputs, results, backwardFunction); | ||
| 63 | 63 | ||
| 64 | 64 | return true; | |
| 65 | 65 | } | |
| 66 | 66 | ||
| 67 | - Func<BackwardFunction> GetBackwradFunction(string op_name, | ||
| 68 | - Tensor[] op_inputs, | ||
| 69 | - object[] attrs, | ||
| 70 | - Tensor[] op_outputs) | ||
| 71 | - { | ||
| 72 | - return () => GetGradientFunction(op_name, op_inputs, attrs, op_outputs); | ||
| 73 | - } | ||
| 74 | - | ||
| 75 | 67 | BackwardFunction GetGradientFunction(string op_name, | |
| 76 | 68 | Tensor[] op_inputs, | |
| 77 | 69 | object[] attrs, | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -1,7 +1,6 @@ | |||
| 1 | 1 | using System; | |
| 2 | 2 | using Tensorflow.Gradients; | |
| 3 | 3 | using static Tensorflow.Binding; | |
| 4 | - using static Tensorflow.tensorflow; | ||
| 5 | 4 | ||
| 6 | 5 | namespace Tensorflow.Eager | |
| 7 | 6 | { | |
@@ -10,7 +9,7 @@ public partial class EagerRunner | |||
| 10 | 9 | void TapeSetRecordBackprop(string op_type, | |
| 11 | 10 | Tensor[] input_tensors, | |
| 12 | 11 | TapeTensor[] output_tensors, | |
| 13 | - Func<BackwardFunction> backward_function_getter) | ||
| 12 | + BackwardFunction backward_function) | ||
| 14 | 13 | { | |
| 15 | 14 | if (!CouldBackprop()) | |
| 16 | 15 | { | |
@@ -19,8 +18,7 @@ void TapeSetRecordBackprop(string op_type, | |||
| 19 | 18 | ||
| 20 | 19 | foreach (var tape in tf.GetTapeSet()) | |
| 21 | 20 | { | |
| 22 | - tape.RecordOperation(op_type, input_tensors, output_tensors, | ||
| 23 | - backward_function_getter); | ||
| 21 | + tape.RecordOperation(op_type, input_tensors, output_tensors, backward_function); | ||
| 24 | 22 | } | |
| 25 | 23 | } | |
| 26 | 24 | } | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -9,7 +9,7 @@ public partial class EagerRunner | |||
| 9 | 9 | bool TapeSetRecordForwardprop(string op_type, | |
| 10 | 10 | Tensor[] input_tensors, | |
| 11 | 11 | TapeTensor[] output_tensors, | |
| 12 | - Func<BackwardFunction> backward_function_getter) | ||
| 12 | + BackwardFunction backward_function_getter) | ||
| 13 | 13 | { | |
| 14 | 14 | if (!CouldForwardprop()) | |
| 15 | 15 | { | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -10,16 +10,16 @@ public partial class EagerRunner | |||
| 10 | 10 | public bool TapeSetRecordOperation(string op_type, | |
| 11 | 11 | Tensor[] input_tensors, | |
| 12 | 12 | Tensor[] output_tensors, | |
| 13 | - Func<BackwardFunction> backward_function_getter) | ||
| 13 | + BackwardFunction backward_function) | ||
| 14 | 14 | { | |
| 15 | 15 | var output_info = output_tensors.Select(x => new TapeTensor(x)).ToArray(); | |
| 16 | 16 | ||
| 17 | 17 | if (!TapeSetRecordForwardprop(op_type, input_tensors, output_info, | |
| 18 | - backward_function_getter)) | ||
| 18 | + backward_function)) | ||
| 19 | 19 | return false; | |
| 20 | 20 | ||
| 21 | 21 | TapeSetRecordBackprop(op_type, input_tensors, output_info, | |
| 22 | - backward_function_getter); | ||
| 22 | + backward_function); | ||
| 23 | 23 | ||
| 24 | 24 | return true; | |
| 25 | 25 | } | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -9,7 +9,8 @@ public interface IEagerRunner | |||
| 9 | 9 | { | |
| 10 | 10 | Tensor[] Execute(Context ctx, string op_name, | |
| 11 | 11 | int num_outputs, | |
| 12 | - Tensor[] inputs, object[] attrs, | ||
| 12 | + Tensor[] inputs, | ||
| 13 | + object[] attrs, | ||
| 13 | 14 | string name = null); | |
| 14 | 15 | ||
| 15 | 16 | (TF_DataType, Tensor[]) ArgsToMatchingEager(Context ctx, | |
@@ -34,7 +35,7 @@ bool RecordGradient(string op_name, | |||
| 34 | 35 | Tensor[] inputs, | |
| 35 | 36 | object[] attrs, | |
| 36 | 37 | Tensor[] results, | |
| 37 | - Func<BackwardFunction> getBackwardFunction = null); | ||
| 38 | + BackwardFunction getBackwardFunction = null); | ||
| 38 | 39 | ||
| 39 | 40 | bool MustRecordGradient(); | |
| 40 | 41 | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -47,7 +47,7 @@ public void Record(Tensors flat_outputs, Tensors inference_args) | |||
| 47 | 47 | { | |
| 48 | 48 | var (backward_function, to_record) = _wrap_backward_function(_forward_graph, _backward, flat_outputs); | |
| 49 | 49 | tf.Runner.RecordGradient(_forward.Name, inference_args, new object[0], to_record, | |
| 50 | - getBackwardFunction: () => backward_function); | ||
| 50 | + getBackwardFunction: backward_function); | ||
| 51 | 51 | } | |
| 52 | 52 | ||
| 53 | 53 | /// <summary> | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -5,7 +5,7 @@ namespace Tensorflow.Gradients | |||
| 5 | 5 | { | |
| 6 | 6 | public class BackpropInitialState | |
| 7 | 7 | { | |
| 8 | - public OpTape<BackwardFunction, TapeTensor> op_tape { get; set; } | ||
| 8 | + public OpTape op_tape { get; set; } | ||
| 9 | 9 | /// <summary> | |
| 10 | 10 | /// Map from tensor to how many references still exist for this tensor in | |
| 11 | 11 | /// the tape. | |
@@ -19,7 +19,7 @@ public class BackpropInitialState | |||
| 19 | 19 | ||
| 20 | 20 | public BackpropInitialState() | |
| 21 | 21 | { | |
| 22 | - op_tape = new OpTape<BackwardFunction, TapeTensor>(); | ||
| 22 | + op_tape = new OpTape(); | ||
| 23 | 23 | tensor_usage_counts = new UnorderedMap<Tensor, long>(); | |
| 24 | 24 | op_missing_tensor = new UnorderedMap<Tensor, long>(); | |
| 25 | 25 | } | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -13,7 +13,7 @@ public interface ITape | |||
| 13 | 13 | void RecordOperation(string op_type, | |
| 14 | 14 | Tensor[] input_tensors, | |
| 15 | 15 | TapeTensor[] output_tensors, | |
| 16 | - Func<BackwardFunction> backward_function_getter); | ||
| 16 | + BackwardFunction backward_function); | ||
| 17 | 17 | ||
| 18 | 18 | void VariableAccessed(ResourceVariable variable); | |
| 19 | 19 | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -5,10 +5,7 @@ namespace Tensorflow.Gradients | |||
| 5 | 5 | /// <summary> | |
| 6 | 6 | /// Map from operation-id to tape entry. | |
| 7 | 7 | /// </summary> | |
| 8 | - /// <typeparam name="BackwardFunction"></typeparam> | ||
| 9 | - /// <typeparam name="TapeTensor"></typeparam> | ||
| 10 | - public class OpTape<BackwardFunction, TapeTensor> : | ||
| 11 | - UnorderedMap<Tensor, OpTapeEntry<BackwardFunction, TapeTensor>> | ||
| 8 | + public class OpTape : UnorderedMap<Tensor, OpTapeEntry> | ||
| 12 | 9 | { | |
| 13 | 10 | ||
| 14 | 11 | } | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -5,9 +5,7 @@ namespace Tensorflow.Gradients | |||
| 5 | 5 | /// <summary> | |
| 6 | 6 | /// Represents an entry in the tape. | |
| 7 | 7 | /// </summary> | |
| 8 | - /// <typeparam name="BackwardFunction"></typeparam> | ||
| 9 | - /// <typeparam name="TapeTensor"></typeparam> | ||
| 10 | - public class OpTapeEntry<BackwardFunction, TapeTensor> | ||
| 8 | + public class OpTapeEntry | ||
| 11 | 9 | { | |
| 12 | 10 | public string op_type { get; set; } | |
| 13 | 11 | public TapeTensor[] output_tensor_info { get; set; } | |
| Back | FazBrowse Home | New Git URL |
0 commit comments