Issue with transformer version 2.11.0 with pip3 install rasa[transformers]

Want to report what I think is an issue. Please confirm and not sure if reported.

  1. I used the code pip3 install rasa[transformers] to install transformers.
  2. This installs transformers version 2.11.0.
  3. When I run rasa run actions, I get this error

ImportError: cannot import name 'AutoModelWithLMHead' from 'transformers'

The one way I could solved this is by upgraded transformers to 4.0.0, which is the latest I see on huggingface.co. I’m not sure if this is the right way to solve this problem, but I noticed it and this maybe helpful to others.

Hi @sparklie3, could you share your config? And maybe part of your actions, if you think they are relevant?

From my actions, I’m just doing this

line 1: from transformers import pipeline, AutoModelWithLMHead, AutoTokenizer line 47: model = AutoModelWithLMHead.from_pretrained("gpt2") and I use the model later.

My config.yml (don’t think this matters, but sharing)

language: en

pipeline:

- name: WhitespaceTokenizer

  intent_tokenization_flag: true

  intent_split_symbol: +

- name: CountVectorsFeaturizer

  analyzer: char_wb

  min_ngram: 1

  max_ngram: 4

- name: DIETClassifier

  epochs: 100

- name: "MitieNLP"

  model: "data/total_word_feature_extractor.dat"  

- name: "MitieEntityExtractor"

- name: "SpacyNLP"

  model: "en_core_web_md"

  # when retrieving word vectors, this will decide if the casing

  # of the word is relevant. E.g. `hello` and `Hello` will

  # retrieve the same vector, if set to `False`. For some

  # applications and models it makes sense to differentiate

  # between these two words, therefore setting this to `True`.

- name: "SpacyEntityExtractor"

  # dimensions to extract

  dimensions: ["PERSON"]

  case_sensitive: False

- name: "DucklingEntityExtractor"

  # url of the running duckling server

  url: "http://localhost:8000"

  # dimensions to extract

  dimensions: ["time", "number", "amount-of-money"]

  # allows you to configure the locale, by default the language is used

  locale: "en_US"

  # if not set the default timezone of Duckling is going to be used

  # needed to calculate dates from relative expressions like "tomorrow"

  timezone: "Americas/New_York"

  # Timeout for receiving response from http url of the running duckling server

  # if not set the default timeout of duckling http url is set to 3 seconds.

  timeout : 3  

- name: RegexFeaturizer

- name: LexicalSyntacticFeaturizer

- name: EntitySynonymMapper

# - name: ResponseSelector

#   retrieval_intent: career_exploration

#   epochs: 100

# - name: HFTransformersNLP

#   model_name: gpt2

#   model_weights: gpt2

#   cache_dir:

policies:

- name: MemoizationPolicy

- name: TEDPolicy

  max_history: 1

  epochs: 100

- name: RulePolicy

I see, I thought you were using the HFTransformersNLP component.

It looks like this is just a version issue, as it seems transformers 2.11.0 does not have AutoModelWithLMHead (see docs here). We have not yet updated the dependency for rasa, so you may get unexpected behaviour if you are using transformers 4.0.0 with our transformers-related components (ex. LanguageModelFeaturizer).

I think since you are using the models in your actions you should be fine unless you decide to use these components. However, if you want to be safe, I would recommend you figure out the correct model rather than using the Auto- classes. You can download the correct Tokenizer and LanguageModel for gpt2 (probably GPT2Tokenizer and GPT2LMHeadModel) using from_pretrained

I was/am using the HFTransformersNLP component. I had followed the instructions and installed pip3 install rasa[transformers] and in my config name: HFTransformersNLP That’s what was causing the error, as you described.

I see, I just noticed only now the doc2.0 says

The HFTransformersNLP is deprecated and will be removed in a future release. The LanguageModelFeaturizer now implements its behavior.

I’ll read up on your LanguageModelFeaturizer. Because I’m new to the space and sometimes doing copy/paste of code between Rasa and Huggingco docs, it was confusing as I didn’t know if I was doing something wrong.

I’ll take your approach:

figure out the correct model rather than using the Auto- classes. You can download the correct Tokenizer and LanguageModel for gpt2 (probably GPT2Tokenizer and GPT2LMHeadModel ) using from_pretrained

I’m not certain I understand the difference between using what I’m doing versus say, using LanguageModelFeaturizer from Rasa. Not sure this makes sense.

I’m not certain I understand the difference between using what I’m doing versus say, using LanguageModelFeaturizer from Rasa. Not sure this makes sense.

I can see how it’s a little confusing. Let me try to explain:

When you use LanguageModelFeaturizer (or the deprecated HFTransformersNLP, or the deprecated LanguageModelTokenizer) you’re using code that we’ve written and tested for transformers version ">=2.4,<2.12". That’s why I recommend you don’t use a different version. (As an aside, we may update this dependency, but it’s still only on our TODO list).

Why I said this:

figure out the correct model rather than using the Auto- classes.

Your original problem is because you were trying to use AutoModelWithLMHead and AutoTokenizer (features that come after the rasa-compatible transformers version ">=2.4,<2.12"). That’s why updating solved the problem.

I’m suggesting you can get around this by not using AutoModelWithLMHead and AutoTokenizer , and instead figuring out which models to use. Then you can downgrade back to a rasa-compatible version of transformers, but still keep your custom code in actions.

Does that clear things up?

1 Like

Thank you so much. BTW Happy holidays!

1 Like

You’re welcome! And thank you, happy holidays to you as well!