tensorflow / haskell

Haskell bindings for TensorFlow
https://tensorflow.github.io/haskell/haddock/
Apache License 2.0
1.58k stars 196 forks source link

Initial support for Tensorflow 2.4. #271

Closed mikesperber closed 3 years ago

mikesperber commented 3 years ago

I needed this to build with Tensorflow 2.4.

However, tensorflow-ops tests fail:

2021-01-29 12:52:49.103275: I tensorflow/core/platform/cpu_feature_guard.cc:142] This TensorFlow binary is optimized with oneAPI Deep Neural Network Library (oneDNN) to use the following CPU instructions in performance-critical operations:  AVX2 FMA
To enable them in other operations, rebuild TensorFlow with the appropriate compiler flags.
2021-01-29 12:52:49.114213: I tensorflow/core/platform/profile_utils/cpu_utils.cc:112] CPU Frequency: 2904000000 Hz
testBasic: [Failed]
ERROR: Malformed TF_STRING tensor; Result: incomplete input
CallStack (from HasCallStack):
  error, called at src/TensorFlow/Types.hs:326:25 in tensorflow-0.3.0.0-L9rHEd5m7I3FbUzqcxFf9q:TensorFlow.Types
testPump: [Failed]
ERROR: Malformed TF_STRING tensor; Result: incomplete input
CallStack (from HasCallStack):
  error, called at src/TensorFlow/Types.hs:326:25 in tensorflow-0.3.0.0-L9rHEd5m7I3FbUzqcxFf9q:TensorFlow.Types
TensorFlowException TF_CANCELLED "[_Derived_]Enqueue operation was cancelled\n\t [[{{node QueueEnqueue_5}}]]"
testAsync: [Failed]
ERROR: Malformed TF_STRING tensor; Result: incomplete input
CallStack (from HasCallStack):
  error, called at src/TensorFlow/Types.hs:326:25 in tensorflow-0.3.0.0-L9rHEd5m7I3FbUzqcxFf9q:TensorFlow.Types

         Test Cases  Total
 Passed  0           0
 Failed  3           3
 Total   3           3

This is beyond my ability - help would be appreciated!

fkm3 commented 3 years ago

Adding real support for attributes with type func is non-trivial, so I recommend add the new 2.4 ops to the list at https://github.com/tensorflow/haskell/blob/master/tensorflow-core-ops/Setup.hs#L87. That will avoid generating bindings for them. Could you give that try and see how far it gets you? I can maybe make an attempt this weekend if there is a more significant blocker.

mikesperber commented 3 years ago

Adding real support for attributes with type func is non-trivial, so I recommend add the new 2.4 ops to the list at https://github.com/tensorflow/haskell/blob/master/tensorflow-core-ops/Setup.hs#L87. That will avoid generating bindings for them. Could you give that try and see how far it gets you? I can maybe make an attempt this weekend if there is a more significant blocker.

Done - that went through. (The addition of AttrFunc was still needed.) Many thanks for the review!

fkm3 commented 3 years ago

The changes look good to me. We should update the CI to use the new tensorflow version, but that can be done later.

The CI tests failed. I think it is a transient issue in the docker setup (failed to download tensorflow lib because of an SSL error). I'm running it again.

fkm3 commented 3 years ago

There is another PR that only touches markdown files and it fails the same way, so I think our CI setup is simply broken.

I ran it manually and got the following error

tensorflow-opgen           > /tfhs/tensorflow-opgen/src/TensorFlow/OpGen.hs:316:26: error: [-Wincomplete-patterns, -Werror=incomplete-patterns]
tensorflow-opgen           >     Pattern match(es) are non-exhaustive
tensorflow-opgen           >     In a case alternative: Patterns not matched: AttrFunc
tensorflow-opgen           >     |
tensorflow-opgen           > 316 |     renderAttrBaseType = \case
tensorflow-opgen           >     |                          ^^^^^...

The following change was enough to fix it for me. However, I'm testing with tf 2.3.

diff --git a/tensorflow-opgen/src/TensorFlow/OpGen.hs b/tensorflow-opgen/src/TensorFlow/OpGen.hs
index 421b147..0d8a746 100644
--- a/tensorflow-opgen/src/TensorFlow/OpGen.hs
+++ b/tensorflow-opgen/src/TensorFlow/OpGen.hs
@@ -321,6 +321,7 @@ typeSig pre pOp = constraints
         AttrType -> "DataType"
         AttrShape -> "Shape"
         AttrTensor -> "TensorProto"
+        AttrFunc -> error "AttrFunc not supported"

     tensorArgAndComment t = tensorArg t <+> hang 0 ("-- ^" <+> argComment t)
     outputs = case parsedOutputs pOp of

Can you update the PR and retry? Use stack build --pedantic --test so that you get the same results as our CI.

mikesperber commented 3 years ago

The following change was enough to fix it for me. However, I'm testing with tf 2.3.

diff --git a/tensorflow-opgen/src/TensorFlow/OpGen.hs b/tensorflow-opgen/src/TensorFlow/OpGen.hs
index 421b147..0d8a746 100644
--- a/tensorflow-opgen/src/TensorFlow/OpGen.hs
+++ b/tensorflow-opgen/src/TensorFlow/OpGen.hs
@@ -321,6 +321,7 @@ typeSig pre pOp = constraints
         AttrType -> "DataType"
         AttrShape -> "Shape"
         AttrTensor -> "TensorProto"
+        AttrFunc -> error "AttrFunc not supported"

     tensorArgAndComment t = tensorArg t <+> hang 0 ("-- ^" <+> argComment t)
     outputs = case parsedOutputs pOp of

Ah, thanks! Did that, and went through.

fkm3 commented 3 years ago

Thanks!