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

Error loading weights #391

Open
rederyang opened this issue Apr 12, 2024 · 3 comments
Open

Error loading weights #391

rederyang opened this issue Apr 12, 2024 · 3 comments

Comments

@rederyang
Copy link

When I ran this code in the reproducing results colab notebook:

!allennlp evaluate "$pretrained_model_url" "$preprocessed_data_dir/test.tsv" \
    --output-file "$output_dir/test_metrics.jsonl" \
    --cuda-device 0 \
    --predictions-output-file "$output_dir/test_predictions.jsonl" \
    --include-package "seq2rel"

I got this Error:

2024-04-12 10:27:06,782 - INFO - allennlp.common.plugins - Plugin allennlp_models available
2024-04-12 10:27:08,988 - INFO - cached_path - cache of https://github.com/JohnGiorgi/seq2rel/releases/download/pretrained-models/cdr_hints.tar.gz is up-to-date
2024-04-12 10:27:08,989 - INFO - allennlp.models.archival - loading archive file https://github.com/JohnGiorgi/seq2rel/releases/download/pretrained-models/cdr_hints.tar.gz from cache at /root/.allennlp/cache/5d845bebc5887213bab7c90a311e51d6dff9a03fb60648a6498d58be8397166c.82548b1687f75978154d471c6ead95e2dd4d865a01baaba9fa7873d62232ffbe
2024-04-12 10:27:08,990 - INFO - allennlp.models.archival - extracting archive file /root/.allennlp/cache/5d845bebc5887213bab7c90a311e51d6dff9a03fb60648a6498d58be8397166c.82548b1687f75978154d471c6ead95e2dd4d865a01baaba9fa7873d62232ffbe to temp dir /tmp/tmp0mo17roo
2024-04-12 10:27:15,245 - INFO - allennlp.models.archival - removing temporary unarchived model dir at /tmp/tmp0mo17roo
Traceback (most recent call last):
  File "/usr/local/lib/python3.8/site-packages/transformers/configuration_utils.py", line 616, in _get_config_dict
    resolved_config_file = cached_path(
  File "/usr/local/lib/python3.8/site-packages/transformers/utils/hub.py", line 284, in cached_path
    output_path = get_from_cache(
  File "/usr/local/lib/python3.8/site-packages/transformers/utils/hub.py", line 508, in get_from_cache
    raise OSError(
OSError: Distant resource does not have an ETag, we won't be able to reliably ensure reproducibility.

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/usr/local/bin/allennlp", line 8, in <module>
    sys.exit(run())
  File "/usr/local/lib/python3.8/site-packages/allennlp/__main__.py", line 39, in run
    main(prog="allennlp")
  File "/usr/local/lib/python3.8/site-packages/allennlp/commands/__init__.py", line 120, in main
    args.func(args)
  File "/usr/local/lib/python3.8/site-packages/allennlp/commands/evaluate.py", line 135, in evaluate_from_args
    return evaluate_from_archive(
  File "/usr/local/lib/python3.8/site-packages/allennlp/commands/evaluate.py", line 242, in evaluate_from_archive
    archive = load_archive(
  File "/usr/local/lib/python3.8/site-packages/allennlp/models/archival.py", line 232, in load_archive
    dataset_reader, validation_dataset_reader = _load_dataset_readers(
  File "/usr/local/lib/python3.8/site-packages/allennlp/models/archival.py", line 268, in _load_dataset_readers
    dataset_reader = DatasetReader.from_params(
  File "/usr/local/lib/python3.8/site-packages/allennlp/common/from_params.py", line 604, in from_params
    return retyped_subclass.from_params(
  File "/usr/local/lib/python3.8/site-packages/allennlp/common/from_params.py", line 636, in from_params
    kwargs = create_kwargs(constructor_to_inspect, cls, params, **extras)
  File "/usr/local/lib/python3.8/site-packages/allennlp/common/from_params.py", line 206, in create_kwargs
    constructed_arg = pop_and_construct_arg(
  File "/usr/local/lib/python3.8/site-packages/allennlp/common/from_params.py", line 314, in pop_and_construct_arg
    return construct_arg(class_name, name, popped_params, annotation, default, **extras)
  File "/usr/local/lib/python3.8/site-packages/allennlp/common/from_params.py", line 348, in construct_arg
    result = annotation.from_params(params=popped_params, **subextras)
  File "/usr/local/lib/python3.8/site-packages/allennlp/common/from_params.py", line 604, in from_params
    return retyped_subclass.from_params(
  File "/usr/local/lib/python3.8/site-packages/allennlp/common/from_params.py", line 638, in from_params
    return constructor_to_call(**kwargs)  # type: ignore
  File "/usr/local/lib/python3.8/site-packages/allennlp/data/tokenizers/pretrained_transformer_tokenizer.py", line 72, in __init__
    self.tokenizer = cached_transformers.get_tokenizer(
  File "/usr/local/lib/python3.8/site-packages/allennlp/common/cached_transformers.py", line 204, in get_tokenizer
    tokenizer = transformers.AutoTokenizer.from_pretrained(
  File "/usr/local/lib/python3.8/site-packages/transformers/models/auto/tokenization_auto.py", line 547, in from_pretrained
    config = AutoConfig.from_pretrained(
  File "/usr/local/lib/python3.8/site-packages/transformers/models/auto/configuration_auto.py", line 725, in from_pretrained
    config_dict, _ = PretrainedConfig.get_config_dict(pretrained_model_name_or_path, **kwargs)
  File "/usr/local/lib/python3.8/site-packages/transformers/configuration_utils.py", line 561, in get_config_dict
    config_dict, kwargs = cls._get_config_dict(pretrained_model_name_or_path, **kwargs)
  File "/usr/local/lib/python3.8/site-packages/transformers/configuration_utils.py", line 656, in _get_config_dict
    raise EnvironmentError(
OSError: Can't load config for 'microsoft/BiomedNLP-PubMedBERT-base-uncased-abstract-fulltext'. If you were trying to load it from 'https://huggingface.co/models', make sure you don't have a local directory with the same name. Otherwise, make sure 'microsoft/BiomedNLP-PubMedBERT-base-uncased-abstract-fulltext' is the correct path to a directory containing a config.json file

After upgrading to the latest version of transformers(4.39.3), this error is solved, but I got a new error:

2024-04-12 10:30:32,153 - INFO - allennlp.common.plugins - Plugin allennlp_models available
2024-04-12 10:30:34,344 - INFO - cached_path - cache of https://github.com/JohnGiorgi/seq2rel/releases/download/pretrained-models/cdr_hints.tar.gz is up-to-date
2024-04-12 10:30:34,345 - INFO - allennlp.models.archival - loading archive file https://github.com/JohnGiorgi/seq2rel/releases/download/pretrained-models/cdr_hints.tar.gz from cache at /root/.allennlp/cache/5d845bebc5887213bab7c90a311e51d6dff9a03fb60648a6498d58be8397166c.82548b1687f75978154d471c6ead95e2dd4d865a01baaba9fa7873d62232ffbe
2024-04-12 10:30:34,345 - INFO - allennlp.models.archival - extracting archive file /root/.allennlp/cache/5d845bebc5887213bab7c90a311e51d6dff9a03fb60648a6498d58be8397166c.82548b1687f75978154d471c6ead95e2dd4d865a01baaba9fa7873d62232ffbe to temp dir /tmp/tmpq6ecqnkx
2024-04-12 10:30:41,043 - INFO - allennlp.data.vocabulary - Loading token dictionary from /tmp/tmpq6ecqnkx/vocabulary.
2024-04-12 10:30:43,684 - INFO - allennlp.modules.token_embedders.embedding - Loading a model trained before embedding extension was implemented; pass an explicit vocab namespace if you want to extend the vocabulary.
2024-04-12 10:30:44,093 - INFO - allennlp.models.archival - removing temporary unarchived model dir at /tmp/tmpq6ecqnkx
Traceback (most recent call last):
  File "/usr/local/bin/allennlp", line 8, in <module>
    sys.exit(run())
  File "/usr/local/lib/python3.8/site-packages/allennlp/__main__.py", line 39, in run
    main(prog="allennlp")
  File "/usr/local/lib/python3.8/site-packages/allennlp/commands/__init__.py", line 120, in main
    args.func(args)
  File "/usr/local/lib/python3.8/site-packages/allennlp/commands/evaluate.py", line 135, in evaluate_from_args
    return evaluate_from_archive(
  File "/usr/local/lib/python3.8/site-packages/allennlp/commands/evaluate.py", line 242, in evaluate_from_archive
    archive = load_archive(
  File "/usr/local/lib/python3.8/site-packages/allennlp/models/archival.py", line 235, in load_archive
    model = _load_model(config.duplicate(), weights_path, serialization_dir, cuda_device)
  File "/usr/local/lib/python3.8/site-packages/allennlp/models/archival.py", line 279, in _load_model
    return Model.load(
  File "/usr/local/lib/python3.8/site-packages/allennlp/models/model.py", line 438, in load
    return model_class._load(config, serialization_dir, weights_file, cuda_device)
  File "/usr/local/lib/python3.8/site-packages/allennlp/models/model.py", line 380, in _load
    raise RuntimeError(
RuntimeError: Error loading state dict for CopyNetSeq2Rel
	Missing keys: []
	Unexpected keys: ['_source_embedder.token_embedder_tokens.transformer_model.embeddings.position_ids']

Could you please help fix this problem? Thanks for your great work!

@TingheZhang
Copy link

Model name was changed to BiomedNLP-BiomedBERT-base-uncased-abstract-fulltext https://huggingface.co/microsoft/BiomedNLP-BiomedBERT-base-uncased-abstract-fulltext

@rederyang
Copy link
Author

@TingheZhang Thanks.

@JohnGiorgi
Copy link
Owner

JohnGiorgi commented May 27, 2024

Thanks @TingheZhang! @rederxz I have a PR open to fix this on the fly so you don't have to mess with the pre-trained models config files: #392

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

3 participants