The sample code is under # Fine-tuning the model segment. Attached below:
from transformers import TrainingArguments
model_name = model_id.split(“/”)[-1]
batch_size = 8
gradient_accumulation_steps = 1
num_train_epochs = 10
training_args = TrainingArguments(
f"{model_name}-finetuned-gtzan",
evaluation_strategy=“epoch”,
save_strategy=“epoch”,
learning_rate=5e-5,
per_device_train_batch_size=batch_size,
gradient_accumulation_steps=gradient_accumulation_steps,
per_device_eval_batch_size=batch_size,
num_train_epochs=num_train_epochs,
warmup_ratio=0.1,
logging_steps=5,
load_best_model_at_end=True,
metric_for_best_model=“accuracy”,
fp16=True,
push_to_hub=True,
)
The error messages I got from jupyter is :
AlreadyExistsError Traceback (most recent call last)
File ~\anaconda3\envs\pygpu\lib\site-packages\transformers\utils\import_utils.py:1793, in _LazyModule._get_module(self, module_name)
1792 try:
→ 1793 return importlib.import_module(“.” + module_name, self.name)
1794 except Exception as e:
File ~\anaconda3\envs\pygpu\lib\importlib_init_.py:126, in import_module(name, package)
125 level += 1
→ 126 return _bootstrap._gcd_import(name[level:], package, level)
File :1050, in _gcd_import(name, package, level)
File :1027, in find_and_load(name, import)
File :1006, in find_and_load_unlocked(name, import)
File :688, in _load_unlocked(spec)
File :883, in exec_module(self, module)
File :241, in _call_with_frames_removed(f, *args, **kwds)
File ~\anaconda3\envs\pygpu\lib\site-packages\transformers\modeling_tf_utils.py:38
37 from . import DataCollatorWithPadding, DefaultDataCollator
—> 38 from .activations_tf import get_tf_activation
39 from .configuration_utils import PretrainedConfig
File ~\anaconda3\envs\pygpu\lib\site-packages\transformers\activations_tf.py:22
21 try:
—> 22 import tf_keras as keras
23 except (ModuleNotFoundError, ImportError):
File ~\anaconda3\envs\pygpu\lib\site-packages\tf_keras_init_.py:3
1 “”“AUTOGENERATED. DO NOT EDIT.”“”
----> 3 from tf_keras import internal
4 from tf_keras import activations
File ~\anaconda3\envs\pygpu\lib\site-packages\tf_keras_internal__init_.py:3
1 “”“AUTOGENERATED. DO NOT EDIT.”“”
----> 3 from tf_keras.internal import backend
4 from tf_keras.internal import layers
File ~\anaconda3\envs\pygpu\lib\site-packages\tf_keras_internal_\backend_init_.py:3
1 “”“AUTOGENERATED. DO NOT EDIT.”“”
----> 3 from tf_keras.src.backend import _initialize_variables as initialize_variables
4 from tf_keras.src.backend import track_variable
File ~\anaconda3\envs\pygpu\lib\site-packages\tf_keras\src_init_.py:21
15 “”“Implementation of the TF-Keras API, the high-level API of TensorFlow.
16
17 Detailed documentation and user guides are available at
18 keras.io.
19 “””
—> 21 from tf_keras.src import applications
22 from tf_keras.src import distribute
File ~\anaconda3\envs\pygpu\lib\site-packages\tf_keras\src\applications_init_.py:18
15 “”“Keras Applications are premade architectures with pre-trained weights.”“”
—> 18 from tf_keras.src.applications.convnext import ConvNeXtBase
19 from tf_keras.src.applications.convnext import ConvNeXtLarge
File ~\anaconda3\envs\pygpu\lib\site-packages\tf_keras\src\applications\convnext.py:28
26 import tensorflow.compat.v2 as tf
—> 28 from tf_keras.src import backend
29 from tf_keras.src import initializers
File ~\anaconda3\envs\pygpu\lib\site-packages\tf_keras\src\backend.py:35
34 from tf_keras.src.dtensor import dtensor_api as dtensor
—> 35 from tf_keras.src.engine import keras_tensor
36 from tf_keras.src.utils import control_flow_util
File ~\anaconda3\envs\pygpu\lib\site-packages\tf_keras\src\engine\keras_tensor.py:19
17 import tensorflow.compat.v2 as tf
—> 19 from tf_keras.src.utils import object_identity
21 # isort: off
File ~\anaconda3\envs\pygpu\lib\site-packages\tf_keras\src\utils_init_.py:53
52 # Preprocessing utils
—> 53 from tf_keras.src.utils.feature_space import FeatureSpace
55 # Internal
File ~\anaconda3\envs\pygpu\lib\site-packages\tf_keras\src\utils\feature_space.py:20
19 from tf_keras.src import backend
—> 20 from tf_keras.src.engine import base_layer
21 from tf_keras.src.saving import saving_lib
File ~\anaconda3\envs\pygpu\lib\site-packages\tf_keras\src\engine\base_layer.py:35
34 from tf_keras.src import regularizers
—> 35 from tf_keras.src.dtensor import lazy_variable
36 from tf_keras.src.engine import base_layer_utils
File ~\anaconda3\envs\pygpu\lib\site-packages\tf_keras\src\dtensor\lazy_variable.py:23
22 from tensorflow.python.framework import ops
—> 23 from tensorflow.python.framework import tensor
24 from tensorflow.python.ops import gen_resource_variable_ops
File ~\AppData\Roaming\Python\Python310\site-packages\tensorflow\python\framework\tensor.py:50
47 from tensorflow.python.util.tf_export import tf_export
—> 50 _tensor_equality_api_usage_gauge = monitoring.BoolGauge(
51 “/tensorflow/api/enable_tensor_equality”,
52 “Whether ops.enable_tensor_equality() is called.”)
55 def _override_helper(clazz_object, operator, func):
File ~\AppData\Roaming\Python\Python310\site-packages\tensorflow\python\eager\monitoring.py:356, in BoolGauge.init(self, name, description, *labels)
349 “”“Creates a new BoolGauge.
350
351 Args:
(…)
354 *labels: The label list of the new metric.
355 “””
→ 356 super(BoolGauge, self).init(‘BoolGauge’, _bool_gauge_methods,
357 len(labels), name, description, *labels)
File ~\AppData\Roaming\Python\Python310\site-packages\tensorflow\python\eager\monitoring.py:131, in Metric.init(self, metric_name, metric_methods, label_length, *args)
128 raise ValueError(‘Cannot create {} metric with label >= {}’.format(
129 self._metric_name, len(self._metric_methods)))
→ 131 self._metric = self._metric_methods[self._label_length].create(*args)
AlreadyExistsError: Another metric with the same name already exists.
The above exception was the direct cause of the following exception:
RuntimeError Traceback (most recent call last)
File ~\anaconda3\envs\pygpu\lib\site-packages\transformers\utils\import_utils.py:1793, in _LazyModule._get_module(self, module_name)
1792 try:
→ 1793 return importlib.import_module(“.” + module_name, self.name)
1794 except Exception as e:
File ~\anaconda3\envs\pygpu\lib\importlib_init_.py:126, in import_module(name, package)
125 level += 1
→ 126 return _bootstrap._gcd_import(name[level:], package, level)
File :1050, in _gcd_import(name, package, level)
File :1027, in find_and_load(name, import)
File :1006, in find_and_load_unlocked(name, import)
File :688, in _load_unlocked(spec)
File :883, in exec_module(self, module)
File :241, in _call_with_frames_removed(f, *args, **kwds)
File ~\anaconda3\envs\pygpu\lib\site-packages\transformers\integrations\integration_utils.py:36
34 import packaging.version
—> 36 from … import PreTrainedModel, TFPreTrainedModel
37 from … import version as version
File :1075, in handle_fromlist(module, fromlist, import, recursive)
File ~\anaconda3\envs\pygpu\lib\site-packages\transformers\utils\import_utils.py:1781, in _LazyModule.getattr(self, name)
1780 elif name in self._class_to_module.keys():
→ 1781 module = self._get_module(self._class_to_module[name])
1782 value = getattr(module, name)
File ~\anaconda3\envs\pygpu\lib\site-packages\transformers\utils\import_utils.py:1795, in _LazyModule._get_module(self, module_name)
1794 except Exception as e:
→ 1795 raise RuntimeError(
1796 f"Failed to import {self.name}.{module_name} because of the following error (look up to see its"
1797 f" traceback):\n{e}"
1798 ) from e
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.
The above exception was the direct cause of the following exception:
RuntimeError Traceback (most recent call last)
Cell In[27], line 8
5 gradient_accumulation_steps = 1
6 num_train_epochs = 10
----> 8 training_args = TrainingArguments(
9 f"{model_name}-finetuned-gtzan",
10 eval_strategy=“epoch”,
11 save_strategy=“epoch”,
12 learning_rate=5e-5,
13 warmup_ratio=0.1,
14 logging_steps=5,
15 metric_for_best_model=“accuracy”,
16 fp16=True,
17 )
File :134, in init(self, output_dir, overwrite_output_dir, do_train, do_eval, do_predict, eval_strategy, prediction_loss_only, per_device_train_batch_size, per_device_eval_batch_size, per_gpu_train_batch_size, per_gpu_eval_batch_size, gradient_accumulation_steps, eval_accumulation_steps, eval_delay, torch_empty_cache_steps, learning_rate, weight_decay, adam_beta1, adam_beta2, adam_epsilon, max_grad_norm, num_train_epochs, max_steps, lr_scheduler_type, lr_scheduler_kwargs, warmup_ratio, warmup_steps, log_level, log_level_replica, log_on_each_node, logging_dir, logging_strategy, logging_first_step, logging_steps, logging_nan_inf_filter, save_strategy, save_steps, save_total_limit, save_safetensors, save_on_each_node, save_only_model, restore_callback_states_from_checkpoint, no_cuda, use_cpu, use_mps_device, seed, data_seed, jit_mode_eval, use_ipex, bf16, fp16, fp16_opt_level, half_precision_backend, bf16_full_eval, fp16_full_eval, tf32, local_rank, ddp_backend, tpu_num_cores, tpu_metrics_debug, debug, dataloader_drop_last, eval_steps, dataloader_num_workers, dataloader_prefetch_factor, past_index, run_name, disable_tqdm, remove_unused_columns, label_names, load_best_model_at_end, metric_for_best_model, greater_is_better, ignore_data_skip, fsdp, fsdp_min_num_params, fsdp_config, fsdp_transformer_layer_cls_to_wrap, accelerator_config, deepspeed, label_smoothing_factor, optim, optim_args, adafactor, group_by_length, length_column_name, report_to, ddp_find_unused_parameters, ddp_bucket_cap_mb, ddp_broadcast_buffers, dataloader_pin_memory, dataloader_persistent_workers, skip_memory_metrics, use_legacy_prediction_loop, push_to_hub, resume_from_checkpoint, hub_model_id, hub_strategy, hub_token, hub_private_repo, hub_always_push, gradient_checkpointing, gradient_checkpointing_kwargs, include_inputs_for_metrics, include_for_metrics, eval_do_concat_batches, fp16_backend, evaluation_strategy, push_to_hub_model_id, push_to_hub_organization, push_to_hub_token, mp_parameters, auto_find_batch_size, full_determinism, torchdynamo, ray_scope, ddp_timeout, torch_compile, torch_compile_backend, torch_compile_mode, dispatch_batches, split_batches, include_tokens_per_second, include_num_input_tokens_seen, neftune_noise_alpha, optim_target_modules, batch_eval_metrics, eval_on_start, use_liger_kernel, eval_use_gather_object, average_tokens_across_devices)
File ~\anaconda3\envs\pygpu\lib\site-packages\transformers\training_args.py:1859, in TrainingArguments.post_init(self)
1856 self.report_to = “all”
1857 if self.report_to == “all” or self.report_to == [“all”]:
1858 # Import at runtime to avoid a circular import.
→ 1859 from .integrations import get_available_reporting_integrations
1861 self.report_to = get_available_reporting_integrations()
1863 if “codecarbon” in self.report_to and torch.version.hip:
File :1075, in handle_fromlist(module, fromlist, import, recursive)
File ~\anaconda3\envs\pygpu\lib\site-packages\transformers\utils\import_utils.py:1781, in _LazyModule.getattr(self, name)
1779 value = Placeholder
1780 elif name in self._class_to_module.keys():
→ 1781 module = self._get_module(self._class_to_module[name])
1782 value = getattr(module, name)
1783 elif name in self._modules:
File ~\anaconda3\envs\pygpu\lib\site-packages\transformers\utils\import_utils.py:1795, in _LazyModule._get_module(self, module_name)
1793 return importlib.import_module(“.” + module_name, self.name)
1794 except Exception as e:
→ 1795 raise RuntimeError(
1796 f"Failed to import {self.name}.{module_name} because of the following error (look up to see its"
1797 f" traceback):\n{e}"
1798 ) from e
RuntimeError: Failed to import transformers.integrations.integration_utils 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.
============================
Lots of messages output here, but not much solution I can find in the google, anyone knows what’s wrong?