Skip to content
This repository has been archived by the owner on Sep 13, 2023. It is now read-only.

MLEM-loaded model performs consistently worse #641

Open
rocco-fortuna opened this issue Mar 13, 2023 · 4 comments
Open

MLEM-loaded model performs consistently worse #641

rocco-fortuna opened this issue Mar 13, 2023 · 4 comments
Labels
bug Something isn't working ml-framework ML Framework support serialization Dumping and loading Python objects

Comments

@rocco-fortuna
Copy link

rocco-fortuna commented Mar 13, 2023

I have a Pytorch text classification model I cannot disclose the architecture of. Whenever the model is loaded with the relative library, it consistently performs slightly better than the model saved and then loaded with MLEM.
As detailed on the Discord discussion with @aguschin:

It's a Pytorch sequence classification model. Ran the eval four times each:

  1. the original model
  2. the mlem_model saved and loaded with:
# load the model with Pytorch model class
model = MyModel.from_pretrained('./model_path')

# save
from mlem.api import save
save(model, "./checkpoints/v070_mlem")

#
from mlem.api import load
mlem_model = load("./checkpoints/v070_mlem")

And did eval 4 times each on 5k samples, getting the accuracies:

  1. original:
  • 0.7868
  • 0.7874
  • 0.7844
  • 0.7864
  1. mlem_model:
  • 0.7778
  • 0.783
  • 0.7808
  • 0.7816

So almost the same, but consistently lower by about 0.6% on average.

@rocco-fortuna
Copy link
Author

rocco-fortuna commented Mar 13, 2023

@aguschin mentioned:

I think we can [try] one of Pytorch examples to see if this can be reproduced there. If that won't help us, we can try to dig deeper into some specifics.

Let me know if you need any additional info.

@aguschin
Copy link
Contributor

@mike0sv do you have any ideas why this could be the case?

@mike0sv
Copy link
Contributor

mike0sv commented Mar 14, 2023

Under the hood, mlem save and loads model with torch.save and torch.load (or torch.jit.save and torch.jit.load). We do not do anything else with the model. Can you confirm that this logic is to blame by running something like this

# load the model with Pytorch model class
model = MyModel.from_pretrained('./model_path')

# save
torch.save(model, "...")

#
model = torch.load("...")

and running evaluation?
If your model is isinstance(model, torch.jit.ScriptModule), use torch.jit

@rocco-fortuna
Copy link
Author

rocco-fortuna commented Mar 16, 2023

That yielded:

  • 0.7832
  • 0.7862
  • 0.7888
  • 0.7892

Consistently with the original model's performance

@aguschin aguschin added bug Something isn't working question Further information is requested ml-framework ML Framework support serialization Dumping and loading Python objects and removed question Further information is requested labels Apr 19, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug Something isn't working ml-framework ML Framework support serialization Dumping and loading Python objects
Projects
None yet
Development

No branches or pull requests

3 participants