Bug when trying to run examples in tensorflow text-classification
OS Specifics
`transformers` version: 4.35.2
- Platform: Linux-6.5.0-25-generic-x86_64-with-glibc2.35
- Python version: 3.10.12
- Huggingface_hub version: 0.19.4
- Safetensors version: 0.4.0
- Accelerate version: not installed
- Accelerate config: not found
- PyTorch version (GPU?): not installed (NA)
- Tensorflow version (GPU?): 2.15.0 (True)
- Flax version (CPU?/GPU?/TPU?): not installed (NA)
- Jax version: not installed
- JaxLib version: not installed
- Using GPU in script?: <fill in>
- Using distributed or parallel set-up in script?: <fill in>
Information
[ ] The official example scripts
[ ] My own modified scripts
Tasks
[ ] An officially supported task in the examples folder (such as GLUE/SQuAD, ...)
[ ] My own task or dataset (give details below)
Reproduction
While I was trying out examples in the transformers source code, the examples directory, I experienced an issue while I was trying to run the example tensorflow.textclassification.run_text_classification - the bash command line as: python run_text_classification.py --model_name_or_path distilbert-base-cased --train_file training_data.json --validation_file validation_data.json --output_dir output, as per the testclassifiication.README.md instructions.
Here is the error:
traceback (most recent call last):
File "/home/humbulani/transformers-main/examples/tensorflow/text-classification/run_text_classification.py", line 600, in <module>
main()
File "/home/humbulani/transformers-main/examples/tensorflow/text-classification/run_text_classification.py", line 527, in main
model.compile(optimizer=optimizer, metrics=metrics) # Removed optimizer=optimizer positional argument
File "/home/humbulani/django/env/lib/python3.10/site-packages/transformers/modeling_tf_utils.py", line 1531, in compile
super().compile(
File "/home/humbulani/django/env/lib/python3.10/site-packages/keras/src/utils/traceback_utils.py", line 70, in error_handler
raise e.with_traceback(filtered_tb) from None
File "/home/humbulani/django/env/lib/python3.10/site-packages/keras/src/optimizers/__init__.py", line 329, in get
raise ValueError(
ValueError: Could not interpret optimizer identifier: None
I then decided to read through the source code starting from the run_text_classification.main. This function calls compile.model which has a signature: model.compile(optimizer=optimizer, metrics=metrics). This function accepts optimizer as one of the keyword arguments, and depending of the below block code optimizer maybe None:
if the else part is executed and optimizer is set to None, it the overrides the assignment of the optimzer, which is equal to "rmsprop"' by default, argument in the function:keras.src.engine.training.compile` and its signature is given by:
This then leads to all sorts of issues. I then decided to assign optimizer in the else part condition to: optimizer = None or "rmsprop" and the code worked perfectly. I'm sure there could be better fix than this hack which maybe submitted with a PR id this proves to be a genuine issue.
The Stacktrace for function calls:
/home/humbulani/transformers-main/examples/tensorflow/text-classification/run_text_classification.py(595)<module>()
-> main()
/home/humbulani/transformers-main/examples/tensorflow/text-classification/run_text_classification.py(522)main()
-> model.compile(optimizer=optimizer, metrics=metrics)
/home/humbulani/django/env/lib/python3.10/site-packages/transformers/modeling_tf_utils.py(1531)compile()
-> super().compile(
/home/humbulani/django/env/lib/python3.10/site-packages/keras/src/utils/traceback_utils.py(65)error_handler()
-> return fn(*args, **kwargs)
/home/humbulani/django/env/lib/python3.10/site-packages/keras/src/engine/training.py(784)compile()
-> self.optimizer = self._get_optimizer(optimizer)
/home/humbulani/django/env/lib/python3.10/site-packages/keras/src/engine/training.py(848)_get_optimizer()
-> return tf.nest.map_structure(_get_single_optimizer, optimizer)
/home/humbulani/django/env/lib/python3.10/site-packages/tensorflow/python/util/nest.py(631)map_structure()
-> return nest_util.map_structure(
/home/humbulani/django/env/lib/python3.10/site-packages/tensorflow/python/util/nest_util.py(1066)map_structure()
-> return _tf_core_map_structure(func, *structure, **kwargs)
/home/humbulani/django/env/lib/python3.10/site-packages/tensorflow/python/util/nest_util.py(1106)_tf_core_map_structure()
-> [func(*x) for x in entries],
/home/humbulani/django/env/lib/python3.10/site-packages/tensorflow/python/util/nest_util.py(1106)<listcomp>()
-> [func(*x) for x in entries],
/home/humbulani/django/env/lib/python3.10/site-packages/keras/src/engine/training.py(839)_get_single_optimizer()
-> opt = optimizers.get(opt)
> /home/humbulani/django/env/lib/python3.10/site-packages/keras/src/optimizers/__init__.py(277)get()
-> """Retrieves a Keras Optimizer instance.
Bug when trying to run examples in tensorflow text-classification
OS Specifics
Information
Tasks
Reproduction
While I was trying out examples in the transformers source code, the examples directory, I experienced an issue while I was trying to run the example tensorflow.textclassification.run_text_classification - the bash command line as:
python run_text_classification.py --model_name_or_path distilbert-base-cased --train_file training_data.json --validation_file validation_data.json --output_dir output
, as per the testclassifiication.README.md instructions.Here is the error:
I then decided to read through the source code starting from the run_text_classification.main. This function calls compile.model which has a signature:
model.compile(optimizer=optimizer, metrics=metrics)
. This function accepts optimizer as one of the keyword arguments, and depending of the below block code optimizer maybe None:if the else part is executed and optimizer is set to None, it the overrides the assignment of the optimzer, which is equal to
"rmsprop"' by default, argument in the function:
keras.src.engine.training.compile` and its signature is given by:This then leads to all sorts of issues. I then decided to assign optimizer in the else part condition to: optimizer = None or "rmsprop" and the code worked perfectly. I'm sure there could be better fix than this hack which maybe submitted with a PR id this proves to be a genuine issue.
The Stacktrace for function calls:
Environement