記事一覧表示

TPUEstimatorのログを消した話

公開されている事前学習済みBERTを持ってきて、notebook上で公式の通りに動かしているんですが、fine-tuning中に「ログが多すぎて、これ以上表示できない」みたいなエラーで止まっしまった。
表示されているログを見ると、

I0229 11:37:52.823160 140695538263808 tpu_estimator.py:2307] global_step/sec: 0.193832
INFO:tensorflow:examples/sec: 1.55065
I0229 11:37:52.824455 140695538263808 tpu_estimator.py:2308] examples/sec: 1.55065
INFO:tensorflow:global_step/sec: 5.84653

みたいなログが、step(batch)毎に表示されていた。
まあ、多分、step(batch)毎の学習時間を表示しているだけなので、消しても問題ないはず。
上記のログを見ると tpu_estimator.py の2307行目と2308行目でメッセージが出てるっぽいので、ターミナルでファイル tpu_estimator.py を検索。

$ sudo find / -name tpu_estimator.py | xargs -I {} wc {}
  33  169 1851 /home/jupyter/src/tensorflow/tensorflow/contrib/tpu/python/tpu/tpu_estimator.py
             ・
             ・
  4422  15483 179695 /usr/local/lib/python2.7/dist-packages/tensorflow_estimator/python/estimator/tpu/tpu_estimator.py
             ・
             ・
  4422  15483 179695 /usr/local/lib/python3.5/dist-packages/tensorflow_estimator/python/estimator/tpu/tpu_estimator.py
  33  169 1851 /usr/local/lib/python3.5/dist-packages/tensorflow_core/contrib/tpu/python/tpu/tpu_estimator.py
  33  169 1851 /usr/local/lib/python3.5/dist-packages/tensorflow_core/python/tpu/tpu_estimator.py

python3で動かしてた(てか、python2にもtensorflowあるのか)ので /usr/local/lib/python3.5/dist-packages/tensorflow_estimator/python/estimator/tpu/tpu_estimator.py だと推定。
このファイルの2307行目と2308行目を以下のようにコメントアウト

    #logging.info('global_step/sec: %g', global_step_per_sec)              
    #logging.info('examples/sec: %g', examples_per_sec)

これでログが消えた。