nlp-with-transformers / notebooks

Jupyter notebooks for the Natural Language Processing with Transformers book

Home Page:https://transformersbook.com/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Chap 8 notebook: ONNX TypeError: export() got an unexpected keyword argument 'use_external_data_format'

jeromemassot opened this issue · comments

Information

The problem arises in chapter:

  • Introduction
  • Text Classification
  • Transformer Anatomy
  • Multilingual Named Entity Recognition
  • Text Generation
  • Summarization
  • Question Answering
  • [x ] Making Transformers Efficient in Production
  • Dealing with Few to No Labels
  • Training Transformers from Scratch
  • Future Directions

Describe the bug

TypeError: export() got an unexpected keyword argument 'use_external_data_format'
In the notebook from this repository, the same problem has generated a warning not a TypeError.

To Reproduce

Steps to reproduce the behavior:

  1. model_ckpt = "transformersbook/distilbert-base-uncased-distilled-clinc"
  2. onnx_model_path = Path("onnx/model.onnx")
  3. convert( ...

Expected behavior

Facing the same issue, while executing convert()

from transformers.convert_graph_to_onnx import convert

model_ckpt = "transformersbook/distilbert-base-uncased-distilled-clinc"
onnx_model_path = Path("onnx/model.onnx")
convert(framework="pt", model=model_ckpt, tokenizer=tokenizer, output=onnx_model_path, 
        opset=12, pipeline_name="text-classification")

Added stacktrace

ONNX opset version set to: 12
Loading pipeline (model: transformersbook/distilbert-base-uncased-distilled-clinc, tokenizer: PreTrainedTokenizerFast(name_or_path='transformersbook/distilbert-base-uncased-distilled-clinc', vocab_size=30522, model_max_len=512, is_fast=True, padding_side='right', special_tokens={'unk_token': '[UNK]', 'sep_token': '[SEP]', 'pad_token': '[PAD]', 'cls_token': '[CLS]', 'mask_token': '[MASK]'}))
Using framework PyTorch: 1.12.1+cu113
Found input input_ids with shape: {0: 'batch', 1: 'sequence'}
Found input attention_mask with shape: {0: 'batch', 1: 'sequence'}
Found output output_0 with shape: {0: 'batch'}
Ensuring inputs are in correct order
head_mask is not present in the generated input list.
Generated inputs order: ['input_ids', 'attention_mask']
---------------------------------------------------------------------------

TypeError                                 Traceback (most recent call last)
[<ipython-input-68-46e250e62185>](https://localhost:8080/#) in <module>
      5 onnx_model_path = Path("onnx/model.onnx")
      6 convert(framework="pt", model=model_ckpt, tokenizer=tokenizer, output=onnx_model_path, 
----> 7         opset=12, pipeline_name="text-classification")

1 frames
[/usr/local/lib/python3.7/dist-packages/transformers/convert_graph_to_onnx.py](https://localhost:8080/#) in convert_pytorch(nlp, opset, output, use_external_format)
    289             use_external_data_format=use_external_format,
    290             enable_onnx_checker=True,
--> 291             opset_version=opset,
    292         )
    293 

TypeError: export() got an unexpected keyword argument 'use_external_data_format'

Any workarounds?

I am encountering the same exact problem when running the chapter 8 notebook and with the same error message as in cataluna84 msg above while running convert().

Is there a fix or a workaround?