CounterfactualExplanations.jl icon indicating copy to clipboard operation
CounterfactualExplanations.jl copied to clipboard

Update Model Catalogue docs

Open izagorac opened this issue 6 months ago • 10 comments

When trying to import a PyTorch model as explained in the docs (https://juliatrustworthyai.github.io/CounterfactualExplanations.jl/dev/tutorials/model_catalogue/#Importing-PyTorch-models). I get the following error: ERROR: MethodError: no method matching pytorch_model_loader(::String, ::String, ::String, ::String)

According to Patrick, the code for importing has been moved to TaijaInteroperability.jl. This has to be updated in the docs.

izagorac avatar Dec 07 '23 15:12 izagorac

Thanks @izagorac! In the meantime, you should be able to use the method as expected by first importing the package:

using CounterfactualExplanations
using TaijaInteroperability
...

I'm a bit surprised thought that the error message didn't already hint at this, since we've deprecated the method.

If it's not too much trouble, can you post a minimum working example here including information about the exact package version you're using?

Thanks!

@kmariuszk for info

pat-alt avatar Dec 07 '23 18:12 pat-alt

Find my code and error message below. Im using CounterfactualExplanations v.0.1.31.

model_loaded = CounterfactualExplanations.Models.pytorch_model_loader(
        "$(pwd())/docs/src/tutorials/miscellaneous",
        "neural_network_class",
        "NeuralNetwork",
        "$(pwd())/docs/src/tutorials/miscellaneous/pretrained_model.pt"
    )

M = CounterfactualExplanations.Models.PyTorchModel(model_loaded, counterfactual_data.likelihood)
Screenshot 2023-12-11 at 11 35 36

izagorac avatar Dec 11 '23 10:12 izagorac

Can you try instead:

model_loaded = TaijaInteroperability.pytorch_model_loader(...)

pat-alt avatar Dec 11 '23 11:12 pat-alt

It gives the exact same error. I'm using TaijaInteroperability v.0.1.0

izagorac avatar Dec 11 '23 11:12 izagorac

Hmm alright thanks! @kmariuszk any idea what's going on here?

pat-alt avatar Dec 11 '23 11:12 pat-alt

Hey @izagorac, did you also activate the PythonCall package in your environment?

To give you a better overview of what I mean: Python and R functionality are package extensions in TaijaInteroperability.jl, which means you have to activate some weak dependencies to make them activate their appropriate functionality, so if you want to use Python functionality you have to run using TaijaInteroperability, PythonCall and the same applies to RCall. We did this to minimize the pain of users waiting for both PythonCall and RCall pre-compilation and to minimize the chance of errors caused by using both of these packages in the same environment.

Let me know if that solves the problem!

kmariuszk avatar Dec 12 '23 16:12 kmariuszk

Also, @pat-alt regarding this bit:

I'm a bit surprised thought that the error message didn't already hint at this, since we've deprecated the method.

We didn't release the latest version of package and thus users can still use PyTorch functionality in the original way, i.e., using CounterfactualExplanations, PythonCall

kmariuszk avatar Dec 12 '23 16:12 kmariuszk

Also, @pat-alt regarding this bit:

I'm a bit surprised thought that the error message didn't already hint at this, since we've deprecated the method.

We didn't release the latest version of package and thus users can still use PyTorch functionality in the original way, i.e., using CounterfactualExplanations, PythonCall

Ah yes, of course! Thanks for checking @kmariuszk

pat-alt avatar Dec 13 '23 05:12 pat-alt

Thanks @kmariuszk and @pat-alt, it works when using PythonCall. Before I was using PyCall, does that mean that that package is not necessary anymore?

izagorac avatar Dec 13 '23 11:12 izagorac

Thanks @kmariuszk and @pat-alt, it works when using PythonCall. Before I was using PyCall, does that mean that that package is not necessary anymore?

Yes, we decided not to use PyCall quite some time ago due to some bugs it was introducing. We're going to work on updating the documentation in the upcoming two weeks, so (hopefully) you won't experience such ambiguities anymore

kmariuszk avatar Dec 13 '23 11:12 kmariuszk