tensorflow/text

Managing tensorflow and tensorflow-cpu variants dependency

chiragjn opened this issue ยท 5 comments

So now that tensorflow_text lists tensorflow as a hard requirement and that is the gpu variant how do I install this with just cpu variant? I read all the previous cpu package related discussions and there seems to be no working solution at the moment

First off, the tensorflow-cpu requirement seems to be out of sync

install_requires=[
'tensorflow>=2.8.0, <2.9',
'tensorflow-macos>=2.7.0, <2.8.0; platform_machine == "arm64" and platform_system == "Darwin"',
'tensorflow_hub>=0.8.0',
],
extras_require={
'tensorflow_cpu': ['tensorflow-cpu>=2.4.0rc0, <2.5',],

trying

pip install -U tensorflow-text[tensorflow_cpu]==2.8.1 tensorflow-cpu==2.8.0

will bring in both tensorflow and tensorflow-cpu plus fail because constraint is tensorflow-cpu<2.5 and >=2.4.0rc0


just trying

pip install -U tensorflow-text[tensorflow_cpu]==2.8.1

will bring in both tensorflow and tensorflow-cpu with different versions which depend on different numpy versions again leading to conflicts

The conflict is caused by:
    tensorflow 2.8.0 depends on numpy>=1.20
    tensorflow-cpu 2.4.4 depends on numpy~=1.19.2

Even if the cpu version requirement is bumped to 2.8.x which tensorflow package would be finally installed?

Thanks for pointing out the listing of tensorflow-cpu is behind. That's a bug and I'll fix it now for future packages.

In the meantime, you can install tensorflow-cpu after installing tensorflow-text and it should work.

Here's a temporary method that lets you use tensorflow-cpu and it works fine. Hope that helps.

pip install tensorflow-cpu==2.8.0
pip install -no-deps tensorflow-text==2.8.1

Here's a temporary method that lets you use tensorflow-cpu and it works fine. Hope that helps.

pip install tensorflow-cpu==2.8.0
pip install -no-deps tensorflow-text==2.8.1

Thanks, this does work, I wish there was a better solution because this can't be managed in a single requirements.txt nor will pip check pass :(
Anyway, I think tensorflow can also adopt putting device in the version part like torch did - tensorflow==x.y.z+cu112 / tensorflow==x.y.z+cpu

or perhaps till then this project can remove tensorflow as a hard dependency and make it extra?

install_requires=[ 
     'tensorflow_hub>=0.8.0', 
 ], 
 extras_require={ 
     'cpu': ['tensorflow-cpu>=2.8.0rc0, <2.9',],
     'gpu': ['tensorflow>=2.8.0rc0, <2.9',],
     ... 

I think tensorflow can also adopt putting device in the version part like torch did - tensorflow==x.y.z+cu112 / tensorflow==x.y.z+cpu

This is a good idea. I'll bring it up with them.

or perhaps till then this project can remove tensorflow as a hard dependency and make it extra?

TF Text is tied so heavily to the tf versions, we have been hesitant to do it. The average user starting off just pip installs and doesn't want to worry about versioning, and getting linking errors due to a mismatch will turn a number of new users off.

However, perhaps we could do something similar to the above suggestion if TF doesn't. Like having a tensorflow-text==x.y.z+cpu that has the install_requires on tensorflow-cpu. This should address the problem that users like yourself are having.

I wanted to give a quick update on this.

First, TF will not switch to this method. The problem is that doing versions this way is it combines the two packages into one, and there is a size limit to what you can have in pypi. Doubling the growth will be bad for TF.

That said, our library is much smaller, so it should be less of a problem. However, we could just add a tensorflow-text-cpu package as well to achieve the same goal. Anyway, we've recently got some help with the builds, and I've added this issue to the list they're working through.