Skip to content

Pretrained model seems incompatible with current code #20

@HongchengFan

Description

@HongchengFan

hello,
I downloaded the pretrained model from https://drive.google.com/file/d/10rjaLc4L-sa8QNueJDkHSkajFs-LLjgi/view and placed it at SymLM/checkpoints/pretrained/checkpoint_best.pt

Then I set up the training_evaluation/prediction.sh with:

CHECKPOINT_PATH=checkpoints/pretrained/
DATASET_PATH="data/x64/data_bin"

I ran the prediction script with:

bash training_evaluation/prediction.sh

However, I encountered the following error:

Traceback (most recent call last):
  File "training_evaluation/function_name_prediction.py", line 152, in <module>
    cli_main()
  File "training_evaluation/function_name_prediction.py", line 149, in cli_main
    main(args)
  File "training_evaluation/function_name_prediction.py", line 29, in main
    _main(args)
  File "training_evaluation/function_name_prediction.py", line 59, in _main
    model = FuncNamePred.from_pretrained(
  File "/home/xxx/SymLM/fairseq/models/roberta_mf/function_name_prediction.py", line 200, in from_pretrained
    x = hub_utils.from_pretrained(
  File "/home/xxx/SymLM/fairseq/hub_utils.py", line 71, in from_pretrained
    models, args, task = checkpoint_utils.load_model_ensemble_and_task(
  File "/home/xxx/SymLM/fairseq/checkpoint_utils.py", line 279, in load_model_ensemble_and_task
    state = load_checkpoint_to_cpu(filename, arg_overrides)
  File "/home/xxx/SymLM/fairseq/checkpoint_utils.py", line 210, in load_checkpoint_to_cpu
    setattr(args, arg_name, arg_val)
AttributeError: 'NoneType' object has no attribute 'bpe'

It seems the pretrained model is not compatible with the current code.

I tried to add argument initialization in def load_checkpoint_to_cpu(path, arg_overrides=None): in SymLM/fairseq/checkpoint_utils.py as follows:

if not state["args"]: 
        from types import SimpleNamespace
        state["args"] = SimpleNamespace(
            arch="roberta_mf",
            task="func_name_pred",
            criterion="func_name_pred",
            num_external=948,   
            external_emb="embedding",
            num_calls=1,     
            num_classes=3069,     
            max_sentences=8,    
            gen_subset="test", 
        )

But then I still encounter missing attributes like seed.

I set up seed=42 and encountered a new traceback:

Traceback (most recent call last):
  File "training_evaluation/function_name_prediction.py", line 152, in <module>
    cli_main()
  File "training_evaluation/function_name_prediction.py", line 149, in cli_main
    main(args)
  File "training_evaluation/function_name_prediction.py", line 29, in main
    _main(args)
  File "training_evaluation/function_name_prediction.py", line 59, in _main
    model = FuncNamePred.from_pretrained(
  File "/home/xxx/SymLM/fairseq/models/roberta_mf/function_name_prediction.py", line 200, in from_pretrained
    x = hub_utils.from_pretrained(
  File "/home/xxx/SymLM/fairseq/hub_utils.py", line 71, in from_pretrained
    models, args, task = checkpoint_utils.load_model_ensemble_and_task(
  File "/home/xxx/SymLM/fairseq/checkpoint_utils.py", line 281, in load_model_ensemble_and_task
    model.load_state_dict(state["model"], strict=strict, args=args)
  File "/home/xxx/SymLM/fairseq/models/fairseq_model.py", line 93, in load_state_dict
    return super().load_state_dict(new_state_dict, strict)
  File "/home/xxx/anaconda3/envs/csursymlm/lib/python3.8/site-packages/torch/nn/modules/module.py", line 2215, in load_state_dict
    raise RuntimeError('Error(s) in loading state_dict for {}:\n\t{}'.format(
RuntimeError: Error(s) in loading state_dict for RobertaModelMF:
    ......

From my investigation, it seems that the pretrained model checkpoint does not fully match the current codebase (e.g., argument settings, model structure). Could you please confirm whether the provided pretrained model is compatible with the current code, or provide the corresponding code version/args used to generate it?

Thank you!

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions