Description
Hi, I am using version 0.2.0.1 of the bindings (with stack, LTS 14.4, on macos catalina), and i encountered the following problem: when computing gradients for the TensorFlow.Ops.reduceMean
op, if any of the inputs to the op come from (correctly fed) placeholders, the code always causes a SIGSEGV. I've put together a small code example that reproduces the error, in which the gradients of a function y = mean[x * w] are computed w.r.t. w, (with both x and w of dim = 2):
{-# LANGUAGE OverloadedLists #-}
import Control.Monad.IO.Class (liftIO)
import Data.Vector (Vector)
import qualified TensorFlow.Core as TF
import qualified TensorFlow.Ops as TF
import qualified TensorFlow.Gradient as TF
main :: IO ()
main = TF.runSession $ do
x <- TF.placeholder [2]
w <- TF.placeholder [2]
let ys = x `TF.mul` w
y <- TF.render $ TF.reduceMean ys
let xf = TF.feed x $ TF.encodeTensorData [2] ([0.4,0.6] :: Vector Float)
let wf = TF.feed w $ TF.encodeTensorData [2] ([0.1,0.2] :: Vector Float)
g : _ <- TF.gradients y [w]
g' <- TF.runWithFeeds [wf, xf] g :: TF.Session (Vector Float)
liftIO $ print g'
The SIGSEGV is not thrown when using a different op (e.g. reduceSum
), nor when both x
and w
above do not come from placeholders (e.g. if they are instantiated as constant tensors).
Moreover, even if x
and w
do not come from placeholders, the gradient call succeeds but outputs [0.4,0.6]
, as if reduceSum
was used (i.e. gradients are not scaled by the vector size, 2 in this case).
I hope i didn't miss any important information, thanks in advance to anyone who can help.