• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Python context.execution_mode函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Python中tensorflow.python.eager.context.execution_mode函数的典型用法代码示例。如果您正苦于以下问题:Python execution_mode函数的具体用法?Python execution_mode怎么用?Python execution_mode使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



在下文中一共展示了execution_mode函数的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。

示例1: decorator

  def decorator(self, *args, **kwargs):
    # TODO(b/117110239): Re-enable.
    # with context.execution_mode(context.ASYNC):
    #   f(self, *args, **kwargs)

    with context.execution_mode(context.SYNC):
      f(self, *args, **kwargs)
开发者ID:Albert-Z-Guo,项目名称:tensorflow,代码行数:7,代码来源:remote_test.py


示例2: testEagerIteratorAsync

 def testEagerIteratorAsync(self):
   with context.eager_mode(), context.execution_mode(context.ASYNC):
     val = 0
     dataset = dataset_ops.Dataset.range(10)
     for foo in dataset:
       self.assertEqual(val, foo.numpy())
       val += 1
开发者ID:kylin9872,项目名称:tensorflow,代码行数:7,代码来源:iterator_test.py


示例3: testDatasetEagerIteration

 def testDatasetEagerIteration(self, execution_mode):
   with context.eager_mode(), context.execution_mode(execution_mode):
     val = 0
     dataset = dataset_ops.Dataset.range(10)
     for foo in dataset:
       self.assertEqual(val, foo.numpy())
       val += 1
开发者ID:aritratony,项目名称:tensorflow,代码行数:7,代码来源:dataset_test.py


示例4: _next_internal

  def _next_internal(self):
    """Returns a nested structure of `tf.Tensor`s containing the next element.
    """
    if not context.executing_eagerly():
      with ops.device(self._device):
        ret = gen_dataset_ops.iterator_get_next(
            self._iterator_resource,
            output_types=self._flat_output_types,
            output_shapes=self._flat_output_shapes)
      return self._structure._from_compatible_tensor_list(ret)  # pylint: disable=protected-access

    # This runs in sync mode as iterators use an error status to communicate
    # that there is no more data to iterate over.
    # TODO(b/77291417): Fix
    with context.execution_mode(context.SYNC):
      with ops.device(self._device):
        # TODO(ashankar): Consider removing this ops.device() contextmanager
        # and instead mimic ops placement in graphs: Operations on resource
        # handles execute on the same device as where the resource is placed.
        # NOTE(mrry): Here we use the "_sync" variant of `iterator_get_next`
        # because in eager mode this code will run synchronously on the calling
        # thread. Therefore we do not need to make a defensive context switch
        # to a background thread, and can achieve a small constant performance
        # boost by invoking the iterator synchronously.
        ret = gen_dataset_ops.iterator_get_next_sync(
            self._iterator_resource,
            output_types=self._flat_output_types,
            output_shapes=self._flat_output_shapes)

      return self._structure._from_compatible_tensor_list(ret)  # pylint: disable=protected-access
开发者ID:adit-chandra,项目名称:tensorflow,代码行数:30,代码来源:iterator_ops.py


示例5: _next_internal

 def _next_internal(self):
   """Returns a nested structure of `tf.Tensor`s containing the next element.
   """
   # This runs in sync mode as iterators use an error status to communicate
   # that there is no more data to iterate over.
   # TODO(b/77291417): Fix
   with context.execution_mode(context.SYNC):
     return super(Iterator, self)._next_internal()
开发者ID:Ajaycs99,项目名称:tensorflow,代码行数:8,代码来源:datasets.py


示例6: _next_internal

 def _next_internal(self):
   """Returns a nested structure of `tf.Tensor`s containing the next element.
   """
   # This runs in sync mode as iterators use an error status to communicate
   # that there is no more data to iterate over.
   # TODO(b/77291417): Fix
   with context.execution_mode(context.SYNC):
     with ops.device(self._device):
       flat_ret = ged_ops.experimental_function_buffering_resource_get_next(
           function_buffer_resource=self._buffering_resource,
           output_types=self._flat_output_types)
     return self._element_structure._from_tensor_list(flat_ret)
开发者ID:abhinav-upadhyay,项目名称:tensorflow,代码行数:12,代码来源:prefetching_ops.py


示例7: testCopyBetweenDevicesAsync

  def testCopyBetweenDevicesAsync(self):
    with context.execution_mode(context.ASYNC):
      x = constant_op.constant([[1., 2.], [3., 4.]])
      x = x.cpu()
      x = x.gpu()
      x = x.gpu()
      x = x.cpu()
      context.async_wait()

    # Invalid device
    with self.assertRaises(RuntimeError):
      x.gpu(context.context().num_gpus() + 1)
      context.async_wait()
    context.async_clear_error()
开发者ID:adit-chandra,项目名称:tensorflow,代码行数:14,代码来源:core_test.py


示例8: _run

 def _run(self, func, num_iters, execution_mode=None):
   # call func to maybe warm up the GPU
   ctx = context.context()
   with context.execution_mode(execution_mode):
     func()
     if execution_mode == context.ASYNC:
       ctx.async_wait()
     start = time.time()
     for _ in xrange(num_iters):
       func()
     if execution_mode == context.ASYNC:
       ctx.async_wait()
     end = time.time()
     mean_us = (end - start) * 1e6 / num_iters
     self.report_benchmark(
         iters=num_iters,
         wall_time=mean_us,
         extras={"examples_per_sec": num_iters / (end - start)})
开发者ID:adit-chandra,项目名称:tensorflow,代码行数:18,代码来源:benchmarks_test.py


示例9: testExecuteBasicAsync

 def testExecuteBasicAsync(self):
   with context.execution_mode(context.ASYNC):
     three = constant_op.constant(3)
     five = constant_op.constant(5)
     product = execute(
         b'Mul',
         num_outputs=1,
         inputs=[three, five],
         attrs=('T', three.dtype.as_datatype_enum))[0]
     self.assertAllEqual(15, product)
   # Error: Invalid arguments
   context.set_execution_mode(context.ASYNC)
   with self.assertRaises(errors.InvalidArgumentError):
     execute(
         b'MatMul',
         num_outputs=1,
         inputs=[three, five],
         attrs=('transpose_a', False, 'transpose_b', False, 'T',
                three.dtype.as_datatype_enum))
     context.async_wait()
   context.async_clear_error()
   context.set_execution_mode(context.SYNC)
开发者ID:StephenOman,项目名称:tensorflow,代码行数:22,代码来源:core_test.py


示例10: decorator

  def decorator(self, *args, **kwargs):
    with context.execution_mode(context.ASYNC):
      f(self, *args, **kwargs)

    with context.execution_mode(context.SYNC):
      f(self, *args, **kwargs)
开发者ID:ZhangXinNan,项目名称:tensorflow,代码行数:6,代码来源:remote_test.py



注:本文中的tensorflow.python.eager.context.execution_mode函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python context.get_default_context函数代码示例发布时间:2022-05-27
下一篇:
Python context.executing_eagerly函数代码示例发布时间:2022-05-27
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap