openai / gpt-2-output-dataset

Dataset of GPT-2 outputs for research in detection, biases, and more
MIT License
1.93k stars 548 forks source link

Missing key(s) in state_dict: "roberta.embeddings.position_ids". #47

Closed matteonardelli closed 1 year ago

matteonardelli commented 1 year ago

Hi there, when I try to start the detector (python -m detector.server detector-base.pt), I obtain the error: Missing key(s) in state_dict: "roberta.embeddings.position_ids"..

How can I solve this and play around with the detector? Thanks

Precondition I downloaded (and tried with) both detector-base.pt and detector-large.pt. Either way, I get the same error. I can see that in previous issues, people correctly started the detector, so maybe there is an issue with the .pt files I am downloading.

Full execution log

$ python -m detector.server detector-base.pt

Loading checkpoint from detector-base.pt
Some weights of the model checkpoint at roberta-base were not used when initializing RobertaForSequenceClassification: ['lm_head.dense.weight', 'lm_head.layer_norm.weight', 'lm_head.dense.bias', 'roberta.pooler.dense.bias', 'lm_head.bias', 'lm_head.decoder.weight', 'roberta.pooler.dense.weight', 'lm_head.layer_norm.bias']
- This IS expected if you are initializing RobertaForSequenceClassification from the checkpoint of a model trained on another task or with another architecture (e.g. initializing a BertForSequenceClassification model from a BertForPreTraining model).
- This IS NOT expected if you are initializing RobertaForSequenceClassification from the checkpoint of a model that you expect to be exactly identical (initializing a BertForSequenceClassification model from a BertForSequenceClassification model).
Some weights of RobertaForSequenceClassification were not initialized from the model checkpoint at roberta-base and are newly initialized: ['classifier.dense.bias', 'classifier.out_proj.bias', 'classifier.dense.weight', 'classifier.out_proj.weight']
You should probably TRAIN this model on a down-stream task to be able to use it for predictions and inference.
Traceback (most recent call last):
  File "/opt/anaconda3/envs/detector/lib/python3.9/runpy.py", line 197, in _run_module_as_main
    return _run_code(code, main_globals, None,
  File "/opt/anaconda3/envs/detector/lib/python3.9/runpy.py", line 87, in _run_code
    exec(code, run_globals)
  File "/Users/user/workspace/stanford/gpt-2-output-dataset/detector/server.py", line 120, in <module>
    fire.Fire(main)
  File "/opt/anaconda3/envs/detector/lib/python3.9/site-packages/fire/core.py", line 141, in Fire
    component_trace = _Fire(component, args, parsed_flag_args, context, name)
  File "/opt/anaconda3/envs/detector/lib/python3.9/site-packages/fire/core.py", line 475, in _Fire
    component, remaining_args = _CallAndUpdateTrace(
  File "/opt/anaconda3/envs/detector/lib/python3.9/site-packages/fire/core.py", line 691, in _CallAndUpdateTrace
    component = fn(*varargs, **kwargs)
  File "/Users/user/workspace/stanford/gpt-2-output-dataset/detector/server.py", line 89, in main
    model.load_state_dict(data['model_state_dict'])
  File "/opt/anaconda3/envs/detector/lib/python3.9/site-packages/torch/nn/modules/module.py", line 1604, in load_state_dict
    raise RuntimeError('Error(s) in loading state_dict for {}:\n\t{}'.format(
RuntimeError: Error(s) in loading state_dict for RobertaForSequenceClassification:
    Missing key(s) in state_dict: "roberta.embeddings.position_ids".
    Unexpected key(s) in state_dict: "roberta.pooler.dense.weight", "roberta.pooler.dense.bias".
jongwook commented 1 year ago

Hi, the code is pretty old at this point and you will need to pin an older version of transformers (because I didn't put an upper bound in requirements.txt). In #35, there are some reports that installing transformers==2.9.1 fixes the problem, and 2.1.1 was the latest version when the model was published in Nov 2019. Will close this in as duplicate of #35.