Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Demangle pytorch and tensorflow dependencies #3662

Open
4 tasks done
CloseChoice opened this issue May 16, 2024 · 0 comments
Open
4 tasks done

Demangle pytorch and tensorflow dependencies #3662

CloseChoice opened this issue May 16, 2024 · 0 comments
Labels
enhancement Indicates new feature requests

Comments

@CloseChoice
Copy link
Collaborator

Issue Description

Currently our dependencies for the deep explainer are mangled together somewhere deep down. This best visible when running the notebook notebooks/image_examples/image_classification/PyTorch Deep Explainer MNIST example.ipynb without tf_keras installed, then one gets an error. This is completely counter intuitive since this notebook just needs pytorch related dependencies. We should definitely get this into a state where pytorch and tensorflow code can coexist without the other framework being installed.

Minimal Reproducible Example

pip uninstall tf_keras

then run `notebooks/image_examples/image_classification/PyTorch Deep Explainer MNIST example.ipynb`

then this throws an error in the cell



# since shuffle=True, this is a random sample of test data
batch = next(iter(test_loader))
images, _ = batch

background = images[:100]
test_images = images[100:103]

e = shap.DeepExplainer(model, background)
shap_values = e.shap_values(test_images)
``

Traceback

---------------------------------------------------------------------------
ModuleNotFoundError                       Traceback (most recent call last)
File ~/programming/github/shap_master/.venv/lib/python3.10/site-packages/transformers/activations_tf.py:22
     21 try:
---> 22     import tf_keras as keras
     23 except (ModuleNotFoundError, ImportError):

ModuleNotFoundError: No module named 'tf_keras'

During handling of the above exception, another exception occurred:

ValueError                                Traceback (most recent call last)
File ~/programming/github/shap_master/.venv/lib/python3.10/site-packages/transformers/utils/import_utils.py:1472, in _LazyModule._get_module(self, module_name)
   1471 try:
-> 1472     return importlib.import_module("." + module_name, self.__name__)
   1473 except Exception as e:

File /usr/lib/python3.10/importlib/__init__.py:126, in import_module(name, package)
    125         level += 1
--> 126 return _bootstrap._gcd_import(name[level:], package, level)

File <frozen importlib._bootstrap>:1050, in _gcd_import(name, package, level)

File <frozen importlib._bootstrap>:1027, in _find_and_load(name, import_)
...
   1476         f" traceback):\n{e}"
   1477     ) from e

RuntimeError: Failed to import transformers.modeling_tf_utils because of the following error (look up to see its traceback):
Your currently installed version of Keras is Keras 3, but this is not yet supported in Transformers. Please install the backwards-compatible tf-keras package with `pip install tf-keras`.

Expected Behavior

should work without any tensorflow dependencies

Bug report checklist

  • I have checked that this issue has not already been reported.
  • I have confirmed this bug exists on the latest release of shap.
  • I have confirmed this bug exists on the master branch of shap.
  • I'd be interested in making a PR to fix this bug

Installed Versions

master

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement Indicates new feature requests
Projects
None yet
Development

No branches or pull requests

1 participant