nomic-ai / contrastors

Train Models Contrastively in Pytorch
Apache License 2.0
512 stars 37 forks source link

Incompatible Keys Error when loading pre-trained model #20

Closed Linhvjc closed 5 months ago

Linhvjc commented 6 months ago

I have modified config to using my pretrained instead of using model nomic-ai/nomic-bert-2048, my config is:

pretrained: "/home/link/spaces/contrastors/src/contrastors/ckpts/mlm-trainer/final_model"
# model_name: "nomic-ai/nomic-bert-2048"

But when I load my pretrained model, It have some error about Incompatible Keys Error, I found some issue in your code, below is the details: My pretrained model confis is

{
  "activation_function": "swiglu",
  "architectures": [
    "NomicBertForPreTraining"
  ],
  "attn_pdrop": 0.0,
  "bos_token_id": null,
  "causal": false,
  "dense_seq_output": true,
  "embd_pdrop": 0.1,
  "eos_token_id": null,
  "fused_bias_fc": true,
  "fused_dropout_add_ln": true,
  "initializer_range": 0.02,
  "layer_norm_epsilon": 1e-12,
  "max_trained_positions": 2048,
  "mlp_fc1_bias": false,
  "mlp_fc2_bias": false,
  "model_type": "nomic_bert",
  "n_embd": 768,
  "n_head": 12,
  "n_inner": 3072,
  "n_layer": 12,
  "n_positions": 128,
  "pad_vocab_size_multiple": 64,
  "parallel_block": false,
  "parallel_block_tied_norm": false,
  "prenorm": false,
  "qkv_proj_bias": false,
  "reorder_and_upcast_attn": false,
  "resid_pdrop": 0.1,
  "rotary_emb_base": 1000,
  "rotary_emb_fraction": 1.0,
  "rotary_emb_interleaved": false,
  "rotary_emb_scale_base": null,
  "rotary_scaling_factor": null,
  "scale_attn_by_inverse_layer_idx": false,
  "scale_attn_weights": true,
  "summary_activation": null,
  "summary_first_dropout": 0.1,
  "summary_proj_to_labels": true,
  "summary_type": "cls_index",
  "summary_use_proj": true,
  "torch_dtype": "float32",
  "transformers_version": "4.38.2",
  "type_vocab_size": 2,
  "use_cache": true,
  "use_flash_attn": true,
  "use_rms_norm": false,
  "use_xentropy": true,
  "vocab_size": 62016
}

In this model config have not model_name. So when get config using BiEncoderConfig, the default model_name is EleutherAI/pythia-1b is set.

My question is why model_name is EleutherAI/pythia-1b ?. I hope you response soon. Thanks

zanussbaum commented 6 months ago

Hi does it work if you uncomment model_name?