Skip to content

Commit b09c2e4

Browse files
committed
Go back to VarHandleOp
1 parent d6ffea7 commit b09c2e4

1 file changed

Lines changed: 9 additions & 9 deletions

File tree

TensorFlowSharp/OperationsExtras.cs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -104,9 +104,9 @@ public TFOutput Variable (TFOutput initialValue, out TFOperation init, out TFOut
104104

105105
using (var newScope = WithScope (scopeName)) {
106106
var type = initialValue.OutputType;
107-
var handle = VariableV2 (new TFShape (GetShape (initialValue)), type);
107+
var handle = VarHandleOp (type, new TFShape (GetShape (initialValue)));
108108
using (var aScope = WithScope ("Assign")) {
109-
init = Assign (handle, initialValue).Operation;
109+
init = AssignVariableOp (handle, initialValue);
110110
if (trainable)
111111
AddTrainableVariable (handle.Operation);
112112
using (var rScope = WithScope ("Read")) {
@@ -187,10 +187,10 @@ public TFOutput Variable (TFOutput initialValue, out TFOutput value, bool traina
187187

188188
using (var newScope = WithScope (scopeName)) {
189189
var type = initialValue.OutputType;
190-
var handle = VariableV2 (new TFShape (GetShape (initialValue)), type);
190+
var handle = VarHandleOp (type, new TFShape (GetShape (initialValue)));
191191
using (var aScope = WithScope ("Assign")) {
192-
var init = Assign (handle, initialValue);
193-
AddInitVariable (init.Operation);
192+
var init = AssignVariableOp (handle, initialValue);
193+
AddInitVariable (init);
194194
if (trainable)
195195
AddTrainableVariable (handle.Operation);
196196
using (var rScope = WithScope ("Read")) {
@@ -207,7 +207,7 @@ public TFOutput Variable (TFOutput initialValue, out TFOutput value, bool traina
207207
/// <param name="initialValue">Initial value.</param>
208208
/// <param name="trainable">If true, this add the variable to the graph's TrainableVariables, this collection is intended to be used by the Optimizer classes.</param>
209209
/// <param name="operName">Operation name, optional.</param>
210-
/// <returns>The returning TFOutput returns the handle to the variable.</returns>
210+
/// <returns>The returning TFOutput returns the handle to the variable, this is a VarHandleOp, if you want to read it, create a ReadVariableOp on result.</returns>
211211
/// <remarks>
212212
/// Variables need to be initialized before the main execution so you will typically want to
213213
/// run the session on the variable.
@@ -221,10 +221,10 @@ public TFOutput Variable (TFOutput initialValue, bool trainable = true, string o
221221
using (var newScope = WithScope (scopeName)) {
222222
var type = initialValue.OutputType;
223223

224-
var handle = VariableV2 (new TFShape (GetShape (initialValue)), type);
224+
var handle = VarHandleOp (type, new TFShape (GetShape (initialValue)));
225225
using (var aScope = WithScope ("Assign")) {
226-
var init = Assign (handle, initialValue);
227-
AddInitVariable (handle.Operation);
226+
var init = AssignVariableOp (handle, initialValue);
227+
AddInitVariable (init);
228228
if (trainable)
229229
AddTrainableVariable (handle.Operation);
230230
return handle;

0 commit comments

Comments
 (0)