Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TypeError: __init__() got an unexpected keyword argument 'gradient_checkpointing' #57

Closed
azouiaymen opened this issue Aug 20, 2021 · 1 comment

Comments

@azouiaymen
Copy link

i am unable to load a checkpoint into my abstractive model , i don't know why . i am using trasnformersum env with conda :

channels:
    - conda-forge
    - pytorch
dependencies:
    - pytorch
    - scikit-learn
    - tensorboard
    - spacy
    - sphinx
    - pyarrow
    - pre-commit
    - pip
    - pip:
      - pytorch_lightning
      - transformers==3.0.2
      - torch_optimizer
      - wandb
      - rouge-score
      - packaging
      - datasets
      - gradio

i use this commande python3 predict_abst.py , here's a what my code looks like :

import glob
import os
import sys

sys.path.insert(0, os.path.abspath("./src"))
from abstractive import AbstractiveSummarizer 

def summarize_text(text, model_choice):
    summarizer = AbstractiveSummarizer.load_from_checkpoint(model_choice)
    # summarizer = AbstractiveSummarizer.load_from_checkpoint(model_choice)
    return summarizer.predict(text)

input = """Johannes Gutenberg (1398 – 1468) was a German goldsmith and publisher who introduced printing to Europe. His introduction of mechanical movable type printing to Europe started the Printing Revolution and is widely regarded as the most important event of the modern period. It played a key role in the scientific revolution and laid the basis for the modern knowledge-based economy and the spread of learning to the masses.

Gutenberg many contributions to printing are: the invention of a process for mass-producing movable type, the use of oil-based ink for printing books, adjustable molds, and the use of a wooden printing press. His truly epochal invention was the combination of these elements into a practical system that allowed the mass production of printed books and was economically viable for printers and readers alike.

In Renaissance Europe, the arrival of mechanical movable type printing introduced the era of mass communication which permanently altered the structure of society. The relatively unrestricted circulation of information—including revolutionary ideas—transcended borders, and captured the masses in the Reformation. The sharp increase in literacy broke the monopoly of the literate elite on education and learning and bolstered the emerging middle class.t """

print(summarize_text(input,"./models/epoch=18-step=2678.ckpt"))```
==============================================================
and i am getting this error :
```python
Traceback (most recent call last):
  File "predict_abst.py", line 19, in <module>
    print(summarize_text(input,"./models/epoch=18-step=2678.ckpt"))
  File "predict_abst.py", line 9, in summarize_text
    summarizer = AbstractiveSummarizer.load_from_checkpoint(model_choice)
  File "/opt/conda/envs/transformersum/lib/python3.6/site-packages/pytorch_lightning/core/saving.py", line 153, in load_from_checkpoint
    model = cls._load_model_state(checkpoint, strict=strict, **kwargs)
  File "/opt/conda/envs/transformersum/lib/python3.6/site-packages/pytorch_lightning/core/saving.py", line 195, in _load_model_state
    model = cls(**_cls_kwargs)
  File "/root/project/transformersum/src/abstractive.py", line 113, in __init__
    gradient_checkpointing=self.hparams.gradient_checkpointing,
  File "/opt/conda/envs/transformersum/lib/python3.6/site-packages/transformers/modeling_auto.py", line 1213, in from_pretrained
    return model_class.from_pretrained(pretrained_model_name_or_path, *model_args, config=config, **kwargs)
  File "/opt/conda/envs/transformersum/lib/python3.6/site-packages/transformers/modeling_utils.py", line 672, in from_pretrained
    model = cls(config, *model_args, **model_kwargs)
TypeError: __init__() got an unexpected keyword argument 'gradient_checkpointing'```
@HHousen
Copy link
Owner

HHousen commented Aug 23, 2021

Interesting. Please try updating to the latest version of transformers. In v3.0.2, gradient_checkpointing was not an option. As you can see it does not appear in the configuration_bart.py file. However, in the latest version, gradient_checkpointing is present.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants