@@ -15,11 +15,13 @@ public class ConcreteFunction: Trackable
1515 {
1616 protected IEnumerable < Tensor > _captured_inputs ;
1717 internal FuncGraph func_graph ;
18+ protected DelayedRewriteGradientFunctions _delayed_rewrite_functions ;
19+ protected Dictionary < string , string > _attrs ;
1820 internal ForwardBackwardCall forward_backward ;
1921 public Tensor [ ] Inputs => func_graph . Inputs ;
2022 public Tensor [ ] CapturedInputs => func_graph . external_captures ;
2123
22- public string Name => func_graph ? . FuncName ;
24+ public string Name => _delayed_rewrite_functions . forward ( ) . Name ;
2325
2426 public Tensor [ ] Outputs ;
2527 public Type ReturnType ;
@@ -31,14 +33,18 @@ public ConcreteFunction(string name)
3133 {
3234 func_graph = new FuncGraph ( name ) ;
3335 _captured_inputs = func_graph . external_captures ;
36+ _attrs = new Dictionary < string , string > ( ) ;
37+ _delayed_rewrite_functions = new DelayedRewriteGradientFunctions ( func_graph , _attrs ) ;
3438 }
3539
3640 public ConcreteFunction ( FuncGraph graph , Dictionary < string , string > attrs = null )
3741 {
3842 func_graph = graph ;
3943 _captured_inputs = func_graph . external_captures ;
4044
41- ToGraph ( graph . Inputs , graph . Outputs . Where ( x => x != null ) . ToArray ( ) ) ;
45+ //ToGraph(graph.Inputs, graph.Outputs.Where(x => x != null).ToArray());
46+ _attrs = attrs ;
47+ _delayed_rewrite_functions = new DelayedRewriteGradientFunctions ( func_graph , _attrs ) ;
4248 }
4349
4450 public ConcreteFunction ( Func < Tensor , Tensor > func , TF_DataType dtype )
@@ -57,6 +63,8 @@ public ConcreteFunction(Func<Tensor, Tensor> func, TF_DataType dtype)
5763 null ) ;
5864 func_graph . Exit ( ) ;
5965 _captured_inputs = func_graph . external_captures ;
66+ _attrs = new Dictionary < string , string > ( ) ;
67+ _delayed_rewrite_functions = new DelayedRewriteGradientFunctions ( func_graph , _attrs ) ;
6068 }
6169
6270 public ConcreteFunction ( Func < Tensor , IDatasetV2 > func , TF_DataType dtype )
@@ -78,6 +86,8 @@ public ConcreteFunction(Func<Tensor, IDatasetV2> func, TF_DataType dtype)
7886 null ) ;
7987 func_graph . Exit ( ) ;
8088 _captured_inputs = func_graph . external_captures ;
89+ _attrs = new Dictionary < string , string > ( ) ;
90+ _delayed_rewrite_functions = new DelayedRewriteGradientFunctions ( func_graph , _attrs ) ;
8191 }
8292
8393 /*public ConcreteFunction(Func<Tensors, Tensors> func,
@@ -176,7 +186,7 @@ public void AddTograph(Graph? g = null)
176186 {
177187 g = ops . get_default_graph ( ) ;
178188 }
179- // TODO(Rinne); complete it with `_delayed_rewrite_functions`.
189+ _delayed_rewrite_functions . forward ( ) . AddToGraph ( g ) ;
180190 }
181191
182192 public void SetExternalCaptures ( IEnumerable < Tensor > captures )
0 commit comments