TypeError: __init__() got an unexpected keyword argument 'alignment_layer'

Hello,

I’m getting an error when the model gets evaluated and it try to export.

I believe the only thing I changed since last training (which was working) was to export it has ctranslate2_int8 to save MBs.

Note: If i restart the training, it will restart where it failed and crach again at the next export.

see error:

2022-01-07 23:54:08.210000: I training.py:192] Evaluation result for step 1000: loss = 3.287896 ; perplexity = 26.786436 ; wer = 0.789772
2022-01-07 23:54:08.215000: I training.py:192] Exporting model to gdrive/MyDrive/VGR/PREP/eng-lin/v1/OpenNMT/export/1000 (best wer so far: 0.789772)
Traceback (most recent call last):
  File "/usr/local/bin/onmt-main", line 8, in <module>
    sys.exit(main())
  File "/usr/local/lib/python3.7/dist-packages/opennmt/bin/main.py", line 312, in main
    hvd=hvd,
  File "/usr/local/lib/python3.7/dist-packages/opennmt/runner.py", line 284, in train
    moving_average_decay=train_config.get("moving_average_decay"),
  File "/usr/local/lib/python3.7/dist-packages/opennmt/training.py", line 135, in __call__
    evaluator, step, moving_average=moving_average
  File "/usr/local/lib/python3.7/dist-packages/opennmt/training.py", line 192, in _evaluate
    evaluator(step)
  File "/usr/local/lib/python3.7/dist-packages/opennmt/evaluation.py", line 355, in __call__
    self._maybe_export(step, results)
  File "/usr/local/lib/python3.7/dist-packages/opennmt/evaluation.py", line 384, in _maybe_export
    self._model.export(export_dir, exporter=self._exporter)
  File "/usr/local/lib/python3.7/dist-packages/opennmt/models/model.py", line 406, in export
    exporter.export(self, export_dir)
  File "/usr/local/lib/python3.7/dist-packages/opennmt/utils/exporters.py", line 21, in export
    self._export_model(model, export_dir)
  File "/usr/local/lib/python3.7/dist-packages/opennmt/utils/exporters.py", line 166, in _export_model
    model_spec = model.ctranslate2_spec
  File "/usr/local/lib/python3.7/dist-packages/opennmt/models/transformer.py", line 174, in ctranslate2_spec
    alignment_heads=self._alignment_heads,
TypeError: __init__() got an unexpected keyword argument 'alignment_layer'

Here my training and saving config:

    train:
        save_checkpoints_steps: 500
        batch_type: tokens
        #0 automaticaly find the highest number
        batch_size: 0
        #max_step: 500000
        #single_pass: true
        # (optional) How many checkpoints to keep on disk.
        keep_checkpoint_max: 2
        average_last_checkpoints: 4
        #effective_batch_size: 1
        #maximum number of tokens
        maximum_features_length: 2500
        maximum_labels_length: 2500

    eval:
        steps: 500
        scorers: wer
        export_on_best: wer
        save_eval_predictions: true
        export_format: ctranslate2_int8
        max_exports_to_keep: 2
        early_stopping:
            metric: loss
            steps: 4

Hi,

It seems you partially updated OpenNMT-tf. Try this command:

pip install --upgrade OpenNMT-tf

After trying you suggestion, I was still getting the error. Than I found the issue.

I was running this command:
!pip3 install ctranslate2==2.7.0 #--force-reinstall
because i had issues with the newer version.
This was causing some interferance with my the version of opennmt-tf installed.

I don’t remember why I was forcing that specific version of ctranslate2, I just remember that I was having issue with the lattest… I will wait for the model to be generated then try the latest version of ctranslate2.

The latest version of OpenNMT-tf requires at least version 2.9 of CTranslate2: