Skip to content

Issue with saving and inference on a FastFit model I trained #25

@shervin0

Description

@shervin0

I have installed fastfit 1.2.1 from source.
I am exactly following the example on the fastfit read-me page (https://github.com/IBM/fastfit).
I can train the model, but I cannot save it. I try this to save the model:
model.save_pretrained("fast-fit")
Here's the error message when trying to save the model:
AssertionError: Config has to be initialized with encoder config

And here's where the error happens:

File ~/anaconda3/envs/pytorch_p310/lib/python3.10/site-packages/fastfit/modeling.py:259, in FastFitConfig.init(self, all_docs, num_repeats, rep_tokens, inference_type, clf_level, init_freeze, clf_dim, proj_dim, similarity_metric, encoder_dropout, encoding_type, clf_query, clf_doc, mask_zeros_in_query, mask_zeros_in_doc, sim_factor, clf_factor, mlm_factor, mask_prob, pretrain_mode, length_norm, scores_temp, inference_direction, symetric_mode, length_norm_at_inference, **kwargs)

    256 self.length_norm_at_inference = length_norm_at_inference
    258 assert inference_direction in ["query", "doc", "both"]
--> 259 assert "encoder" in kwargs, "Config has to be initialized with encoder config"
    260 encoder_config = kwargs.pop("encoder")
    261 encoder_model_type = encoder_config.pop("model_type")

Also, trying to use the trained model for inference, I use this code:

from transformers import AutoTokenizer, pipeline

tokenizer = AutoTokenizer.from_pretrained("sentence-transformers/paraphrase-mpnet-base-v2")
classifier = pipeline("text-classification", model=model, tokenizer=tokenizer)
print(classifier("I love this package!"))

And get this error on the last line:

TypeError: FastFitTrainable.forward() got an unexpected keyword argument 'input_ids'

Am I doing something incorrectly?
Thanks.

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