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

SIGSEGV when computing gradients for reduceMean using placeholders #255

Open
rikifunt opened this issue Mar 11, 2020 · 0 comments
Open

SIGSEGV when computing gradients for reduceMean using placeholders #255

rikifunt opened this issue Mar 11, 2020 · 0 comments

Comments

@rikifunt
Copy link

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant