NixOS / nixpkgs

Nix Packages collection & NixOS
MIT License
18.08k stars 14.06k forks source link

keras package no longer imports in python environment #314235

Open PicoGeyer opened 5 months ago

PicoGeyer commented 5 months ago

I have a small flake for tensorflow/keras dev:

{
  description = "Deep learning environment";
  outputs = { self, nixpkgs }:
  let pkgs = nixpkgs.legacyPackages.x86_64-linux;
  mypython = pkgs.python3.withPackages (ps: with ps;
    [
      keras
      tensorflow
    ]);
  in
  {
    devShells.x86_64-linux.default = pkgs.mkShell {
      packages = [ mypython ];
    };
  };
}

After a nix flake update, I can no longer import keras. I did a bisect and found that the last version of nixpkgs where the import works is

commit b0db08979c620fc3b774fdda88db0943d723eb59
Merge: 9d4636da3969 8122293b5e0c
Author: Robert Schütz <nix@dotlambda.de>
Date:   Fri Jan 12 14:58:10 2024 +0100

    Merge pull request #280342 from dotlambda/aiosomecomfort-0.0.25

    python311Packages.aiosomecomfort: 0.0.24 -> 0.0.25

With the above version:

python -c 'import tensorflow.keras'
2024-05-24 10:58:22.396626: I tensorflow/core/platform/cpu_feature_guard.cc:182] This TensorFlow binary is optimized to use available CPU instructions in performance-critical operations.
To enable the following instructions: SSE3 SSE4.1 SSE4.2 AVX AVX2 FMA, in other operations, rebuild TensorFlow with the appropriate compiler flags

With any version after that:

nix flake update
• Updated input 'nixpkgs':
    'github:NixOS/nixpkgs/b0db08979c620fc3b774fdda88db0943d723eb59?narHash=sha256-ychTyfZ9rPtDP8uJaSb8mhrkx00G0VQ5kOmuSTE8bS8%3D' (2024-01-12)
  → 'github:NixOS/nixpkgs/3f316d2a50699a78afe5e77ca486ad553169061e?narHash=sha256-NQbegJb2ZZnAqp2EJhWwTf6DrZXSpA6xZCEq%2BRGV1r0%3D' (2024-05-22)

python -c 'import tensorflow.keras'
2024-05-24 11:00:05.363240: I tensorflow/core/platform/cpu_feature_guard.cc:182] This TensorFlow binary is optimized to use available CPU instructions in performance-critical operations.
To enable the following instructions: SSE3 SSE4.1 SSE4.2 AVX AVX2 FMA, in other operations, rebuild TensorFlow with the appropriate compiler flags.
Traceback (most recent call last):
  File "<string>", line 1, in <module>
ModuleNotFoundError: No module named 'tensorflow.keras'

@NikolaMandic

Metadata:

nix-shell -p nix-info --run "nix-info -m"
 - system: `"x86_64-linux"`
 - host os: `Linux 6.1.87, NixOS, 23.11 (Tapir), 23.11.20240424.dd37924`
 - multi-user?: `yes`
 - sandbox: `yes`
 - version: `nix-env (Nix) 2.18.1`
 - channels(root): `"nixos-23.11"`
 - nixpkgs: `/nix/store/22chir190mpfvp59lgh39q7fp7w77br9-source`
aanderse commented 2 months ago

@PicoGeyer did you ever find any resolution to this?

idlip commented 2 months ago

Hi, I'd like to add that you can call keras as standalone package. Just remove tensorflow. prefix, and keras.api or keras.models.. would work fine.

Even I wonder why it is not linked in tensorflow package calls

idlip commented 2 months ago

Related conversation: https://github.com/NixOS/nixpkgs/pull/333568#issuecomment-2280808641

Bug filed: #332198

FalseDev commented 1 month ago

I got tf.keras to work as expected using

my-python-packages = ps: with ps; [
  tensorflow-bin
  (keras.override {
       tensorflow = tensorflow-bin;
  })
];
idlip commented 1 month ago

May I know if it works with python312.withPackages, I get error that tensorflow 2.13 is not supported for 3.12