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


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] Evaluation result for step 1000: loss = 3.287896 ; perplexity = 26.786436 ; wer = 0.789772
2022-01-07 23:54:08.215000: I] 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>
  File "/usr/local/lib/python3.7/dist-packages/opennmt/bin/", line 312, in main
  File "/usr/local/lib/python3.7/dist-packages/opennmt/", line 284, in train
  File "/usr/local/lib/python3.7/dist-packages/opennmt/", line 135, in __call__
    evaluator, step, moving_average=moving_average
  File "/usr/local/lib/python3.7/dist-packages/opennmt/", line 192, in _evaluate
  File "/usr/local/lib/python3.7/dist-packages/opennmt/", line 355, in __call__
    self._maybe_export(step, results)
  File "/usr/local/lib/python3.7/dist-packages/opennmt/", line 384, in _maybe_export
    self._model.export(export_dir, exporter=self._exporter)
  File "/usr/local/lib/python3.7/dist-packages/opennmt/models/", line 406, in export
    exporter.export(self, export_dir)
  File "/usr/local/lib/python3.7/dist-packages/opennmt/utils/", line 21, in export
    self._export_model(model, export_dir)
  File "/usr/local/lib/python3.7/dist-packages/opennmt/utils/", line 166, in _export_model
    model_spec = model.ctranslate2_spec
  File "/usr/local/lib/python3.7/dist-packages/opennmt/models/", line 174, in ctranslate2_spec
TypeError: __init__() got an unexpected keyword argument 'alignment_layer'

Here my training and saving config:

        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

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


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: