alibi-detect icon indicating copy to clipboard operation
alibi-detect copied to clipboard

Support for saving detectors with pytorch backend

Open pthalasta opened this issue 2 years ago • 2 comments

I was executing MMD Drift detector with pytorch backend and while saving the detector i ended up with an error

---------------------------------------------------------------------------
NotImplementedError                       Traceback (most recent call last)
/tmp/ipykernel_2460/896443056.py in <module>
      1 # we can also save/load an initialised detector
      2 filepath = 'models'  # change to directory where detector is saved
----> 3 save_detector(cd, filepath)

/opt/conda/envs/test/lib/python3.8/site-packages/alibi_detect/saving/saving.py in save_detector(detector, filepath, legacy)
     48 
     49     if 'backend' in list(detector.meta.keys()) and detector.meta['backend'] in ['pytorch', 'sklearn']:
---> 50         raise NotImplementedError('Saving detectors with PyTorch or sklearn backend is not yet supported.')
     51 
     52     # TODO: Replace .__args__ w/ typing.get_args() once Python 3.7 dropped (and remove type ignore below)

NotImplementedError: Saving detectors with PyTorch or sklearn backend is not yet supported.

Is there any ETA on when we'll have the feature supported? I'm not sure how useful it is to have the detector trained without being able to export/save and use them in other environments? Any specific reason why it is not supported?

pthalasta avatar Sep 15 '22 00:09 pthalasta

Hi @pthalasta, we are now actively working on this, and it will be released relatively soon. I shall make sure to update here once released. In the meantime, there is save/load support for the tensorflow backend, and for any detectors without a backend, such as KSDrift.

ascillitoe avatar Sep 21 '22 09:09 ascillitoe

@ascillitoe thanks for the update! I'll look into KSDrift. Yes, i did use tensorflow for some but since our main code is pytorch, having the pytorch support would really help!

pthalasta avatar Sep 21 '22 20:09 pthalasta