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

python3Packages.tensorflow: Fix numpy==1.20 support #130022

Closed

Conversation

bergkvist
Copy link
Member

@bergkvist bergkvist commented Jul 12, 2021

Motivation for this change

Fixes #128829

Things done
  • Tested using sandboxing (nix.useSandbox on NixOS, or option sandbox in nix.conf on non-NixOS linux)
  • Built on platform(s)
    • NixOS
    • macOS
    • other Linux distributions
  • Tested via one or more NixOS test(s) if existing and applicable for the change (look inside nixos/tests)
  • Tested compilation of all pkgs that depend on this change using nix-shell -p nixpkgs-review --run "nixpkgs-review wip"
  • Tested execution of all binary files (usually in ./result/bin/)
  • 21.11 Release Notes (or backporting 21.05 Relase notes)
    • (Package updates) Added a release notes entry if the change is major or breaking
    • (Module updates) Added a release notes entry if the change is significant
    • (Module addition) Added a release notes entry if adding a new NixOS module
  • Fits CONTRIBUTING.md.

@bergkvist bergkvist force-pushed the bergkvist/tensorflow-numpy-1.20 branch from b3db322 to a32b89b Compare July 12, 2021 15:07
@ofborg ofborg bot requested a review from abbradar July 12, 2021 15:07
@bergkvist bergkvist force-pushed the bergkvist/tensorflow-numpy-1.20 branch from a32b89b to c71cd8e Compare July 12, 2021 15:08
@bergkvist bergkvist changed the title Fix pythonPackages3.tensorflow: Support numpy==1.20 python3Packages.tensorflow: Fix numpy==1.20 support Jul 12, 2021
@bergkvist bergkvist marked this pull request as ready for review July 12, 2021 15:25
maintainers/maintainer-list.nix Show resolved Hide resolved
Comment on lines +9 to +19
+from tensorflow.python.ops import math_ops
# go/tf-wildcard-import
# pylint: disable=wildcard-import
from tensorflow.python.ops.gen_array_ops import *
@@ -2897,7 +2898,7 @@ def matrix_set_diag(

def _constant_if_small(value, shape, dtype, name):
try:
- if np.prod(shape) < 1000:
+ if math_ops.reduce_prod(shape) < 1000:
return constant(value, shape=shape, dtype=dtype, name=name)
Copy link
Contributor

Choose a reason for hiding this comment

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

I feel like this should probably be upstreamed, there's nothing nixpkgs specific in it.

Copy link
Member Author

@bergkvist bergkvist Jul 15, 2021

Choose a reason for hiding this comment

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

I agree that this fix feels like it belongs in the Tensorflow repository. (or perhaps even as a change/fix to np.prod in the Numpy repository)

There have been open PRs to resolve the issue upstream/in the Tensorflow repo for more than 2 months. Supporting Numpy 1.20 doesn't seem to be a high priority for the Tensorflow team - since Numpy 1.19 is working fine with Tensorflow.

Numpy 1.20-support is pretty much essential in order for Tensorflow to work within the nixpkgs ecosystem, since nixpkgs currently ships NumPy 1.20 (pkgs.python3.pkgs.numpy). Downgrading NumPy to 1.19 in nixpkgs also seems like a risky option - since it might break something else depending on 1.20 or higher.

Shipping multiple versions of the same Python library within nixpkgs is also not a good option - since any environment that depends on multiple versions of the same python-library will break. That said, there is some interesting discussion around how to make it work here: https://discourse.nixos.org/t/allowing-multiple-versions-of-python-package-in-pythonpath-nixpkgs/3849

@bergkvist bergkvist force-pushed the bergkvist/tensorflow-numpy-1.20 branch from c71cd8e to fe76d16 Compare July 15, 2021 01:16
@risicle
Copy link
Contributor

risicle commented Jul 22, 2021

Upstream seem to have fixed this via tensorflow/tensorflow#47957

@bergkvist
Copy link
Member Author

@risicle Okay - nice! Does that means we should close this pull request? (Once we verify that Tensorflow in nixpkgs is working)

I guess an alternative would be to modify this PR to bump the Tensorflow version instead of patching it with the fix.

@risicle
Copy link
Contributor

risicle commented Jul 23, 2021

Either works for me.

@risicle
Copy link
Contributor

risicle commented Aug 1, 2021

Fixed in #132099

@risicle risicle closed this Aug 1, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Python 37, 38, 39: Tensorflow broken
4 participants