@@ -0,0 +1,15 @@ | |||||
using System; | |||||
using System.Collections.Generic; | |||||
using System.Text; | |||||
namespace Tensorflow | |||||
{ | |||||
public class AggregationMethod | |||||
{ | |||||
public static int ADD_N = 0; | |||||
public static int DEFAULT = ADD_N; | |||||
// The following are experimental and may not be supported in future releases. | |||||
public static int EXPERIMENTAL_TREE = 1; | |||||
public static int EXPERIMENTAL_ACCUMULATE_N = 2; | |||||
} | |||||
} |
@@ -0,0 +1,32 @@ | |||||
using System; | |||||
using System.Collections.Generic; | |||||
using System.Text; | |||||
namespace Tensorflow | |||||
{ | |||||
public class gradients_impl | |||||
{ | |||||
public static void gradients(object ys, | |||||
object xs, | |||||
List<Tensor> grad_ys = null, | |||||
string name = "gradients", | |||||
bool colocate_gradients_with_ops = false, | |||||
bool gate_gradients = false, | |||||
int? aggregation_method = null) | |||||
{ | |||||
_GradientsHelper(ys, xs, grad_ys, name, colocate_gradients_with_ops, gate_gradients); | |||||
} | |||||
public static void _GradientsHelper(object ys, | |||||
object xs, | |||||
List<Tensor> grad_ys = null, | |||||
string name = "gradients", | |||||
bool colocate_gradients_with_ops = false, | |||||
bool gate_gradients = false, | |||||
Graph src_graph = null) | |||||
{ | |||||
if (src_graph == null) | |||||
src_graph = ops.get_default_graph(); | |||||
} | |||||
} | |||||
} |
@@ -222,7 +222,7 @@ namespace Tensorflow | |||||
} | } | ||||
} | } | ||||
return ""; | |||||
return $"{name} {dtype} {rank} {string.Join(",", shape)}"; | |||||
} | } | ||||
public void Dispose() | public void Dispose() | ||||
@@ -1,5 +1,6 @@ | |||||
using System; | using System; | ||||
using System.Collections.Generic; | using System.Collections.Generic; | ||||
using System.Linq; | |||||
using System.Text; | using System.Text; | ||||
using distribute_lib = Tensorflow.Distribute; | using distribute_lib = Tensorflow.Distribute; | ||||
@@ -48,8 +49,10 @@ namespace Tensorflow | |||||
/// <param name="gate_gradients"></param> | /// <param name="gate_gradients"></param> | ||||
public List<KeyValuePair<object, object>> compute_gradients(Tensor loss, | public List<KeyValuePair<object, object>> compute_gradients(Tensor loss, | ||||
List<RefVariable> var_list = null, | List<RefVariable> var_list = null, | ||||
int? aggregation_method = null, | |||||
GateGradientType gate_gradients = GateGradientType.GATE_OP, | GateGradientType gate_gradients = GateGradientType.GATE_OP, | ||||
bool colocate_gradients_with_ops = false) | |||||
bool colocate_gradients_with_ops = false, | |||||
List<Tensor> grad_loss = null) | |||||
{ | { | ||||
int num_towers = 1; | int num_towers = 1; | ||||
if(distribute_lib.get_loss_reduction() == VariableAggregationType.MEAN) | if(distribute_lib.get_loss_reduction() == VariableAggregationType.MEAN) | ||||
@@ -65,10 +68,13 @@ namespace Tensorflow | |||||
break; | break; | ||||
} | } | ||||
foreach(var v in var_list) | |||||
{ | |||||
var processors = var_list.Select(v => optimizer._get_processor(v)); | |||||
var var_refs = processors.Select(x => x.target()).ToList(); | |||||
} | |||||
gradients_impl.gradients(loss, var_refs, grad_ys: grad_loss, | |||||
gate_gradients: (gate_gradients == GateGradientType.GATE_OP), | |||||
aggregation_method: aggregation_method, | |||||
colocate_gradients_with_ops: colocate_gradients_with_ops); | |||||
return null; | return null; | ||||
} | } | ||||
@@ -0,0 +1,12 @@ | |||||
using System; | |||||
using System.Collections.Generic; | |||||
using System.Text; | |||||
namespace Tensorflow | |||||
{ | |||||
public interface _OptimizableVariable | |||||
{ | |||||
Tensor target(); | |||||
void update_op(Graph g); | |||||
} | |||||
} |
@@ -0,0 +1,34 @@ | |||||
using System; | |||||
using System.Collections.Generic; | |||||
using System.Text; | |||||
namespace Tensorflow | |||||
{ | |||||
public class optimizer | |||||
{ | |||||
public static _OptimizableVariable _get_processor(RefVariable v) | |||||
{ | |||||
return new _RefVariableProcessor(v); | |||||
} | |||||
} | |||||
public class _RefVariableProcessor : _OptimizableVariable | |||||
{ | |||||
private RefVariable _v; | |||||
public _RefVariableProcessor(RefVariable v) | |||||
{ | |||||
_v = v; | |||||
} | |||||
public Tensor target() | |||||
{ | |||||
return _v._ref(); | |||||
} | |||||
public void update_op(Graph g) | |||||
{ | |||||
} | |||||
} | |||||
} |
@@ -78,6 +78,11 @@ namespace Tensorflow | |||||
ops.add_to_collections(collections, this); | ops.add_to_collections(collections, this); | ||||
} | } | ||||
public Tensor _ref() | |||||
{ | |||||
return _variable; | |||||
} | |||||
public static implicit operator _VariableScopeStore(RefVariable variable) | public static implicit operator _VariableScopeStore(RefVariable variable) | ||||
{ | { | ||||
return null; | return null; | ||||