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

Throwing warning if frameworks get imported on importing ivy #11784

Merged
merged 5 commits into from
Mar 9, 2023
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions ivy/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,15 @@
from ivy._version import __version__ as __version__
import builtins
import numpy as np
import importlib


modules = ["jax", "tensorflow", "torch"]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The logic looks great, it would be better if we get the modules programmatically so that even if there's a new backend added, it would be taken into account (e.g. paddle and mindspore are being added and we'd like modules to contain those without having to explicitly add it to the list). Secondly, we should do this check at the end of the __init__.py file so that even if any other file imported in this file does a framework import, we'd be able to check for it



for module in modules:
if importlib.find_spec(module) is not None:
warnings.warn(f"{module} module detected,only Numpy should be imported")


warnings.filterwarnings("ignore", module="^(?!.*ivy).*$")
Expand Down