question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Another metric with the same name already exists.

See original GitHub issue

Hi, i’m struggling to use pipeline module from transformers following the installation guide in this repo, maybe i’m doing something wrong and someone can help me.

Environment info

Tried to run ‘transformers-cli env’ and got same error i’m trying to report:

2021-11-03 23:43:42.958058: W tensorflow/stream_executor/platform/default/dso_loader.cc:64] Could not load dynamic library 'libcudart.so.11.0'; dlerror: libcudart.so.11.0: cannot open shared object file: No such file or directory
2021-11-03 23:43:42.958079: I tensorflow/stream_executor/cuda/cudart_stub.cc:29] Ignore above cudart dlerror if you do not have a GPU set up on your machine.
2021-11-03 23:43:43.680663: E tensorflow/core/lib/monitoring/collection_registry.cc:77] Cannot register 2 metrics with the same name: /tensorflow/api/keras/optimizers
Traceback (most recent call last):
  File "/home/ramirom/workspace/testTensor/env/lib/python3.8/site-packages/transformers/file_utils.py", line 2147, in _get_module
    return importlib.import_module("." + module_name, self.__name__)
  File "/usr/lib/python3.8/importlib/__init__.py", line 127, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
  File "<frozen importlib._bootstrap>", line 1014, in _gcd_import
  File "<frozen importlib._bootstrap>", line 991, in _find_and_load
  File "<frozen importlib._bootstrap>", line 975, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 671, in _load_unlocked
  File "<frozen importlib._bootstrap_external>", line 848, in exec_module
  File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
  File "/home/ramirom/workspace/testTensor/env/lib/python3.8/site-packages/transformers/modeling_tf_utils.py", line 637, in <module>
    class TFPreTrainedModel(tf.keras.Model, TFModelUtilsMixin, TFGenerationMixin, PushToHubMixin):
  File "/home/ramirom/workspace/testTensor/env/lib/python3.8/site-packages/tensorflow/python/util/lazy_loader.py", line 62, in __getattr__
    module = self._load()
  File "/home/ramirom/workspace/testTensor/env/lib/python3.8/site-packages/tensorflow/python/util/lazy_loader.py", line 45, in _load
    module = importlib.import_module(self.__name__)
  File "/usr/lib/python3.8/importlib/__init__.py", line 127, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
  File "<frozen importlib._bootstrap>", line 1014, in _gcd_import
  File "<frozen importlib._bootstrap>", line 991, in _find_and_load
  File "<frozen importlib._bootstrap>", line 961, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
  File "<frozen importlib._bootstrap>", line 1014, in _gcd_import
  File "<frozen importlib._bootstrap>", line 991, in _find_and_load
  File "<frozen importlib._bootstrap>", line 961, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
  File "<frozen importlib._bootstrap>", line 1014, in _gcd_import
  File "<frozen importlib._bootstrap>", line 991, in _find_and_load
  File "<frozen importlib._bootstrap>", line 961, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
  File "<frozen importlib._bootstrap>", line 1014, in _gcd_import
  File "<frozen importlib._bootstrap>", line 991, in _find_and_load
  File "<frozen importlib._bootstrap>", line 975, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 671, in _load_unlocked
  File "<frozen importlib._bootstrap_external>", line 848, in exec_module
  File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
  File "/home/ramirom/workspace/testTensor/env/lib/python3.8/site-packages/keras/__init__.py", line 25, in <module>
    from keras import models
  File "/home/ramirom/workspace/testTensor/env/lib/python3.8/site-packages/keras/models.py", line 20, in <module>
    from keras import metrics as metrics_module
  File "/home/ramirom/workspace/testTensor/env/lib/python3.8/site-packages/keras/metrics.py", line 24, in <module>
    from keras import activations
  File "/home/ramirom/workspace/testTensor/env/lib/python3.8/site-packages/keras/activations.py", line 20, in <module>
    from keras.layers import advanced_activations
  File "/home/ramirom/workspace/testTensor/env/lib/python3.8/site-packages/keras/layers/__init__.py", line 23, in <module>
    from keras.engine.input_layer import Input
  File "/home/ramirom/workspace/testTensor/env/lib/python3.8/site-packages/keras/engine/input_layer.py", line 21, in <module>
    from keras.engine import base_layer
  File "/home/ramirom/workspace/testTensor/env/lib/python3.8/site-packages/keras/engine/base_layer.py", line 43, in <module>
    from keras.mixed_precision import loss_scale_optimizer
  File "/home/ramirom/workspace/testTensor/env/lib/python3.8/site-packages/keras/mixed_precision/loss_scale_optimizer.py", line 18, in <module>
    from keras import optimizers
  File "/home/ramirom/workspace/testTensor/env/lib/python3.8/site-packages/keras/optimizers.py", line 31, in <module>
    from keras.optimizer_v2 import adadelta as adadelta_v2
  File "/home/ramirom/workspace/testTensor/env/lib/python3.8/site-packages/keras/optimizer_v2/adadelta.py", line 22, in <module>
    from keras.optimizer_v2 import optimizer_v2
  File "/home/ramirom/workspace/testTensor/env/lib/python3.8/site-packages/keras/optimizer_v2/optimizer_v2.py", line 36, in <module>
    keras_optimizers_gauge = tf.__internal__.monitoring.BoolGauge(
  File "/home/ramirom/workspace/testTensor/env/lib/python3.8/site-packages/tensorflow/python/eager/monitoring.py", line 360, in __init__
    super(BoolGauge, self).__init__('BoolGauge', _bool_gauge_methods,
  File "/home/ramirom/workspace/testTensor/env/lib/python3.8/site-packages/tensorflow/python/eager/monitoring.py", line 135, in __init__
    self._metric = self._metric_methods[self._label_length].create(*args)
tensorflow.python.framework.errors_impl.AlreadyExistsError: Another metric with the same name already exists.

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "/home/ramirom/workspace/testTensor/env/bin/transformers-cli", line 5, in <module>
    from transformers.commands.transformers_cli import main
  File "/home/ramirom/workspace/testTensor/env/lib/python3.8/site-packages/transformers/commands/transformers_cli.py", line 23, in <module>
    from .run import RunCommand
  File "/home/ramirom/workspace/testTensor/env/lib/python3.8/site-packages/transformers/commands/run.py", line 17, in <module>
    from ..pipelines import SUPPORTED_TASKS, TASK_ALIASES, Pipeline, PipelineDataFormat, pipeline
  File "/home/ramirom/workspace/testTensor/env/lib/python3.8/site-packages/transformers/pipelines/__init__.py", line 25, in <module>
    from ..models.auto.configuration_auto import AutoConfig
  File "/home/ramirom/workspace/testTensor/env/lib/python3.8/site-packages/transformers/models/__init__.py", line 19, in <module>
    from . import (
  File "/home/ramirom/workspace/testTensor/env/lib/python3.8/site-packages/transformers/models/layoutlm/__init__.py", line 22, in <module>
    from .configuration_layoutlm import LAYOUTLM_PRETRAINED_CONFIG_ARCHIVE_MAP, LayoutLMConfig
  File "/home/ramirom/workspace/testTensor/env/lib/python3.8/site-packages/transformers/models/layoutlm/configuration_layoutlm.py", line 22, in <module>
    from ...onnx import OnnxConfig, PatchingSpec
  File "/home/ramirom/workspace/testTensor/env/lib/python3.8/site-packages/transformers/onnx/__init__.py", line 17, in <module>
    from .convert import export, validate_model_outputs
  File "/home/ramirom/workspace/testTensor/env/lib/python3.8/site-packages/transformers/onnx/convert.py", line 23, in <module>
    from .. import PreTrainedModel, PreTrainedTokenizer, TensorType, TFPreTrainedModel, is_torch_available
  File "<frozen importlib._bootstrap>", line 1039, in _handle_fromlist
  File "/home/ramirom/workspace/testTensor/env/lib/python3.8/site-packages/transformers/file_utils.py", line 2137, in __getattr__
    module = self._get_module(self._class_to_module[name])
  File "/home/ramirom/workspace/testTensor/env/lib/python3.8/site-packages/transformers/file_utils.py", line 2149, in _get_module
    raise RuntimeError(
RuntimeError: Failed to import transformers.modeling_tf_utils because of the following error (look up to see its traceback):
Another metric with the same name already exists.

  • transformers version: 4.13.0.dev0 and tried 4.12.0 and same error
  • Platform: Ubuntu 20.04.3 LTS
  • Python version: Python 3.8.10
  • PyTorch version (GPU?): none
  • Tensorflow version (GPU?): tensorflow 2.6.1
  • Using GPU in script?: No
  • Using distributed or parallel set-up in script?: No

Information

Model I am using (Bert, XLNet …): I’m just importing pipeline from transformers.

The problem arises when using:

  • [*] the official example scripts: (give details below)
  • my own modified scripts: (give details below)

To reproduce

Steps to reproduce the behavior:

I start from a clean pip environment

  1. install tensorflow following installation page instructions
# Requires the latest pip
pip install --upgrade pip

# Current stable release for CPU and GPU
pip install tensorflow
  1. install transformers following installation instruction: pip install transformers
  2. create a python script (test.py) and do: from transformers import pipeline
  3. run: python3 test.py
  4. i got the following error: Traceback (most recent call last): File "test.py", line 1, in <module> from transformers import pipeline File "<frozen importlib._bootstrap>", line 1039, in _handle_fromlist File "/home/ramirom/workspace/testTensor/env/lib/python3.8/site-packages/transformers/file_utils.py", line 2137, in __getattr__ module = self._get_module(self._class_to_module[name]) File "/home/ramirom/workspace/testTensor/env/lib/python3.8/site-packages/transformers/file_utils.py", line 2149, in _get_module raise RuntimeError( RuntimeError: Failed to import transformers.pipelines because of the following error (look up to see its traceback): Failed to import transformers.modeling_tf_utils because of the following error (look up to see its traceback): Another metric with the same name already exists.

Expected behavior

I expect no error when just importing pipeline

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Reactions:6
  • Comments:6 (1 by maintainers)

github_iconTop GitHub Comments

7reactions
frgfmcommented, Nov 4, 2021

Just FYI: the underlying problem actually seems to come from keras 2.7 after some investigation: https://github.com/keras-team/keras/issues/15585

meaning installing keras==2.6.0 should solve the problem

1reaction
slavkaborovskacommented, Nov 4, 2021

I’ve experienced the same problem, switching to an earlier version of tensorflow (2.5 instead of 2.6) seems to have solved it for me. There seems to be some issue with 2.6 version right now according to this thread: #14265

Read more comments on GitHub >

github_iconTop Results From Across the Web

Another metric with the same name already exists." - Stack ...
TL;DR: Ensure the Keras version matches the Tensorflow version. I am experiencing the same thing with: Windows; Python3.8; Tensorflow-2.6.1.
Read more >
Another metric with the same name already exists in Keras 2.7.0
Importing results in the error AlreadyExistsError: Another metric with the same name already exists. . Describe the expected behavior.
Read more >
Another metric with the same name already exists - General ...
Dear All, I've updated Tensorflow and Keras to 2.6.0. (I use Windows 10 and Python 3.9.6) While trying to follow this tutorial, ...
Read more >
Another metric with the same name already exists
I have problem with this code: from tensorflow.keras.models import Sequential. and got this errors: Traceback (most recent call last): File "K:\test.py", ...
Read more >
Another metrix with the same name already exists
However, it has been couple of days I am suffering with this error ... AlreadyExistsError: Another metric with the same name already exists....
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found