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

Use conditional keras_nlp imports #2394

Draft
wants to merge 4 commits into
base: master
Choose a base branch
from
Draft

Conversation

smitlg
Copy link
Contributor

@smitlg smitlg commented Mar 19, 2024

What does this PR do?

Uses conditional import for keras_nlp to avoid hard dependency on keras_nlp.

On the current master branch:

/keras-cv$ pip install .
/keras-cv$ python
Python 3.11.0 | packaged by conda-forge | (main, Jan 14 2023, 12:27:40) [GCC 11.3.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import keras_cv
...
  File "/repos/keras-cv/keras_cv/models/feature_extractor/clip/clip_processor.py", line 14, in <module>
    from keras_nlp.layers import StartEndPacker
ModuleNotFoundError: No module named 'keras_nlp'

This will require users to forcefully install keras_nlp, even when they don't want to use the part of the code requiring keras_nlp.

On this branch:

>>> import keras_cv
>>> keras_cv.__file__
'/repos/keras-cv/keras_cv/__init__.py'

Before submitting

  • This PR fixes a typo or improves the docs (you can dismiss the other checks if that's the case).
  • Did you read the contributor guideline,
    Pull Request section?
  • Was this discussed/approved via a Github issue? Please add a link
    to it if that's the case.
  • Did you write any new necessary tests?
  • If this adds a new model, can you run a few training steps on TPU in Colab to ensure that no XLA incompatible OP are used?

Who can review?

cc @divyashreepathihalli

@innat
Copy link
Contributor

innat commented Mar 19, 2024

To fix the code format, make sure to run

shell/clean.sh # if keras-cv is built locally
shell/format.sh
shell/lint.sh

@smitlg
Copy link
Contributor Author

smitlg commented Mar 21, 2024

The same error is thrown because of tensorflow_text.

[/usr/local/lib/python3.10/dist-packages/keras_cv/models/feature_extractor/clip/clip_tokenizer.py](https://localhost:8080/#) in <module>
     14 import regex as re
     15 import tensorflow as tf
---> 16 import tensorflow_text as tf_text
     17 
     18 try:

ModuleNotFoundError: No module named 'tensorflow_text'

I will update the PR to add the fix for this too.

@smitlg smitlg mentioned this pull request Mar 22, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants