为了账号安全,请及时绑定邮箱和手机立即绑定

Tensorflow如何使用我的GPU?

Tensorflow如何使用我的GPU?

千巷猫影 2021-05-12 14:20:57
所以我正在训练Tensorflow中的NN,同时我正在监视我的GPU负载。从屏幕截图中可以看到Tensorflow基本上只使用GPU内存,这正常吗?我以为他们利用了我所有的cuda核心来执行一些计算等。有没有人真的知道这些东西?提前致谢!代码来了...import tensorflow as tftf.logging.set_verbosity(tf.logging.INFO)# ... some file reading here def train_input_fn(features, labels, batch_size):    return tf.estimator.inputs.pandas_input_fn(        x = features,        y = labels,        num_epochs = 1,        shuffle = True,        batch_size = batch_size)def eval_input_fn(features, labels):    return tf.estimator.inputs.pandas_input_fn(        x = features,        y = labels,        num_epochs = 1,        shuffle = True)def pred_input_fn(features):    return tf.estimator.inputs.pandas_input_fn(        x = features,        num_epochs = 1,        shuffle = False)model_dir = './DNN_Linear_Combined_Regressor'file_writer = tf.summary.FileWriter(model_dir)estimator = tf.estimator.DNNLinearCombinedRegressor(    model_dir = model_dir,    linear_feature_columns = wide_columns,    dnn_feature_columns = deep_columns,    dnn_optimizer = tf.train.AdamOptimizer(learning_rate=0.001),    dnn_hidden_units = [64,64,64,8],     batch_norm = True,    dnn_dropout = 0.1)train_spec = tf.estimator.TrainSpec(input_fn = train_input_fn(train, y_train, batch_size=5000))eval_spec = tf.estimator.EvalSpec(input_fn = eval_input_fn(valid, y_valid))tf.estimator.train_and_evaluate(estimator, train_spec, eval_spec)
查看完整描述

2 回答

?
慕桂英546537

TA贡献1848条经验 获得超10个赞

根据此处的TensorFlow文档,默认情况下,TensorFlow将使用与您的GPU内存一样多的内存。


另外,您可以通过以下代码检查哪个张量计算正在使用终端中的哪个设备:


# Creates an estimator with log_device_placement set to True.

sess_config = tf.ConfigProto(log_device_placement=True)

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

your_classifier = tf.estimator.Estimator(config=run_config)

您会看到以下内容:


Device mapping:

/job:localhost/replica:0/task:0/device:GPU:0 -> device: 0, name: Tesla K40c, pci bus

id: 0000:05:00.0

b: /job:localhost/replica:0/task:0/device:GPU:0

a: /job:localhost/replica:0/task:0/device:GPU:0

MatMul: /job:localhost/replica:0/task:0/device:GPU:0

GPU:0您的默认GPU在哪里。


查看完整回答
反对 回复 2021-05-25
  • 2 回答
  • 0 关注
  • 146 浏览
慕课专栏
更多

添加回答

举报

0/150
提交
取消
微信客服

购课补贴
联系客服咨询优惠详情

帮助反馈 APP下载

慕课网APP
您的移动学习伙伴

公众号

扫描二维码
关注慕课网微信公众号