"next_docs/en/git@developer.sourcefind.cn:wangsen/mineru.git" did not exist on "cece8f53759170bc486cc0b12f75ca652b2743ff"
Commit 6f5967a0 authored by alope107's avatar alope107 Committed by Taylor Robie
Browse files

Transformer partial fix (#5092)

* Fix Transformer TPU crash in Python 2.X.

- Tensorflow raises an error when tf_inspect.getfullargspec is called on
a functools.partial in Python 2.X. This issue would be hit during the
eval stage of the Transformer TPU model. This change replaces the call
to functools.partial with a lambda to work around the issue.

* Remove unused import from transformer_main.

* Fix lint error.
parent 7bffd37b
...@@ -22,7 +22,6 @@ from __future__ import absolute_import ...@@ -22,7 +22,6 @@ from __future__ import absolute_import
from __future__ import division from __future__ import division
from __future__ import print_function from __future__ import print_function
import functools
import os import os
import tempfile import tempfile
...@@ -111,9 +110,10 @@ def model_fn(features, labels, mode, params): ...@@ -111,9 +110,10 @@ def model_fn(features, labels, mode, params):
if mode == tf.estimator.ModeKeys.EVAL: if mode == tf.estimator.ModeKeys.EVAL:
if params["use_tpu"]: if params["use_tpu"]:
# host call functions should only have tensors as arguments. # host call functions should only have tensors as arguments.
# functools.partial() pre-populates params so that metric_fn is # This lambda pre-populates params so that metric_fn is
# TPUEstimator compliant. # TPUEstimator compliant.
metric_fn = functools.partial(metrics.get_eval_metrics, params=params) metric_fn = lambda logits, labels: (
metrics.get_eval_metrics(logits, labels, params=params))
eval_metrics = (metric_fn, [logits, labels]) eval_metrics = (metric_fn, [logits, labels])
return tf.contrib.tpu.TPUEstimatorSpec( return tf.contrib.tpu.TPUEstimatorSpec(
mode=mode, loss=loss, predictions={"predictions": logits}, mode=mode, loss=loss, predictions={"predictions": logits},
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment