Skip to main content

tensorflow-auto-detect

Solves the absolute mess that is installing tensorflow from your package requirements.

Just put it in your setuptools requirements and it’ll install the GPU version of tensorflow if you have a CUDA available; otherwise it will fallback to the CPU version.

ci-badge coverage-badge

The problem

Background: Tensorflow provides two pypi packages: tensorflow and tensorflow-gpu. I’m sure you can infer which is compiled for which.

Let’s say you’re making a product or have a project:

  • It uses Tensorflow.

  • It will run on a myriad of classes of machines, and therefore needs to be able to operate and install on machines that may or may not have CUDA available.

  • You want to optimistically utilize a GPU if you can, but fallback to using just CPU.

  • You want your package to be easily installable. Every time. Not just for half of your userbase.

  • You don’t want to have toss the problem on your users and fellow engineers.

Let’s be honest, your stringently detailed absoute step-by-step microbe resistant instructions could.. maybe.. possibly.. not be followed and/or remembered exactly to a tee. You know, like everything else. Tech is hard.

Q: How do you add the proper one to your own package as a requirement when they both install to the same package namespace?

A: Well, you can’t. 🕶

Oh, and by the way, if you install one after the other, say to fix if you installed the wrong one at first, I’ll just blindly trample over the first’s files instead of doing anything useful. (Note: this is not Tensorflow’s fault here, but a more widespread problem in pyland)

You can try to choke it down with sweet hacks like:

  • Adding each in their own extras_require blocks (ruining your default and therefore path of least resistance)

  • Toss the problem onto the user. You’re that guy now.

How does it work?

This package includes a list of all libraries required by each version of tensorflow in tfdetect/cuda.py.

Currently, only the check for the cuda runtime library is active (by design) to be a bit more forgiving and allowing for “strange” setups, even though I’ve yet to come across one. This is the finest heuristic for this anyway, so it works out nicely, even in the face of your sweet sweet custom compiles; not to mention ensuring optional dependencies stay that way.

Versions beneath 1.7 have not been tested, so the CUDA versions are likely to be mismatched. Was too far in the past to care, I’m sorry.

Usage

In requirements.txt or install_requires:

tensorflow-auto-detect==1.10.0  # or any other release, 1to1 mapping to tf releases

As pip argument:

pip install tensorflow-auto-detect==1.8.1  # or any other release, 1to1 mapping to tf releases

Running tests

pip install '.[tests]'
pytest

Metadata

Release files for tensorflow-auto-detect 1.11.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for tensorflow-auto-detect 1.11.0
File Size Uploaded
tensorflow-auto-detect-1.11.0.tar.gz 7.9 kB Details

Release files / tensorflow-auto-detect-1.11.0.tar.gz

Download URL tensorflow-auto-detect-1.11.0.tar.gz
Size 7.9 kB
Tags Source
SHA-256 checksum
How to use checksums
8e6c6e2e3342192faccc05e152af858f335f6c6d2eafccb899fdfa433034003f
BLAKE2b-256 checksum
How to use checksums
2c44136c8f2ab04dd771c116f198bf19c63d02622123f50e1ae1803bf03a4066
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via Python-urllib/3.6

Release history Release notifications | RSS feed

This release

1.11.0 This release

1 release file

1.10.1

2 release files

1.10.0

1 release file

1.9.0

1 release file

1.8.0

1 release file

1.7.1

1 release file

1.7.0

1 release file

1.6.0

1 release file

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page