@@ -221,7 +221,7 @@ public T evaluate<T>(Tensor tensor)
221
221
}
222
222
223
223
///Returns a TensorFlow Session for use in executing tests.
224
- public IEnumerable < Session > cached_session (
224
+ public Session cached_session (
225
225
Graph graph = null , object config = null , bool use_gpu = false , bool force_gpu = false )
226
226
{
227
227
// This method behaves differently than self.session(): for performance reasons
@@ -267,9 +267,8 @@ public IEnumerable<Session> cached_session(
267
267
{
268
268
var sess = self . _get_cached_session (
269
269
graph , config , force_gpu , crash_if_inconsistent_args : true ) ;
270
- var cached = self . _constrain_devices_and_set_default ( sess , use_gpu , force_gpu ) ;
271
- return cached ;
272
-
270
+ using var cached = self . _constrain_devices_and_set_default ( sess , use_gpu , force_gpu ) ;
271
+ return cached ;
273
272
}
274
273
}
275
274
@@ -318,13 +317,12 @@ public Session session(Graph graph = null, object config = null, bool use_gpu =
318
317
return s . as_default ( ) ;
319
318
}
320
319
321
- private IEnumerable < Session > _constrain_devices_and_set_default ( Session sess , bool use_gpu , bool force_gpu )
320
+ private Session _constrain_devices_and_set_default ( Session sess , bool use_gpu , bool force_gpu )
322
321
{
323
322
// Set the session and its graph to global default and constrain devices."""
324
- // if context.executing_eagerly():
325
- // yield None
326
- // else:
327
- {
323
+ if ( tf . executing_eagerly ( ) )
324
+ return null ;
325
+ else {
328
326
sess . graph . as_default ( ) ;
329
327
sess . as_default ( ) ;
330
328
{
@@ -340,13 +338,13 @@ private IEnumerable<Session> _constrain_devices_and_set_default(Session sess, bo
340
338
using (sess.graph.device(gpu_name)) {
341
339
yield return sess;
342
340
}*/
343
- yield return sess ;
341
+ return sess ;
344
342
}
345
343
else if ( use_gpu )
346
- yield return sess ;
344
+ return sess ;
347
345
else
348
346
using ( sess . graph . device ( "/device:CPU:0" ) )
349
- yield return sess ;
347
+ return sess ;
350
348
}
351
349
352
350
}
0 commit comments