| @@ -1,5 +1,6 @@ | |||||
| using System; | using System; | ||||
| using System.Linq; | using System.Linq; | ||||
| using Microsoft.Extensions.Logging; | |||||
| using Tensorflow.Gradients; | using Tensorflow.Gradients; | ||||
| using static Tensorflow.Binding; | using static Tensorflow.Binding; | ||||
| using static Tensorflow.tensorflow; | using static Tensorflow.tensorflow; | ||||
| @@ -38,7 +39,7 @@ namespace Tensorflow.Eager | |||||
| }*/ | }*/ | ||||
| } | } | ||||
| // Console.WriteLine($"RecordGradient: should_record={should_record}, op_name={op_name}"); | |||||
| tf.Logger.LogDebug($"RecordGradient: should_record={should_record}, op_name={op_name}"); | |||||
| if (!should_record) return should_record; | if (!should_record) return should_record; | ||||
| Tensor[] op_outputs; | Tensor[] op_outputs; | ||||
| @@ -0,0 +1,15 @@ | |||||
| using System; | |||||
| using Tensorflow.Gradients; | |||||
| using static Tensorflow.Binding; | |||||
| using static Tensorflow.tensorflow; | |||||
| namespace Tensorflow.Eager | |||||
| { | |||||
| public partial class EagerRunner | |||||
| { | |||||
| public int TapeSetPossibleGradientTypes(params Tensor[] args) | |||||
| { | |||||
| return 1; | |||||
| } | |||||
| } | |||||
| } | |||||
| @@ -40,5 +40,7 @@ namespace Tensorflow.Eager | |||||
| Tensor[] results); | Tensor[] results); | ||||
| bool MustRecordGradient(); | bool MustRecordGradient(); | ||||
| int TapeSetPossibleGradientTypes(params Tensor[] args); | |||||
| } | } | ||||
| } | } | ||||
| @@ -1,7 +1,9 @@ | |||||
| using System; | using System; | ||||
| using System.Collections.Generic; | using System.Collections.Generic; | ||||
| using Microsoft.Extensions.Logging; | |||||
| using Tensorflow.Util; | using Tensorflow.Util; | ||||
| using static Tensorflow.tensorflow; | using static Tensorflow.tensorflow; | ||||
| using static Tensorflow.Binding; | |||||
| namespace Tensorflow.Gradients | namespace Tensorflow.Gradients | ||||
| { | { | ||||
| @@ -34,6 +36,7 @@ namespace Tensorflow.Gradients | |||||
| foreach (var o in output_tensors) | foreach (var o in output_tensors) | ||||
| { | { | ||||
| tensor_tape_[o.GetID()] = op_id; | tensor_tape_[o.GetID()] = op_id; | ||||
| tf.Logger.LogDebug($"RecordOperation: tensor_tape_[{o.GetID()}] = {op_id}"); | |||||
| tensor_usage_[o.GetID()] = 1; | tensor_usage_[o.GetID()] = 1; | ||||
| tensors.Add(o); | tensors.Add(o); | ||||
| } | } | ||||
| @@ -1,5 +1,7 @@ | |||||
| using System.Collections.Generic; | |||||
| using System; | |||||
| using System.Collections.Generic; | |||||
| using Tensorflow.Util; | using Tensorflow.Util; | ||||
| using Microsoft.Extensions.Logging; | |||||
| using static Tensorflow.Binding; | using static Tensorflow.Binding; | ||||
| using static Tensorflow.tensorflow; | using static Tensorflow.tensorflow; | ||||
| @@ -42,6 +44,7 @@ namespace Tensorflow.Gradients | |||||
| if (!CouldBackprop()) | if (!CouldBackprop()) | ||||
| return; | return; | ||||
| tf.Logger.LogDebug($"Watch tensor_id={tensor_id}"); | |||||
| tensor_tape_.emplace(tensor_id, -1); | tensor_tape_.emplace(tensor_id, -1); | ||||
| } | } | ||||
| @@ -50,8 +53,13 @@ namespace Tensorflow.Gradients | |||||
| for (int i = 0; i < tensor_ids.Length; ++i) | for (int i = 0; i < tensor_ids.Length; ++i) | ||||
| { | { | ||||
| if (tensor_tape_.find(tensor_ids[i])) | if (tensor_tape_.find(tensor_ids[i])) | ||||
| { | |||||
| if (IsDtypeTrainable(dtypes[i])) | if (IsDtypeTrainable(dtypes[i])) | ||||
| { | |||||
| tf.Logger.LogDebug($"tape.h->ShouldRecord: should_record = true, tensor_tape_.size()={tensor_tape_.Count}, tensor_ids[{i}]={tensor_ids[i]}"); | |||||
| return true; | return true; | ||||
| } | |||||
| } | |||||
| } | } | ||||
| return false; | return false; | ||||
| } | } | ||||
| @@ -84,6 +84,9 @@ TensorFlow .NET v0.30 is focused on making more Keras API work including: | |||||
| <ItemGroup> | <ItemGroup> | ||||
| <PackageReference Include="Google.Protobuf" Version="3.11.4" /> | <PackageReference Include="Google.Protobuf" Version="3.11.4" /> | ||||
| <PackageReference Include="MethodBoundaryAspect.Fody" Version="2.0.138" /> | <PackageReference Include="MethodBoundaryAspect.Fody" Version="2.0.138" /> | ||||
| <PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="3.1.10" /> | |||||
| <PackageReference Include="Microsoft.Extensions.Logging" Version="3.1.10" /> | |||||
| <PackageReference Include="Microsoft.Extensions.Logging.Console" Version="3.1.10" /> | |||||
| <PackageReference Include="NumSharp.Lite" Version="0.1.9" /> | <PackageReference Include="NumSharp.Lite" Version="0.1.9" /> | ||||
| <PackageReference Include="Protobuf.Text" Version="0.4.0" /> | <PackageReference Include="Protobuf.Text" Version="0.4.0" /> | ||||
| </ItemGroup> | </ItemGroup> | ||||
| @@ -14,6 +14,8 @@ | |||||
| limitations under the License. | limitations under the License. | ||||
| ******************************************************************************/ | ******************************************************************************/ | ||||
| using Microsoft.Extensions.DependencyInjection; | |||||
| using Microsoft.Extensions.Logging; | |||||
| using System.Collections.Generic; | using System.Collections.Generic; | ||||
| using Tensorflow.Contexts; | using Tensorflow.Contexts; | ||||
| using Tensorflow.Eager; | using Tensorflow.Eager; | ||||
| @@ -41,9 +43,18 @@ namespace Tensorflow | |||||
| public OpDefLibrary OpDefLib; | public OpDefLibrary OpDefLib; | ||||
| public Context Context; | public Context Context; | ||||
| public IEagerRunner Runner; | public IEagerRunner Runner; | ||||
| public ILogger Logger; | |||||
| ServiceProvider serviceProvider; | |||||
| public tensorflow() | public tensorflow() | ||||
| { | { | ||||
| serviceProvider = new ServiceCollection() | |||||
| .AddLogging(cfg => cfg.AddConsole()) | |||||
| .Configure<LoggerFilterOptions>(cfg => cfg.MinLevel = LogLevel.Warning) | |||||
| .BuildServiceProvider(); | |||||
| Logger = serviceProvider.GetService<ILogger<tensorflow>>(); | |||||
| Status = new Status(); | Status = new Status(); | ||||
| Context = new Context(new ContextOptions(), Status); | Context = new Context(new ContextOptions(), Status); | ||||
| OpDefLib = new OpDefLibrary(); | OpDefLib = new OpDefLibrary(); | ||||
| @@ -3,6 +3,7 @@ using System.Collections.Generic; | |||||
| using System.Linq; | using System.Linq; | ||||
| using Tensorflow.Keras.ArgsDefinition; | using Tensorflow.Keras.ArgsDefinition; | ||||
| using Tensorflow.Keras.Utils; | using Tensorflow.Keras.Utils; | ||||
| using Microsoft.Extensions.Logging; | |||||
| using static Tensorflow.Binding; | using static Tensorflow.Binding; | ||||
| namespace Tensorflow.Keras.Engine | namespace Tensorflow.Keras.Engine | ||||
| @@ -335,7 +336,7 @@ namespace Tensorflow.Keras.Engine | |||||
| var layer_inputs = node.MapArguments(tensor_dict); | var layer_inputs = node.MapArguments(tensor_dict); | ||||
| // Console.WriteLine($"{node.Layer}: {node.Layer.Name}"); | |||||
| tf.Logger.LogDebug($"{node.Layer}: {node.Layer.Name}"); | |||||
| var outputs = node.Layer.Apply(layer_inputs, is_training: training); | var outputs = node.Layer.Apply(layer_inputs, is_training: training); | ||||
| // Update tensor_dict for next input | // Update tensor_dict for next input | ||||