1 通用分配GPU:

import os
os.environ['CUDA_VISIBLE_DEVICES'] = '1,2'

2 有些使用上述方法不可取,需要从代码中指定分配GPU:

  session_config = tf.ConfigProto(device_count={'GPU': 0,'GPU':1,'GPU':2})

  #session_config.gpu_options.per_process_gpu_memory_fraction = 0.9
  #session_config.gpu_options.allow_growth = True
  #session_config.gpu_options.allocator_type = 'BFC'

  run_config = tf.estimator.RunConfig().replace(session_config=session_config)

  estimator = tf.estimator.Estimator(
      model_fn=model_fn, model_dir=FLAGS.model_dir, config=run_config, params=params)
上述代码的注释细节表示每块GPU利用的具体配置。如果需要在tf.estimator 使用多GPU ,需要注释掉这些配置,也就是上述代码注释部分需要注释掉。
GitHub 加速计划 / te / tensorflow
184.54 K
74.12 K
下载
一个面向所有人的开源机器学习框架
最近提交(Master分支:1 个月前 )
a49e66f2 PiperOrigin-RevId: 663726708 1 个月前
91dac11a This test overrides disabled_backends, dropping the default value in the process. PiperOrigin-RevId: 663711155 1 个月前
Logo

旨在为数千万中国开发者提供一个无缝且高效的云端环境,以支持学习、使用和贡献开源项目。

更多推荐