将TPU估算器中的静音日志记录

时间:2019-04-23 17:53:03

标签: tensorflow logging tensorflow-estimator verbosity tpu

我正在使用BERT run_classifier和tensorflow TPUEstimator,每次我训练模型或使用估计器预测器进行预测时,我在屏幕上打印的日志信息太多。我如何摆脱这些信息。以下行被打印一百万次:

INFO:tensorflow:Dequeue next (1) batch(es) of data from outfeed.
I0423 15:45:17.093261 140624241985408 tpu_estimator.py:540] Dequeue next (1) batch(es) of data from outfeed.

下面的代码行已经在我的屏幕上写了上百万次(尽管没有问题,并且使用TPU正确地训练了模型)

E0423 15:44:54.258747 140624241985408 tpu.py:330] Operation of type Placeholder (module_apply_tokens/bert/encoder/layer_6/attention/output/dense/kernel) is not supported on the TPU. Execution will fail if this op is used in the graph. 
ERROR:tensorflow:Operation of type Placeholder (module_apply_tokens/bert/encoder/layer_6/attention/output/dense/bias) is not supported on the TPU. Execution will fail if this op is used in the graph. 

这是产生这种冗长的代码:

from bert import run_classifier
estimator = tf.contrib.tpu.TPUEstimator(
  use_tpu=True,
  model_fn=model_fn,
  config=get_run_config(OUTPUT_DIR),
  train_batch_size=TRAIN_BATCH_SIZE,
  eval_batch_size=EVAL_BATCH_SIZE,
  predict_batch_size=PREDICT_BATCH_SIZE,
)

input_features = run_classifier.convert_examples_to_features(prediction_examples, label_list, MAX_SEQ_LENGTH, tokenizer)
predict_input_fn = run_classifier.input_fn_builder(features=input_features, seq_length=MAX_SEQ_LENGTH, is_training=False, drop_remainder=True)
predictions = estimator.predict(predict_input_fn)

我如何要求模型不打印它们?

1 个答案:

答案 0 :(得分:1)

您应该可以使用

set the logging verbosity level
tf.logging.set_verbosity(v)

您的main()方法的第一行,其中详细级别v可能是:

_level_names = {
  FATAL: 'FATAL',
  ERROR: 'ERROR',
  WARN: 'WARN',
  INFO: 'INFO',
  DEBUG: 'DEBUG',
}

其中v=tf.logging.FATAL将打印最少的日志。