Skip to content

Commit c869138

Browse files
committed
Revise some implementation details.
1 parent 9420ba3 commit c869138

11 files changed

Lines changed: 31 additions & 65 deletions

File tree

‎src/TensorFlowNET.Core/APIs/c_api.customize.cs‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,5 +9,9 @@ public partial class c_api
99
{
1010
[DllImport(TensorFlowLibName)]
1111
public static extern void TFC_SetAttr(SafeGraphHandle graph, IntPtr op, string attr_name, SafeBufferHandle attr_value_proto, SafeStatusHandle status);
12+
[DllImport(TensorFlowLibName)]
13+
public static extern IntPtr TFC_GetHandleShapeAndType(SafeGraphHandle c_graph, TF_Output output);
14+
[DllImport(TensorFlowLibName)]
15+
public static extern void TFC_SetHandleShapeAndType(SafeGraphHandle c_graph, TF_Output output, byte[] data, long proto_len, SafeStatusHandle status);
1216
}
1317
}

‎src/TensorFlowNET.Core/APIs/tf.gradients.cs‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ namespace Tensorflow
2121
{
2222
public partial class tensorflow
2323
{
24-
internal GradientTape _tapeSet;
24+
GradientTape _tapeSet;
2525

2626
/// <summary>
2727
/// Record operations for automatic differentiation.

‎src/TensorFlowNET.Core/Framework/importer.cs‎

Lines changed: 0 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -79,42 +79,6 @@ public static ITensorOrOperation[] import_graph_def(GraphDef graph_def,
7979
return _GatherReturnElements(return_elements, graph, results);
8080
}
8181

82-
//private static ITensorOrOperation[] _import_graph_def_internal(GraphDef graph_def, Dictionary<string, Tensor> input_map = null, string[] return_elements = null,
83-
// bool validate_colocation_constraints = true, string name = null, OpList producer_op_list = null)
84-
//{
85-
// graph_def = _ProcessGraphDefParam(graph_def);
86-
// input_map = _ProcessInputMapParam(input_map);
87-
// return_elements = _ProcessReturnElementsParam(return_elements);
88-
89-
// if(producer_op_list is not null)
90-
// {
91-
// _RemoveDefaultAttrs(producer_op_list, graph_def);
92-
// }
93-
94-
// var graph = ops.get_default_graph();
95-
// string prefix = null;
96-
// tf_with(ops.name_scope(name, "import", input_map.Values), scope =>
97-
// {
98-
// if (scope is not null)
99-
// {
100-
// Debug.Assert(scope.scope_name.EndsWith("/"));
101-
// prefix = scope.scope_name[scope.scope_name.Length - 1].ToString();
102-
// }
103-
// else
104-
// {
105-
// prefix = "";
106-
// }
107-
108-
// input_map = _ConvertInputMapValues(name, input_map);
109-
// });
110-
111-
// var scope_options = c_api_util.ScopedTFImportGraphDefOptions();
112-
// var options = scope_options.Options;
113-
// _PopulateTFImportGraphDefOptions(scope_options, prefix, input_map, return_elements, validate_colocation_constraints);
114-
115-
116-
//}
117-
11882
private static ITensorOrOperation[] _GatherReturnElements(string[] requested_return_elements,
11983
Graph graph,
12084
TF_ImportGraphDefResults results)

‎src/TensorFlowNET.Core/Functions/ConcreteFunction.cs‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -305,7 +305,7 @@ internal Func<Operation, object[], Tensor[]> _get_gradient_function()
305305

306306
private Tensors _build_call_outputs(Tensors result)
307307
{
308-
// TODO(Rinne): dwal with `func_graph.structured_outputs`
308+
// TODO(Rinne): deal with `func_graph.structured_outputs`
309309

310310
return result;
311311
}

‎src/TensorFlowNET.Core/Functions/Function.cs‎

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
namespace Tensorflow
66
{
7-
public class Function: Trackable
7+
public class Function: Trackable, IGenericFunction
88
{
99
#pragma warning disable CS0169 // The field 'Function._handle' is never used
1010
private IntPtr _handle;
@@ -34,6 +34,11 @@ public virtual Tensors Apply(Tensors inputs)
3434
return result;
3535
}
3636

37+
public ConcreteFunction get_concrete_function(params Tensor[] args)
38+
{
39+
return _get_concrete_function_garbage_collected(args);
40+
}
41+
3742
protected virtual Tensors _call(Tensors inputs)
3843
{
3944
if(_variable_creation_fn is not null)
@@ -57,6 +62,18 @@ protected virtual bool _run_functions_eagerly()
5762
return false;
5863
}
5964

65+
protected ConcreteFunction _get_concrete_function_garbage_collected(Tensor[] args)
66+
{
67+
if(_variable_creation_fn is null)
68+
{
69+
_initialize(args);
70+
// TODO(Rinne): _initialize_uninitialized_variables
71+
}
72+
73+
var concrete = _variable_creation_fn._get_concrete_function_internal_garbage_collected(args);
74+
return concrete;
75+
}
76+
6077
private void _initialize(Tensor[] args)
6178
{
6279
_variable_creation_fn = _compiler(_csharp_function);

‎src/TensorFlowNET.Core/Functions/IGenericFunction.cs‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ namespace Tensorflow.Functions
66
{
77
public interface IGenericFunction
88
{
9-
object[] Apply(params object[] args);
10-
ConcreteFunction get_concrete_function(params object[] args);
9+
Tensors Apply(Tensors args);
10+
ConcreteFunction get_concrete_function(params Tensor[] args);
1111
}
1212
}

‎src/TensorFlowNET.Core/Functions/TracingCompiler.cs‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ internal ConcreteFunction _get_concrete_function_internal_garbage_collected(Tens
4949

5050
private (ConcreteFunction, Tensor[]) _maybe_define_function(Tensor[] args)
5151
{
52-
var lookup_func_key = male_cache_key(args);
52+
var lookup_func_key = make_cache_key(args);
5353
if(_function_cache.TryGetValue(lookup_func_key, out var concrete_function))
5454
{
5555
return (concrete_function, args);
@@ -71,7 +71,7 @@ private ConcreteFunction _create_concrete_function(Tensor[] args)
7171
return concrete_function;
7272
}
7373

74-
private static string male_cache_key(Tensor[] inputs)
74+
private static string make_cache_key(Tensor[] inputs)
7575
{
7676
//string res = "";
7777
//foreach (var input in inputs)

‎src/TensorFlowNET.Core/Gradients/gradients_util.cs‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -727,7 +727,7 @@ private static bool _HasAnyNotNoneGrads(Dictionary<string, List<List<Tensor>>> g
727727

728728
private static Tensor[] _MaybeCompile(string scope, Operation op, Tensor[] out_grads, Action func, Func<Operation, Tensor[], Tensor[]> grad_fn)
729729
{
730-
//scope = scope.TrimEnd('/').Replace('/', '_');
730+
// scope = scope.TrimEnd('/').Replace('/', '_');
731731
return grad_fn(op, out_grads);
732732
}
733733

‎src/TensorFlowNET.Core/Graphs/AutoGraphAttribute.cs‎

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -38,21 +38,6 @@ public override void OnEntry(MethodExecutionArgs args)
3838

3939
// make function as an Operation by autograph
4040
// need to restore mode when exits
41-
42-
//var func_graph = new FuncGraph(func_name);
43-
//func_graph.as_default();
44-
//var input_placeholders = args.Arguments.Select(x => tf.placeholder(((Tensor)x).dtype)).ToArray();
45-
//// stop the function from recursive call.
46-
//already_in_boundary = true;
47-
//var outputs = args.Method.Invoke(args.Instance, input_placeholders) as Tensors;
48-
//already_in_boundary = false;
49-
50-
//var opers = func_graph._nodes_by_name.Values.Select(x => x as Operation).ToArray();
51-
//func_graph.ToGraph(opers,
52-
// input_placeholders,
53-
// outputs,
54-
// null);
55-
//func_graph.Exit();
5641
function = new ConcreteFunction(func_name);
5742
function.Enter();
5843

‎src/TensorFlowNET.Core/Operations/c_api.ops.cs‎

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -208,9 +208,5 @@ public partial class c_api
208208

209209
[DllImport(TensorFlowLibName)]
210210
public static extern int TF_OperationOutputListLength(IntPtr oper, string arg_name, SafeStatusHandle status);
211-
[DllImport(TensorFlowLibName)]
212-
public static extern IntPtr TFC_GetHandleShapeAndType(SafeGraphHandle c_graph, TF_Output output);
213-
[DllImport(TensorFlowLibName)]
214-
public static extern void TFC_SetHandleShapeAndType(SafeGraphHandle c_graph, TF_Output output, byte[] data, long proto_len, SafeStatusHandle status);
215211
}
216212
}

0 commit comments

Comments
 (0)