guillaume-be / rust-bert

Rust native ready-to-use NLP pipelines and transformer-based models (BERT, DistilBERT, GPT2,...)
https://docs.rs/crate/rust-bert
Apache License 2.0
2.67k stars 216 forks source link

Error while porting model `sentence-transformers/multi-qa-distilbert-cos-v1` for Sentence Embeddings #402

Closed pmdyy closed 1 year ago

pmdyy commented 1 year ago

I've been trying to port the Hugging Face's model sentence-transformers/multi-qa-distilbert-cos-v1 using the rust-bert library for the purpose of obtaining Sentence Embeddings. Even though Distilbert is supported, I'm encountering an error.

thread '<unnamed>' panicked at 'called `Result::unwrap()` on an `Err` value: TchError("cannot find the tensor named distilbert.transformer.layer.4.attention.v_lin.weight in resources/multi-qa-distilbert-cos-v1__finetuned_2/rust_model.ot")', src/models/base/player_embedding.rs:33:14
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace

It seems the tensor distilbert.transformer.layer.4.attention.v_lin.weight is not found in the model file. This is surprising as this tensor is usually part of the standard DistilBert model structure.

Steps to reproduce:

  1. Download sentence-transformers/multi-qa-distilbert-cos-v1 from HuggingFace Hub.
  2. Convert pytorch-model.bin using rust-bert's convert_model
  3. Run examples/sentence_embedding_local.rs and changing it to the model in question.

rust-bert version: latest main branch (107fb214d9a891f1eb4d69b71f43b6b1c27b219e) os: Ubuntu 20.04 (focal) [64-bit]

Thanks!