Giter Site home page Giter Site logo

haskell's Introduction

Build Status

The tensorflow-haskell package provides Haskell bindings to TensorFlow.

This is not an official Google product.

Documentation

https://tensorflow.github.io/haskell/haddock/

TensorFlow.Core is a good place to start.

Examples

Neural network model for the MNIST dataset: code

Toy example of a linear regression model (full code):

import Control.Monad (replicateM, replicateM_)
import System.Random (randomIO)
import Test.HUnit (assertBool)

import qualified TensorFlow.Core as TF
import qualified TensorFlow.GenOps.Core as TF
import qualified TensorFlow.Minimize as TF
import qualified TensorFlow.Ops as TF hiding (initializedVariable)
import qualified TensorFlow.Variable as TF

main :: IO ()
main = do
    -- Generate data where `y = x*3 + 8`.
    xData <- replicateM 100 randomIO
    let yData = [x*3 + 8 | x <- xData]
    -- Fit linear regression model.
    (w, b) <- fit xData yData
    assertBool "w == 3" (abs (3 - w) < 0.001)
    assertBool "b == 8" (abs (8 - b) < 0.001)

fit :: [Float] -> [Float] -> IO (Float, Float)
fit xData yData = TF.runSession $ do
    -- Create tensorflow constants for x and y.
    let x = TF.vector xData
        y = TF.vector yData
    -- Create scalar variables for slope and intercept.
    w <- TF.initializedVariable 0
    b <- TF.initializedVariable 0
    -- Define the loss function.
    let yHat = (x `TF.mul` TF.readValue w) `TF.add` TF.readValue b
        loss = TF.square (yHat `TF.sub` y)
    -- Optimize with gradient descent.
    trainStep <- TF.minimizeWith (TF.gradientDescent 0.001) loss [w, b]
    replicateM_ 1000 (TF.run trainStep)
    -- Return the learned parameters.
    (TF.Scalar w', TF.Scalar b') <- TF.run (TF.readValue w, TF.readValue b)
    return (w', b')

Installation Instructions

Note: building this repository with stack requires version 2.3.1 or newer. Check your stack version with stack --version in a terminal.

Build with Docker on Linux

As an expedient we use docker for building. Once you have docker working, the following commands will compile and run the tests.

git clone --recursive https://github.com/tensorflow/haskell.git tensorflow-haskell
cd tensorflow-haskell
docker build -t tensorflow/haskell:2.12.0 docker
# TODO: move the setup step to the docker script.
stack --docker setup
stack --docker test

There is also a demo application:

cd tensorflow-mnist
stack --docker build --exec Main

Stack + Docker + GPU

If you want to use GPU you can do:

IMAGE_NAME=tensorflow/haskell:2.12.0-gpu
docker build -t $IMAGE_NAME docker/gpu
# TODO: move the setup step to the docker script.
stack --docker --docker-image=$IMAGE_NAME setup
stack --docker --docker-image=$IMAGE_NAME test

Using nvidia-docker version 2

See Nvidia docker 2 install instructions

stack --docker --docker-image=$IMAGE_NAME setup
stack --docker --docker-run-args "--runtime=nvidia" --docker-image=$IMAGE_NAME test

Using nvidia-docker classic

Stack needs to use nvidia-docker instead of the normal docker for GPU support. We must wrap 'docker' with a script. This script will shadow the normal docker command.

ln -s `pwd`/tools/nvidia-docker-wrapper.sh <somewhere in your path>/docker
stack --docker --docker-image=$IMAGE_NAME setup
stack --docker --docker-image=$IMAGE_NAME test

Build on macOS

Run the install_macos_dependencies.sh script in the tools/ directory. The script installs dependencies via Homebrew and then downloads and installs the TensorFlow library on your machine under /usr/local.

After running the script to install system dependencies, build the project with stack:

stack test

Build on NixOS

The stack.yaml file describes a NixOS environment containing the necessary dependencies. To build, run:

$ stack --nix build

Installation on CentOS

Xiaokui Shu (@subbyte) maintains separate instructions for installation on CentOS.

Related Projects

Statically validated tensor shapes

https://github.com/helq/tensorflow-haskell-deptyped is experimenting with using dependent types to statically validate tensor shapes. May be merged with this repository in the future.

Example:

{-# LANGUAGE DataKinds, ScopedTypeVariables #-}

import Data.Maybe (fromJust)
import Data.Vector.Sized (Vector, fromList)
import TensorFlow.DepTyped

test :: IO (Vector 8 Float)
test = runSession $ do
  (x :: Placeholder "x" '[4,3] Float) <- placeholder

  let elems1 = fromJust $ fromList [1,2,3,4,1,2]
      elems2 = fromJust $ fromList [5,6,7,8]
      (w :: Tensor '[3,2] '[] Build Float) = constant elems1
      (b :: Tensor '[4,1] '[] Build Float) = constant elems2
      y = (x `matMul` w) `add` b -- y shape: [4,2] (b shape is [4.1] but `add` broadcasts it to [4,2])

  let (inputX :: TensorData "x" [4,3] Float) =
          encodeTensorData . fromJust $ fromList [1,2,3,4,1,0,7,9,5,3,5,4]

  runWithFeeds (feed x inputX :~~ NilFeedList) y

main :: IO ()
main = test >>= print

License

This project is licensed under the terms of the Apache 2.0 license.

haskell's People

Contributors

alanyee avatar austinvhuang avatar awpr avatar blackgnezdo avatar chrberen avatar chroth7 avatar dividedbynil avatar ehamberg avatar erikabor avatar fkm3 avatar grwlf avatar helq avatar jbransen avatar jcberentsen avatar jcmartin avatar jonathankochems avatar judah avatar kenranunderscore avatar leptonyu avatar majjoha avatar mattludwigs avatar mezzomondo avatar mikesperber avatar nathantalewis avatar nmattia avatar rikvdkleij avatar rschlotterbeck avatar saeedhk avatar silky avatar yorickvp avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

haskell's Issues

tensorflow-core-ops build error

Hi,
I tried to build tensorflow-core-ops 0.1.0.0 in LTS Haskell 9.1, came with the following build error? How can I solve this? libtensorflow version 1.3

-- While building package tensorflow-core-ops-0.1.0.0 using:
/private/var/folders/_y/bh1tdq6s1dd9kz9wdxh1cbdm0000gr/T/stack79985/tensorflow-core-ops-0.1.0.0/.stack-work/dist/x86_64-osx/Cabal-1.24.2.0/setup/setup --builddir=.stack-work/dist/x86_64-osx/Cabal-1.24.2.0 build --ghc-options " -ddump-hi -ddump-to-file"
Process exited with code: ExitFailure 1
Logs have been written to: /Users/daniel/.stack/global-project/.stack-work/logs/tensorflow-core-ops-0.1.0.0.log

[1 of 2] Compiling Main ( /private/var/folders/_y/bh1tdq6s1dd9kz9wdxh1cbdm0000gr/T/stack79985/tensorflow-core-ops-0.1.0.0/Setup.hs, /private/var/folders/_y/bh1tdq6s1dd9kz9wdxh1cbdm0000gr/T/stack79985/tensorflow-core-ops-0.1.0.0/.stack-work/dist/x86_64-osx/Cabal-1.24.2.0/setup/Main.o )
[2 of 2] Compiling StackSetupShim ( /Users/daniel/.stack/setup-exe-src/setup-shim-mPHDZzAJ.hs, /private/var/folders/_y/bh1tdq6s1dd9kz9wdxh1cbdm0000gr/T/stack79985/tensorflow-core-ops-0.1.0.0/.stack-work/dist/x86_64-osx/Cabal-1.24.2.0/setup/StackSetupShim.o )
Linking /private/var/folders/_y/bh1tdq6s1dd9kz9wdxh1cbdm0000gr/T/stack79985/tensorflow-core-ops-0.1.0.0/.stack-work/dist/x86_64-osx/Cabal-1.24.2.0/setup/setup ...
Configuring tensorflow-core-ops-0.1.0.0...
parseAttrType: unrecognized type "func" for op "FilterDataset"
CallStack (from HasCallStack):
error, called at src/TensorFlow/OpGen/ParsedOp.hs:342:10 in
tensorflow-opgen-0.1.0.0-9gIM6DSJBcgE9HQZAwSLKX:TensorFlow.OpGen.ParsedOp

"Stateful" generated ops should return "Build"

OpGen should follow the convention of returning a "Build" action (rather than a pure value) if either of the following is true:

  • The OpDef has is_stateful set to true
  • Any of the inputs are Tensor Refs or ResourceHandles.

This approach matches TensorFlow's internal logic around whether it's safe to CSE an op. (It's already what we do for handwritten ops.)

We should also document this behavior somewhere.

Implement `numOutputs` for `minimum`

This seems very similar to #129.

The code in question:

let y = (TF.minimum 0 (TF.expm1 x)) `TF.add` (TF.relu x)

The error message: numOuputs not implemented for "Minimum"

I'm using commit 79d8d7e.

Alternatively, if there is an existing implementation of elu that I could use, how would I use it?

Can't get tensorflow-core-ops to build in a new project

I have the latest commit of this repo checked out, and I'm using stack to try and build, using a relative directory:

resolver: lts-8.12

packages:
- '.'
- location: ../tensorflow-haskell
  extra-dep: true
  subdirs:
    - tensorflow
    - tensorflow-proto
    - tensorflow-opgen 
    - tensorflow-ops
    - tensorflow-core-ops
extra-deps: 
- proto-lens-0.2.0.1
- proto-lens-protoc-0.2.0.1
- proto-lens-descriptors-0.2.0.1

flags: {}

extra-package-dbs: []

I get the error:

$ stack --docker --docker-image=tensorflow/haskell:v0 build --exec my-project-exe
tensorflow-core-ops-0.1.0.0: configure (lib)
Package tensorflow-core-ops uses a custom Cabal build, but does not use a custom-setup stanza
Not using the explicit setup deps approach based on configuration
Strongly recommend fixing the package's cabal file
Progress: 1/3
--  While building package tensorflow-core-ops-0.1.0.0 using:
      /home/ollie/.stack/programs/x86_64-linux-dkd1ce2ff9c9560b648268df668d177711/ghc-8.0.2/bin/ghc --make -odir /home/ollie/Programming/tensorflow-haskell/tensorflow-core-ops/.stack-work/dist/x86_64-linux-dkd1ce2ff9c9560b648268df668d177711/Cabal-1.24.2.0/setup -hidir /home/ollie/Programming/tensorflow-haskell/tensorflow-core-ops/.stack-work/dist/x86_64-linux-dkd1ce2ff9c9560b648268df668d177711/Cabal-1.24.2.0/setup -i -i. -package=Cabal-1.24.2.0 -clear-package-db -global-package-db -package-db=/home/ollie/.stack/snapshots/x86_64-linux-dkd1ce2ff9c9560b648268df668d177711/lts-8.12/8.0.2/pkgdb /home/ollie/Programming/tensorflow-haskell/tensorflow-core-ops/Setup.hs /home/ollie/.stack/setup-exe-src/setup-shim-mPHDZzAJ.hs -main-is StackSetupShim.mainOverride -o /home/ollie/Programming/tensorflow-haskell/tensorflow-core-ops/.stack-work/dist/x86_64-linux-dkd1ce2ff9c9560b648268df668d177711/Cabal-1.24.2.0/setup/setup -threaded
    Process exited with code: ExitFailure 1
    Logs have been written to: /home/ollie/Programming/my-project/.stack-work/logs/tensorflow-core-ops-0.1.0.0.log

    [1 of 2] Compiling Main             ( /home/ollie/Programming/tensorflow-haskell/tensorflow-core-ops/Setup.hs, /home/ollie/Programming/tensorflow-haskell/tensorflow-core-ops/.stack-work/dist/x86_64-linux-dkd1ce2ff9c9560b648268df668d177711/Cabal-1.24.2.0/setup/Main.o ) [TensorFlow.OpGen changed]
    
    /home/ollie/Programming/tensorflow-haskell/tensorflow-core-ops/Setup.hs:31:1: error:
        Failed to load interface for ‘TensorFlow.Internal.FFI’
        Use -v to see a list of the files searched for.
    
    /home/ollie/Programming/tensorflow-haskell/tensorflow-core-ops/Setup.hs:32:1: error:
        Failed to load interface for ‘TensorFlow.OpGen’
        Use -v to see a list of the files searched for.

Yet I can build and run the mnist project fine with

cd tensorflow-mnist
stack --docker --docker-image=tensorflow/haskell:v0 build --exec Main

as described in the README. What is going on?

GHC 8

Bumping the master stack.yaml to lts-7.3 unsurprisingly causes the build to break in OSX el capitan:

[...]
tensorflow-opgen-0.1.0.0: copy/register
Progress: 12/17
--  While building package tensorflow-0.1.0.0 using:
      /Users/.../.stack/setup-exe-cache/x86_64-osx/setup-Simple-Cabal-1.24.0.0-ghc-8.0.1 --builddir=.stack-work/dist/x86_64-osx/Cabal-1.24.0.0 build lib:tensorflow --ghc-options " -ddump-hi -ddump-to-file"
    Process exited with code: ExitFailure 1
    Logs have been written to: /Users/.../tensorflow-haskell/.stack-work/logs/tensorflow-0.1.0.0.log

    Configuring tensorflow-0.1.0.0...
    Preprocessing library tensorflow-0.1.0.0...
    [ 4 of 12] Compiling TensorFlow.Types ( src/TensorFlow/Types.hs, .stack-work/dist/x86_64-osx/Cabal-1.24.0.0/build/TensorFlow/Types.o )
    
    /Users/.../tensorflow-haskell/tensorflow/src/TensorFlow/Types.hs:376:5: error:
        Malformed head of type or class declaration: as \\ b : bs

Is there any notion of when GHC 8 might be supported?

"tensorflow-proto" setup script failure on Mac

This happens when I run stack build in the project's root directory

Warning: File listed in tensorflow/tensorflow.cabal file does not exist: third_party/tensorflow/c/c_api.h
WARNING: filepath wildcard 'third_party/tensorflow/tensorflow/core/example/*.proto' does not match any files.
WARNING: filepath wildcard 'third_party/tensorflow/tensorflow/core/framework/*.proto' does not match any files.
Warning: File listed in tensorflow-proto/tensorflow-proto.cabal file does not exist: third_party/tensorflow/tensorflow/core/lib/core/error_codes.proto
WARNING: filepath wildcard 'third_party/tensorflow/tensorflow/core/protobuf/*.proto' does not match any files.
WARNING: filepath wildcard 'third_party/tensorflow/tensorflow/core/util/*.proto' does not match any files.
tensorflow-proto-0.1.0.0: build (lib)
WARNING: filepath wildcard 'third_party/tensorflow/tensorflow/core/example/*.proto' does not match any files.
WARNING: filepath wildcard 'third_party/tensorflow/tensorflow/core/framework/*.proto' does not match any files.
Warning: File listed in tensorflow-proto/tensorflow-proto.cabal file does not exist: third_party/tensorflow/tensorflow/core/lib/core/error_codes.proto
WARNING: filepath wildcard 'third_party/tensorflow/tensorflow/core/protobuf/*.proto' does not match any files.
WARNING: filepath wildcard 'third_party/tensorflow/tensorflow/core/util/*.proto' does not match any files.
Log files have been written to: /Users/mojojojo/Yandex.Disk.localized/repos/oss/tensorflow.haskell/.stack-work/logs/
Progress: 1/7
--  While building package tensorflow-proto-0.1.0.0 using:
      /Users/mojojojo/Yandex.Disk.localized/repos/oss/tensorflow.haskell/tensorflow-proto/.stack-work/dist/x86_64-osx/Cabal-1.24.2.0/setup/setup --builddir=.stack-work/dist/x86_64-osx/Cabal-1.24.2.0 build lib:tensorflow-proto --ghc-options " -ddump-hi -ddump-to-file"
    Process exited with code: ExitFailure 1
    Logs have been written to: /Users/mojojojo/Yandex.Disk.localized/repos/oss/tensorflow.haskell/.stack-work/logs/tensorflow-proto-0.1.0.0.log

    ./third_party/tensorflow/tensorflow/core/example/:
    getDirectoryContents:openDirStream: does not exist (No such file or directory)

And here are the contents of the log-file:

[1 of 2] Compiling Main             ( /Users/mojojojo/Yandex.Disk.localized/repos/oss/tensorflow.haskell/tensorflow-proto/Setup.hs, /Users/mojojojo/Yandex.Disk.localized/repos/oss/tensorflow.haskell/tensorflow-proto/.stack-work/dist/x86_64-osx/Cabal-1.24.2.0/setup/Main.o )
[2 of 2] Compiling StackSetupShim   ( /Users/mojojojo/.stack/setup-exe-src/setup-shim-mPHDZzAJ.hs, /Users/mojojojo/Yandex.Disk.localized/repos/oss/tensorflow.haskell/tensorflow-proto/.stack-work/dist/x86_64-osx/Cabal-1.24.2.0/setup/StackSetupShim.o )
Linking /Users/mojojojo/Yandex.Disk.localized/repos/oss/tensorflow.haskell/tensorflow-proto/.stack-work/dist/x86_64-osx/Cabal-1.24.2.0/setup/setup ...
Configuring tensorflow-proto-0.1.0.0...
./third_party/tensorflow/tensorflow/core/example/:
getDirectoryContents:openDirStream: does not exist (No such file or directory)

Docker is required, why?

The readme says

For now docker is required

but doesn't state the underlying reason.

Could this be added to the readme?

Basic examples

I am interested in combining Haskell UI( Spock ? ) and TensorFlow to start working on an image identification system. Identify one image in a group.
Is there a bootstrap example like that ? Either your example or something TensorFlow has that you referred.

SInce both Haskell and Deep Learning have a very steep learning curve I think we need some basic examples.

Fetch multi-dimensions arrays

Currently, the only options for fetching a multi-dimensional Tensor are lists or Vectors, both of which concatenate it into one dimension. (For example, a shape of [2,2,2] will turn into a shape of [8]). We should allow using a more appropriate Haskell type for such Fetches.

Permission issues with `stack --docker --docker-image=$IMAGE_NAME setup`

I'm getting:


$ stack  --docker --docker-image=$IMAGE_NAME setup
Error response from daemon: invalid header field value "oci runtime error: container_linux.go:247: starting container process caused \"exec: \\\"/opt/host/bin/stack\\\": permission denied\"\n"

Or more verbose:

$ stack --verbose  --docker --docker-image=$IMAGE_NAME setup
Version 1.3.0 x86_64 hpack-0.15.0
2016-12-24 01:02:50.561890: [debug] Checking for project config at: /home/astor/code/tensorflow-haskell/stack.yaml
@(Stack/Config.hs:863:9)
2016-12-24 01:02:50.562232: [debug] Loading project config file stack.yaml
@(Stack/Config.hs:881:13)
2016-12-24 01:02:50.567649: [debug] Run process: /usr/bin/docker --version
@(System/Process/Read.hs:306:3)
2016-12-24 01:02:50.580563: [debug] Process finished in 12ms: /usr/bin/docker --version
@(System/Process/Read.hs:306:3)
2016-12-24 01:02:50.580878: [debug] Run process: /usr/bin/docker inspect tensorflow/haskell:v0
@(System/Process/Read.hs:306:3)
2016-12-24 01:02:50.657452: [debug] Process finished in 76ms: /usr/bin/docker inspect tensorflow/haskell:v0
@(System/Process/Read.hs:306:3)
2016-12-24 01:02:50.918471: [debug] Run process: /usr/bin/docker create --net=host -e STACK_IN_CONTAINER=1 -e STACK_ROOT=/home/astor/.stack -e STACK_PLATFORM_VARIANT=dkd1ce2ff9c9560b648268df668d177711 -e HOME=/home/astor/code/tensorflow-haskell/.stack-work/docker/_home -e PATH=/opt/host/bin:/home/astor/code/tensorflow-haskell/.stack-work/docker/_home/.local/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin -e PWD=/home/astor/code/tensorflow-haskell -v /home/astor:/home/astor -v /home/astor/.stack:/home/astor/.stack -v /home/astor/code/tensorflow-haskell:/home/astor/code/tensorflow-haskell -v /home/astor/code/tensorflow-haskell/.stack-work/docker/_home:/home/astor/code/tensorflow-haskell/.stack-work/docker/_home -w /home/astor/code/tensorflow-haskell -e USER=astor -e SSH_AUTH_SOCK=/tmp/ssh-dGQ9YG5Rwt/agent.9349 -v /tmp/ssh-dGQ9YG5Rwt/agent.9349:/tmp/ssh-dGQ9YG5Rwt/agent.9349 -v /home/astor/.stack/programs/x86_64-linux/stack-1.3.0/stack:/opt/host/bin/stack -t -i tensorflow/haskell:v0 /opt/host/bin/stack --internal-re-exec-version=1.3.0 --internal-docker-entrypoint "DockerEntrypoint {deUser = Nothing}" --verbose --docker --docker-image=tensorflow/haskell:v0 setup
@(System/Process/Read.hs:306:3)
2016-12-24 01:02:51.145037: [debug] Process finished in 226ms: /usr/bin/docker create --net=host -e STACK_IN_CONTAINER=1 -e STACK_ROOT=/home/astor/.stack -e STACK_PLATFORM_VARIANT=dkd1ce2ff9c9560b648268df668d177711 -e HOME=/home/astor/code/tensorflow-haskell/.stack-work/docker/_home -e PATH=/opt/host/bin:/home/astor/code/tensorflow-haskell/.stack-work/docker/_home/.local/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin -e PWD=/home/astor/code/tensorflow-haskell -v /home/astor:/home/astor -v /home/astor/.stack:/home/astor/.stack -v /home/astor/code/tensorflow-haskell:/home/astor/code/tensorflow-haskell -v /home/astor/code/tensorflow-haskell/.stack-work/docker/_home:/home/astor/code/tensorflow-haskell/.stack-work/docker/_home -w /home/astor/code/tensorflow-haskell -e USER=astor -e SSH_AUTH_SOCK=/tmp/ssh-dGQ9YG5Rwt/agent.9349 -v /tmp/ssh-dGQ9YG5Rwt/agent.9349:/tmp/ssh-dGQ9YG5Rwt/agent.9349 -v /home/astor/.stack/programs/x86_64-linux/stack-1.3.0/stack:/opt/host/bin/stack -t -i tensorflow/haskell:v0 /opt/host/bin/stack --internal-re-exec-version=1.3.0 --internal-docker-entrypoint "DockerEntrypoint {deUser = Nothing}" --verbose --docker --docker-image=tensorflow/haskell:v0 setup
@(System/Process/Read.hs:306:3)
2016-12-24 01:02:51.145408: [debug] Creating process: /usr/bin/docker start -a -i 70f06c60cd610b0bc2c5916f5b1b0129ea5a265a09004f6325555c0a033829a2
@(System/Process/Run.hs:102:5)
Error response from daemon: invalid header field value "oci runtime error: container_linux.go:247: starting container process caused \"exec: \\\"/opt/host/bin/stack\\\": permission denied\"\n"
2016-12-24 01:02:51.757943: [debug] Run process: /usr/bin/docker rm -f 70f06c60cd610b0bc2c5916f5b1b0129ea5a265a09004f6325555c0a033829a2
@(System/Process/Read.hs:306:3)
2016-12-24 01:02:51.849457: [debug] Process finished in 91ms: /usr/bin/docker rm -f 70f06c60cd610b0bc2c5916f5b1b0129ea5a265a09004f6325555c0a033829a2

I am guessing that the -v /home/astor/.stack/programs/x86_64-linux/stack-1.3.0/stack:/opt/host/bin/stack option is the culprit for the permissions issues as docker is juggling UID namespaces.

$ docker info
Containers: 16
 Running: 4
 Paused: 0
 Stopped: 12
Images: 43
Server Version: 1.12.3
Storage Driver: aufs
 Root Dir: /var/lib/docker/aufs
 Backing Filesystem: extfs
 Dirs: 175
 Dirperm1 Supported: true
Logging Driver: json-file
Cgroup Driver: cgroupfs
Plugins:
 Volume: local
 Network: host null bridge overlay
Swarm: active
 NodeID: dmmg7fgiw99uqrpsy0xysv7rp
 Is Manager: true
 ClusterID: f44o7czxjxbszy26plrpq86em
 Managers: 1
 Nodes: 1
 Orchestration:
  Task History Retention Limit: 5
 Raft:
  Snapshot Interval: 10000
  Heartbeat Tick: 1
  Election Tick: 3
 Dispatcher:
  Heartbeat Period: 5 seconds
 CA Configuration:
  Expiry Duration: 3 months
 Node Address: 10.8.116.195
Runtimes: runc
Default Runtime: runc
Security Options: seccomp
Kernel Version: 4.8.3-docker-1
Operating System: Ubuntu 16.04 LTS
OSType: linux
Architecture: x86_64
CPUs: 6
Total Memory: 7.788 GiB
Name: docker5
ID: ZFNZ:NATI:OFDD:RYQL:EFWL:PMVJ:I7FD:PLZE:G55A:EW3A:P4AZ:3RVU
Docker Root Dir: /var/lib/docker
Debug Mode (client): false
Debug Mode (server): false
Registry: https://index.docker.io/v1/
Labels:
 provider=scaleway(VC1L)
Insecure Registries:
 127.0.0.0/8
$ stack --version
Version 1.3.0 x86_64 hpack-0.15.0

meta graph saving and loading similar to python

as-is we can save and load individual tensors

it would be quite good if we could also save/load the metagraph thing, as in python

this way, it would be very easy to train in python and run in haskell, without having to re-create the whole model in haskell (and likewise the other way)

nix-shell invocation from README fails

$ nix-shell tools/userchroot.nix
error: attribute ‘dev’ missing, at /home/niklas/src/haskell/haskell-tensorflow/tools/userchroot.nix:37:9
(use ‘--show-trace’ to show detailed location information)

Which version/commit of nixpkgs is this expected to work on?

missing `conv2d` and other convolution operations can just be added straightforwardly?

this project is awesome!

but i note several operations relating to convolutions are missing.

glancing at tensorflow-ops/src/TensorFlow/Ops.hs it seems like i can just add in the definitions there in a similar manner; i.e. say:

conv2d :: forall a v . TensorType a => Tensor v a -> Tensor v a -> [Int64] -> Build (Tensor Value a)
conv2d input filter strides padding =
    TF.buildOp $ TF.opDef "Conv2D"
            & TF.opAttr "input" .~ input
            & TF.opAttr "filter" .~ filter
            ...

right? or is there a bit more to it?

TF.assign surprising behaviour

I wrote some tests to guide my understanding of TF.assign in relation to run and runSession. Similar to:
https://github.com/tensorflow/haskell/blob/master/tensorflow-ops/tests/BuildTest.hs#L83

case_use_scalar_after_assigns_surprizingly_fails = do
  (f0, f1, f2) <- TF.runSession $ do
    (formula, reset0, reset1) <- do
      w <- TF.initializedVariable 0
      let formula = w                                                                                                                                                   
      r0 <- TF.assign w (TF.scalar (0.1::Float))
      r1 <- TF.assign w (TF.scalar (0.2::Float))
      return (formula, r0, r1)

    (TF.Scalar f0) <- TF.run formula
    TF.run_ reset0
    (TF.Scalar f1) <- TF.run formula
    TF.run_ reset1
    (TF.Scalar f2) <- TF.run formula
    return (f0, f1, f2)

  (0.0, 0.1, 0.2) @=? (f0, f1, f2)

This fails with f0, f1 and f2 being the final value of the assigned variable. If I change the test to:

case_use_scalar_after_assigns_works_but_why = do
  (f0, f1, f2) <- TF.runSession $ do
    (formula, reset0, reset1) <- do
      w <- TF.initializedVariable 0
      let formula = TF.mul 1 w -- Matters
      r0 <- TF.assign w (TF.scalar (0.1::Float))
      r1 <- TF.assign w (TF.scalar (0.2::Float))
      return (formula, r0, r1)

    (TF.Scalar f0) <- TF.run formula
    TF.run_ reset0
    (TF.Scalar f1) <- TF.run formula
    TF.run_ reset1
    (TF.Scalar f2) <- TF.run formula
    return (f0, f1, f2)

  (0.0, 0.1, 0.2) @=? (f0, f1, f2)

by changing to let formula = TF.mul 1 w This works, but why doesn't the previous version?

I wrote these tests because I tried in other code do something like this:

...
M.replicateM epochs $ do
    TF.run_ fitStep
    TF.run $ TF.value refW

to collect the evolution of the w terms but they ended up being equal (but verifiably different from the initial value), even with the TF.value conversion.
(The fitStep does assign to refW)

Is this expected behaviour? Am I missing something?

Remove the dependency on snappy

Our bindings currently link against the snappy C library due to the dependency on snappy-framing. As far as I can tell, the only reason we use that library is for Data.Digest.CRC32C which is pure Haskell code and doesn't actually use that C dependency.

The snappy and snappy-framing packages are also currently not in Stackage, which prevents tensorflow-records and tensorflow-records-conduit from being there as well.

As suggested in the code, one option is to split out the crc32c functionality into its own package.

Implementing Dropout in Haskell Interface

As an exercise to test my understanding, I've been trying to implement a simple dropout operation in the Haskell interface to Tensorflow. Following the example https://github.com/tensorflow/haskell/blob/master/tensorflow-mnist/app/Main.hs, I tried defining a function

-- | Create random bitmask
randomMask :: Int64 -> TF.Shape -> TF.Build (TF.Tensor TF.Value Float)
randomMask (TF.Shape shape) =
    TF.round (TF.randomUniform (TF.vector shape))

to sample a random bitmask. However, I'm getting the error

    /home/rbharath/tensorflow-haskell/tensorflow-mnist/app/MainWithDropout.hs:49:5:
        Not in scope: ‘TF.round’
        Perhaps you meant one of these:
          ‘TF.run’ (imported from TensorFlow.Core),
          ‘TF.run_’ (imported from TensorFlow.Core)
    
    /home/rbharath/tensorflow-haskell/tensorflow-mnist/app/MainWithDropout.hs:49:15: Not in scope: ‘TF.randomUniform’

Tensorflow's python API exports tf.round and tf.random_uniform. The existing MNIST example uses TF.truncateNormal as well. What would be the best way for me to surface round and random_uniform from the underlying tensorflow? (Or is my approach here wrong entirely? I don't understand this codebase well, so any general pointers much appreciated :-))

Failed to load interface for ‘TensorFlow.Minimize’

I created a new project via stack new tensorshell and then added the tensorflow-* libraries to stack.yaml and the tensorshell.cabal file in hopes of being able to run the example program from the README which I pasted in unchanged as RegTest.hs here.

The project and dependencies build and install but compiling RegTest.hs gives me:

src/RegTest.hs:9:1-45: error: …
    Failed to load interface for ‘TensorFlow.Minimize’
    Use -v to see a list of the files searched for.
Compilation failed.

And I can't autocomplete Tensor.M... in GHCI. I can see that [Minimize.hs is here] in master but not in release-1.0.2. I tried changing the reference in stack.yaml to point to a local checkout of master but then I get:

Preprocessing library tensorflow-ops-0.1.0.0...
[1 of 7] Compiling TensorFlow.Queue ( src/TensorFlow/Queue.hs, .stack-work/dist/x86_64-osx/Cabal-1.24.2.0/build/TensorFlow/Queue.o )
[2 of 7] Compiling TensorFlow.Ops   ( src/TensorFlow/Ops.hs, .stack-work/dist/x86_64-osx/Cabal-1.24.2.0/build/TensorFlow/Ops.o )

/Users/john/src/tensorflow-haskell/tensorflow-ops/src/TensorFlow/Ops.hs:249:67: error:
    • Could not deduce (Rendered v)
        arising from a use of ‘renderedOutput’
      from the context: (Rendered (Tensor v), MonadBuild m, TensorType a)
        bound by the type signature for:
                   save :: (Rendered (Tensor v), MonadBuild m, TensorType a) =>
                           ByteString -> [Tensor v a] -> m ControlNode
        at src/TensorFlow/Ops.hs:(244,1)-(247,24)
      Possible fix:
        add (Rendered v) to the context of
          the inferred type of
          toByteStringTensor :: Tensor v a1 -> Tensor Build ByteString
          or the type signature for:
               save :: (Rendered (Tensor v), MonadBuild m, TensorType a) =>
                       ByteString -> [Tensor v a] -> m ControlNode
    • In the second argument of ‘(.)’, namely ‘renderedOutput’
      In the second argument of ‘(.)’, namely
        ‘encodeOutput . renderedOutput’
      In the second argument of ‘(.)’, namely
        ‘encodeUtf8 . encodeOutput . renderedOutput’

--  While building package tensorflow-ops-0.1.0.0 using:
      /Users/john/.stack/setup-exe-cache/x86_64-osx/Cabal-simple_mPHDZzAJ_1.24.2.0_ghc-8.0.2 --builddir=.stack-work/dist/x86_64-osx/Cabal-1.24.2.0 build lib:tensorflow-ops --ghc-options " -ddump-hi -ddump-to-file"
    Process exited with code: ExitFailure 1

Presumably because some versions of the other tensorflow packages are now out of sync with master. Is there a known good combination that I can use to get the example working in GHCI (and ultimately hopefully in IHaskell)?

Thanks.

Include haskell source location in error messages

Many times errors from the underlying tensorflow implementation refer to the names of op nodes and it isn't obvious what haskell code generated those nodes. withNameScope can be used to help find the offending nodes, but that technique isn't ideal.

One idea is to record the line number (or entire call stack) for every node we create, then, when an error occurs we can attempt to parse the node names out of the error message and display their locations alongside the original error. If parsing the error message is too difficult, maybe we can dump the entire mapping to a log file on error.

Another idea is to expand the tensorflow C API to allow some metadata to be passed along with each node. When an error occurs, the metadata for the relevant nodes would be included.

Unit-test the sdist installation

I accidentally uploaded to Hackage a version of the tensorflow library (0.1.0.0) which didn't actually build since it didn't include its c_api.h file. We can make our unit tests check this by running sdist t and then cabal install-ing the resulting tarballs. (proto-lens takes this approach, as do some other packages.)

git not on docker image results in inability to build

i'm not quite sure why this doesn't seem to affect other people, but when i try and include this project as a package of another project, it fails when i build because git doesn't exist in the docker image

this is the error commercialhaskell/stack#3196 (i reported it to stack a while ago, but they pointed out that it was "by design").

it would be good if we could put git into the standard docker image (tensorflow/haskell:v0) so that it can be included easily.

thoughts?

(OSX Sierra) Unable to build due to snappy-framing-0.1.1 and proto-lens-protobuf-types-0.2.1.0 dependencies

Error messages:

--  While building package proto-lens-protobuf-types-0.2.1.0 using:.....
    [1 of 2] Compiling Main             ( /private/var/folders/8_/t6lgx6qd6wd2fzqmphvw00k40000gn/T/stack7708/proto-lens-protobuf-types-0.2.1.0/Setup.hs, /private/var/folders/8_/t6lgx6qd6wd2fzqmphvw00k40000gn/T/stack7708/proto-lens-protobuf-types-0.2.1.0/.stack-work/dist/x86_64-osx/Cabal-1.24.2.0/setup/Main.o )
    
    /private/var/folders/8_/t6lgx6qd6wd2fzqmphvw00k40000gn/T/stack7708/proto-lens-protobuf-types-0.2.1.0/Setup.hs:1:1: error:
        Failed to load interface for ‘Data.ProtoLens.Setup’
        There are files missing in the ‘proto-lens-protoc-0.2.1.0’ package,
        try running 'ghc-pkg check'.
        Use -v to see a list of the files searched for.

...................

    Preprocessing library tensorflow-records-0.1.0.0...
    [1 of 2] Compiling TensorFlow.CRC32C ( src/TensorFlow/CRC32C.hs, .stack-work/dist/x86_64-osx/Cabal-1.24.2.0/build/TensorFlow/CRC32C.o ) [Data.Digest.CRC32C changed]
    
    /Users/user/hs/tf/tensorflow-records/src/TensorFlow/CRC32C.hs:28:1: error:
        Failed to load interface for ‘Data.Digest.CRC32C’
        There are files missing in the ‘snappy-framing-0.1.1’ package,
        try running 'ghc-pkg check'.
        Use -v to see a list of the files searched for.

Avoid unnecessary copies when fetching

Currently, to work around #92, we may do multiple unnecessary copies when fetching the result of a computation. (See also discussion in the PR #108.)

If the output type requires a copy anyway (e.g. [Int64] or Data.Unboxed.Vector Float), then that change caused the data to be copied twice: once to get a `Storable.Vector, and once to get the final type.

Instead, TensorData itself could wrap an S.IOVector instead of an S.Vector, and the Fetchable action could run in IO to extract the final type (with special logic for each type's instance to decide how much copying to do).

Native installation on Linux (Fedora)?

Hi,

I see you have installation instructions either using docker or native MacOS X - is a native install on Linux distros supported, too? And would you happen to have instructions for that?

Many thanks
Sigrid

build for ghci fails

running stack ... ghci i get:

> stack --docker --docker-image=$IMAGE_NAME ghci                                                                            
tensorflow-ops-0.1.0.0: initial-build-steps (lib)
Log files have been written to: /home/noon/dev/tensorflow-haskell/.stack-work/logs/
             
Error: singleBuild: invariant violated, missing package ID missing
             
Warning: Build failed, but optimistically launching GHCi anyway

the resulting ghci that loads up is quite broken. trying to do any operations with the library gives

gcc: error: /tmp/ghc80_0/ghc_49.o: No such file or directory
phase `Linker' failed (exitcode = 1)

i think this might be something quite simple, but just noting it down as i don't have time to fix it right now.

Implement some of the python training/optimization functions

there are many nice functions from <tf-source>/python/training that it would be great to have (I'm particularly interested in the adam optimizer, but eventually we'd transfer them all across)

is there some better plan than just porting them?

it might be useful to plan out an interface a bit, because most of them are stateful, and it would be nice to have a clean interaction with sessions.

thoughts?

Consolidate the packages

#111 started consolidating some packages; see also discussion in #66. We should consider doing this further, perhaps:

  • merge tensorflow-logging into tensorflow
  • merge tensorflow-opgen and/or tensorflow-proto into tensorflow

There's some concerns around adding extra dependencies to the merged packages; I haven't thought it through completely.

"embedding_lookup" appears to be broken, maybe missing some reshaping?

i've been trying to use this function in some model, but i think it's broken. i'm trying to fix it, but i might not have time today, so i want to note it.

there appear to be a few problems:

  1. we could add the special-case for np = 1 that is in the original python (that would actually probably fix the problem i'm facing right now)

  2. in embeddingLookup the dynamicPartition operation fails for me with:

TensorFlowException TF_INVALID_ARGUMENT: "data.shape must start with partitions.shape, got data.shape = [12000], partitions.shape = [100,120,1] ..."

i believe this is because we are missing reshaping ids to the ids to get the flatIds that is in the python.

  1. we're missing a bunch of reshaping at the end

i believe this is just simply missing from the implementation in the haskell code here, compared to the python: https://github.com/tensorflow/tensorflow/blob/master/tensorflow/python/ops/embedding_ops.py#L160

maybe it's missing because we don't have any of the framework/tensor_shape.py code.

i think to fix this we should probably add some tests. when i get some time i might port some of the python ones again, and hopefully identify some actual problems that way.

Monad transformer version of Session

It would be useful to have a SessionT as well, such that we can run the TensorFlow operations in any monad with a MonadIO instance instead of just IO itself.

building `tensorflow-core-ops` broken by some recent change ..

(hey all, sorry i've been ignoring comments on PRs for a few days; i've been moving house!)

when trying to build the master branch from scratch i now get:

> stack --docker --docker-image=$IMAGE_NAME build                                                                                                                                         1 ↵
tensorflow-core-ops-0.1.0.0: configure (lib)
Log files have been written to: /home/noon/dev/ext/tensorflow-haskell/.stack-work/logs/
Progress: 1/5
--  While building package tensorflow-core-ops-0.1.0.0 using:
      /home/noon/.stack/programs/x86_64-linux-dkd1ce2ff9c9560b648268df668d177711/ghc-7.10.3/bin/ghc --make -odir /home/noon/dev/ext/tensorflow-haskell/tensorflow-core-ops/.stack-work/dist/x86_64-linux-dkd1ce2ff9c9560b648268df668d177711/Cabal-1.22.5.0/setup -hidir /home/noon/dev/ext/tensorflow-haskell/tensorflow-core-ops/.stack-work/dist/x86_64-linux-dkd1ce2ff9c9560b648268df668d177711/Cabal-1.22.5.0/setup -i -i. -clear-package-db -global-package-db -package-db=/home/noon/.stack/snapshots/x86_64-linux-dkd1ce2ff9c9560b648268df668d177711/lts-6.2/7.10.3/pkgdb -package-db=/home/noon/dev/ext/tensorflow-haskell/.stack-work/install/x86_64-linux-dkd1ce2ff9c9560b648268df668d177711/lts-6.2/7.10.3/pkgdb -hide-all-packages -package=Cabal-1.22.5.0 -package-id=array-0.5.1.0-960bf9ae8875cc30355e086f8853a049 -package-id=base-4.8.2.0-0d6d1084fbc041e1cded9228e80e264d -package-id=bin-package-db-0.0.0.0-c2998655922e5892be4d23c583233dd1 -package-id=binary-0.7.5.0-bf6a937522bb8cec5d00218470f28789 -package-id=bytestring-0.10.6.0-9a873bcf33d6ce2fd2698ce69e2c1c66 -package-id=containers-0.5.6.2-59326c33e30ec8f6afd574cbac625bbb -package-id=deepseq-1.4.1.1-614b63b36dd6e29d2b35afff57c25311 -package-id=directory-1.2.2.0-660a7a83a753ed85c8a374c15dae2b97 -package-id=filepath-1.4.0.0-f97d1e4aebfd7a03be6980454fe31d6e -package-id=ghc-prim-0.4.0.0-6cdc86811872333585fa98756aa7c51e -package-id=haskeline-0.7.2.1-ee66b80ab55ef13718feae46e4940f5d -package-id=hoopl-3.10.0.2-e1d2f66d9c173061362d378e84471a99 -package-id=hpc-0.6.0.2-a33eebda3a4ae222891fd5d14c4f2b1f -package-id=integer-gmp-1.0.0.0-3c8c40657a9870f5c33be17496806d8d -package-id=lens-family-1.2.0-2ee1455711f137e5934d52960f7c8de9 -package-id=mainland-pretty-0.4.1.4-50285c86e8742407fa4c6ab802a9fa2c -package-id=pretty-1.1.2.0-5cc412214ea63f61ee84c4fbabdbe0ec -package-id=process-1.2.3.0-a22328103774f0499a990653944cbf99 -package-id=proto-lens-0.1.0.4-8f71435f97cecb0d4abb0e4f05221e76 -package-id=template-haskell-2.10.0.0-3c4cb52230f347282af9b2817f013181 -package-id=tensorflow-0.1.0.0-e20ca24aee7f264ccc7941a1a0f7cec4 -package-id=tensorflow-opgen-0.1.0.0-bacacaf1d71fc43e6d64d7edd8d7aed1 -package-id=terminfo-0.4.0.1-ff5b3d5838955b7711e16ccc720f06f4 -package-id=text-1.2.2.1-f5b1651133426aa2c83c19d64d248779 -package-id=time-1.5.0.1-1b9a502bb07a3e6f4d6935fbf9db7181 -package-id=transformers-0.4.2.0-81450cd8f86b36eaa8fa0cbaf6efc3a3 -package-id=unix-2.7.1.0-bb54ee8f9f6b2600aae7a748eb88a610 -package-id=xhtml-3000.2.1-e005917157f780654d68110616d034e8 /home/noon/dev/ext/tensorflow-haskell/tensorflow-core-ops/Setup.hs /home/noon/.stack/setup-exe-src/setup-shim-mPHDZzAJ.hs -main-is StackSetupShim.mainOverride -o /home/noon/dev/ext/tensorflow-haskell/tensorflow-core-ops/.stack-work/dist/x86_64-linux-dkd1ce2ff9c9560b648268df668d177711/Cabal-1.22.5.0/setup/setup -threaded
    Process exited with code: ExitFailure 1
    Logs have been written to: /home/noon/dev/ext/tensorflow-haskell/.stack-work/logs/tensorflow-core-ops-0.1.0.0.log

    Linking /home/noon/dev/ext/tensorflow-haskell/tensorflow-core-ops/.stack-work/dist/x86_64-linux-dkd1ce2ff9c9560b648268df668d177711/Cabal-1.22.5.0/setup/setup ...
    /home/noon/dev/ext/tensorflow-haskell/.stack-work/install/x86_64-linux-dkd1ce2ff9c9560b648268df668d177711/lts-6.2/7.10.3/lib/x86_64-linux-ghc-7.10.3/tensorflow-0.1.0.0-GSrYl0vSuJ3KqlFS0XZj4L/libHStensorflow-0.1.0.0-GSrYl0vSuJ3KqlFS0XZj4L.a(Raw.o):(.text+0x1d90): undefined reference to `TF_DeleteDeprecatedSession'
    /home/noon/dev/ext/tensorflow-haskell/.stack-work/install/x86_64-linux-dkd1ce2ff9c9560b648268df668d177711/lts-6.2/7.10.3/lib/x86_64-linux-ghc-7.10.3/tensorflow-0.1.0.0-GSrYl0vSuJ3KqlFS0XZj4L/libHStensorflow-0.1.0.0-GSrYl0vSuJ3KqlFS0XZj4L.a(Raw.o):(.text+0x1f28): undefined reference to `TF_CloseDeprecatedSession'
    /home/noon/dev/ext/tensorflow-haskell/.stack-work/install/x86_64-linux-dkd1ce2ff9c9560b648268df668d177711/lts-6.2/7.10.3/lib/x86_64-linux-ghc-7.10.3/tensorflow-0.1.0.0-GSrYl0vSuJ3KqlFS0XZj4L/libHStensorflow-0.1.0.0-GSrYl0vSuJ3KqlFS0XZj4L.a(Raw.o):(.text+0x20c0): undefined reference to `TF_NewDeprecatedSession'

i believe this isn't being caught by the CI because that uses a different docker base. (it's not clear to me why that is, of course, and i don't think i can see those images on docker hub for whatever reason). that is, i successfully ran ./ci_build/outer_launch_tests.sh on my machine.

TensorFlowException TF_INVALID_ARGUMENT "No OpKernel was registered to support Op 'Reshape' with these attrs.

I can't get reshape to work. In the tensorflow-mnist example (https://github.com/tensorflow/haskell/blob/master/tensorflow-mnist/app/Main.hs) if I replace

let hiddenZ = (images `TF.matMul` hiddenWeights) `TF.add` hiddenBiases

with

let hiddenZ = ((TF.reshape images (TF.vector [batchSize, numPixels])) `TF.matMul` hiddenWeights) `TF.add` hiddenBiases

(which should have no effect because the shape is the same), I get the following error.

Main: TensorFlowException TF_INVALID_ARGUMENT "No OpKernel was registered to support Op 'Reshape' with these attrs.  Registered devices: [CPU], Registered kernels:\n  device='GPU'; T in [DT_COMPLEX128]; Tshape in [DT_INT32]\n  device='GPU'; T in [DT_COMPLEX64]; Tshape in [DT_INT32]\n  device='GPU'; T in [DT_INT8]; Tshape in [DT_INT32]\n  device='GPU'; T in [DT_UINT8]; Tshape in [DT_INT32]\n  device='GPU'; T in [DT_INT16]; Tshape in [DT_INT32]\n  device='GPU'; T in [DT_UINT16]; Tshape in [DT_INT32]\n  device='GPU'; T in [DT_INT64]; Tshape in [DT_INT32]\n  device='GPU'; T in [DT_DOUBLE]; Tshape in [DT_INT32]\n  device='GPU'; T in [DT_FLOAT]; Tshape in [DT_INT32]\n  device='GPU'; T in [DT_HALF]; Tshape in [DT_INT32]\n  device='CPU'; Tshape in [DT_INT32]\n\n\t [[Node: Reshape_27 = Reshape[T=DT_FLOAT, Tshape=DT_INT64](Placeholder_0:0, Const_26:0)]]"
Process exited with ExitFailure 1: /home/optml/holdenl/tensorflow-haskell/.stack-work/install/x86_64-linux-dkd1ce2ff9c9560b648268df668d177711/lts-6.2/7.10.3/bin/Main

Building .dylib on osx?

The build instructions for osx produce a shared object .so file but this extension is not resolved by stack when trying to link the tensorflow project as a local dependency. (It looks like the .so format may not play nicely with stack on osx.) Is there a way to create a .dylib target and build that instead? References here and here

Problem running GPU sessions concurrently

Using the procedure outlined in #157 I try to run two experiments concurrently using Control.Concurrent.Async.concurrently experiment1 experiment2

I log summaries to different filenames.

Running the experiments infividually works fine, but concurrently, various problems occur:

Sometimes I get:

I tensorflow/core/common_runtime/gpu/gpu_device.cc:975] Creating TensorFlow device (/gpu:0) -> (device: 0, name: GeForce GTX 1070, pci bus id: 0000:01:00.0)
I tensorflow/core/common_runtime/gpu/gpu_device.cc:975] Creating TensorFlow device (/gpu:0) -> (device: 0, name: GeForce GTX 1070, pci bus id: 0000:01:00.0)
W tensorflow/core/framework/op_kernel.cc:993] Invalid argument: Infinity in summary histogram for: DecoderDecoder/HistogramSummary_193
         [[Node: DecoderDecoder/HistogramSummary_193 = HistogramSummary[T=DT_FLOAT, _device="/job:localhost/replica:0/task:0/cpu:0"](DecoderDecoder/Const_192, DecoderDecoder/ReadVariableOp_186)]]

Other times:

I tensorflow/core/common_runtime/gpu/gpu_device.cc:975] Creating TensorFlow device (/gpu:0) -> (device: 0, name: GeForce GTX 1070, pci bus id: 0000:01:00.0)
I tensorflow/core/common_runtime/gpu/gpu_device.cc:975] Creating TensorFlow device (/gpu:0) -> (device: 0, name: GeForce GTX 1070, pci bus id: 0000:01:00.0)
E tensorflow/stream_executor/cuda/cuda_event.cc:49] Error polling for event status: failed to query event: CUDA_ERROR_ILLEGAL_ADDRESS
F tensorflow/core/common_runtime/gpu/gpu_event_mgr.cc:198] Unexpected Event status: 1
E tensorflow/stream_executor/cuda/cuda_event.cc:49] Error polling for event status: failed to query event: CUDA_ERROR_ILLEGAL_ADDRESS
F tensorflow/core/common_runtime/gpu/gpu_event_mgr.cc:198] Unexpected Event status: 1

Where the program aborts (I was running in ghci, but this problem killed even ghci)

I do use a wrapper around runSession to allow sharing of the GPU memory like this:
TF.runSessionWithOptions (def & TF.sessionConfig .~ (def & TF.gpuOptions .~ (def & TF.allowGrowth .~ True))) so I don't think this is about memory allocation.

`master` doesn't compile

The docker image builds fine, but a stack ... build fails with:

tensorflow-proto-0.1.0.0: build
WARNING: filepath wildcard '../third_party/tensorflow/tensorflow/core/framework/*.proto' does not match any files.
Warning: File listed in tensorflow-proto/tensorflow-proto.cabal file does not exist: ../third_party/tensorflow/tensorflow/core/protobuf/config.proto
Progress: 65/72
--  While building package tensorflow-proto-0.1.0.0 using:
      /home/colin/code/haskell/tensorflow/tensorflow-proto/.stack-work/dist/x86_64-linux-dk2c39bc19b761ac36dc046245d1d47fe6/Cabal-1.22.5.0/setup/setup --builddir=.stack-work/dist/x86_64-linux-dk2c39bc19b761ac36dc046245d1d47fe6/Cabal-1.22.5.0 build lib:tensorflow-proto --ghc-options " -ddump-hi -ddump-to-file"
    Process exited with code: ExitFailure 1
    Logs have been written to: /home/colin/code/haskell/tensorflow/.stack-work/logs/tensorflow-proto-0.1.0.0.log

    [1 of 1] Compiling Main             ( /home/colin/code/haskell/tensorflow/tensorflow-proto/Setup.hs, /home/colin/code/haskell/tensorflow/tensorflow-proto/.stack-work/dist/x86_64-linux-dk2c39bc19b761ac36dc046245d1d47fe6/Cabal-1.22.5.0/setup/Main.o )
    Linking /home/colin/code/haskell/tensorflow/tensorflow-proto/.stack-work/dist/x86_64-linux-dk2c39bc19b761ac36dc046245d1d47fe6/Cabal-1.22.5.0/setup/setup ...
    Configuring tensorflow-proto-0.1.0.0...
    Warning: 'extra-src-files:
    ../third_party/tensorflow/tensorflow/core/framework/*.proto' is a relative
    path outside of the source tree. This will not work when generating a tarball
    with 'sdist'.
    Warning: 'extra-src-files:
    ../third_party/tensorflow/tensorflow/core/protobuf/config.proto' is a relative
    path outside of the source tree. This will not work when generating a tarball
    with 'sdist'.
    setup: ./../third_party/tensorflow/tensorflow/core/framework/: does not exist

`stack --docker --docker-image=$IMAGE_NAME setup` fails with FailedConnectionException2

Setup fails on

sudo stack --docker --docker-image=$IMAGE_NAME setup

with

FailedConnectionException2 "raw.githubusercontent.com" 443 True getProtocolByName: does not exist (no such protocol name: tcp)

I'm running on Linux. Output of uname -a:

Linux valiant 4.4.0-62-generic #83-Ubuntu SMP Wed Jan 18 14:10:15 UTC 2017 x86_64 x86_64 x86_64 GNU/Linux

See also NixOS/nixpkgs#15168 and NixOS/nixpkgs#18038. (I don't have the background to understand what's going on there.)

implement `numOutputs` for `biasAdd`

this function fails with:

numOuputs not implemented for "BiasAdd"

when you try and use it anywhere, such as

...
conv `TFC.biasAdd` (TF.readValue convBias)

missing a bunch of the "classification" functions

from here: https://www.tensorflow.org/versions/r0.11/api_docs/python/nn.html#classification

i.e. i'd like sigmoid_cross_entropy_with_logits, it's not there

glancing around it appears that there are many ops that are in tensorflow/python/ops/nn.py that aren't defined here; i guess because they can't be straightfowardly gen'd like the ones in nn_ops.py.

do the maintainers have some sort of plan for these? or should I just go about adding them as PRs as i happen on ones I care about?

Parse Error on Core.hs

I'm trying to build the repo using the instructions in README.md. However, I'm getting the following error:

rbharath@tensorbr0:~/tensorflow-haskell$ sudo stack --docker --docker-image=$IMAGE_NAME test --allow-different-user
tensorflow-core-ops-0.1.0.0: configure (lib)
tensorflow-0.1.0.0: test (suite: FFITest)
tensorflow-0.1.0.0: test (suite: VarIntTest)
tensorflow-core-ops-0.1.0.0: build (lib)
Log files have been written to: /home/rbharath/tensorflow-haskell/.stack-work/logs/
Progress: 2/10
--  While building package tensorflow-core-ops-0.1.0.0 using:
      /home/rbharath/tensorflow-haskell/tensorflow-core-ops/.stack-work/dist/x86_64-linux-dkd1ce2ff9c9560b648268df668d177711/Cabal-1.22.5.0/setup/setup --builddir=.stack-work/dist/x86_64-linux-dkd1ce2ff9c9560b648268df668d177711/Cabal-1.22.5.0 build lib:tensorflow-core-ops --ghc-options " -ddump-hi -ddump-to-file"
    Process exited with code: ExitFailure 1
    Logs have been written to: /home/rbharath/tensorflow-haskell/.stack-work/logs/tensorflow-core-ops-0.1.0.0.log

    Configuring tensorflow-core-ops-0.1.0.0...
    Preprocessing library tensorflow-core-ops-0.1.0.0...
    [1 of 1] Compiling TensorFlow.GenOps.Core ( .stack-work/dist/x86_64-linux-dkd1ce2ff9c9560b648268df668d177711/Cabal-1.22.5.0/build/autogen/TensorFlow/GenOps/Core.hs, .stack-work/dist/x86_64-linux-dkd1ce2ff9c9560b648268df668d177711/Cabal-1.22.5.0/build/TensorFlow/GenOps/Core.o )
    
    /home/rbharath/tensorflow-haskell/tensorflow-core-ops/.stack-work/dist/x86_64-linux-dkd1ce2ff9c9560b648268df668d177711/Cabal-1.22.5.0/build/autogen/TensorFlow/GenOps/Core.hs:6766:34:
        parse error on input ‘{’

Has anyone seen a similar failure before? I'm on an Ubuntu 16.04 machine.

Control flow api is a bit opaque

I've perused the python source and I believe I follow most of the dataflow concepts surrounding exit, enter, merge, swtich, nextIteration, etc, but I don't understand how they correspond to what is currently exposed in the haskell api. Are there some code/examples/docs somewhere? How does one get access to frames or their names?

Virtual memory exhausted building in docker - update instructions?

There might be some docker-tuning that needs to be mentioned in README.md.

        ... 179 more jobs
____[1,760 / 2,373] Compiling tensorflow/core/kernels/matching_files_op.cc
ERROR: /tensorflow/tensorflow/core/kernels/BUILD:76:1: C++ compilation of rule '//tensorflow/core/kernels:strided_slice_op' failed: gcc failed: error executing command /usr/bin/gcc -U_FORTIFY_SOURCE '-D_FORTIFY_SOURCE=1' -fstack-protector -Wall -Wl,-z,-relro,-z,now -B/usr/bin -B/usr/bin -Wunused-but-set-parameter -Wno-free-nonheap-object -fno-canonical-system-headers ... (remaining 106 argument(s) skipped): com.google.devtools.build.lib.shell.BadExitStatusException: Process exited with status 1.
virtual memory exhausted: Cannot allocate memory
____Building complete.
Target //tensorflow:libtensorflow_c.so failed to build
Use --verbose_failures to see the command lines of failed build steps.
____Elapsed time: 974.415s, Critical Path: 907.05s

implement conv2d with the ability to specify the strides

for reasons unknown to me, the one in GenOps doesn't allow strides to be specified directly.

here's my version that works (i'll add it via a PR with some tests):

conv2D :: forall v1 v2 t m . ( TF.MonadBuild m
                             , TF.TensorType t
                             , TF.TensorKind v1
                             , TF.TensorKind v2
                             , TF.Rendered (TF.Tensor v1)
                             , TF.OneOf '[Data.Word.Word16, Double, Float] t)
       => TF.Tensor v1 t     -- ^ __input__
       -> TF.Tensor v2 t     -- ^ __filter__
       -> [Int64]            -- ^ __strides__
       -> m (TF.Tensor v1 t) -- ^ __output__
conv2D input filter strides = TF.build $ do
    inputs  <- TF.buildInputs input
    filters <- TF.buildInputs filter
    TF.buildOp [] $ TF.opDef "Conv2D"
                    & TF.opAttr "T"           .~ TF.tensorType (undefined :: t)
                    & TF.opAttr "strides"     .~ strides
                    & TF.opAttr "padding"     .~ ("SAME" :: ByteString)
                    & TF.opAttr "data_format" .~ ("NHWC" :: ByteString)
                    & TF.opInputs             .~ (inputs ++ filters)

Move node to device?

If I have the the following expression:

[...]
let deadSoon = x ``TF.add`` y
let out = deadSoon ``TF.add`` z
[...]

Is it possible to move deadSoon to another device after the computation of out? If so, and this is a forward pass, will back propagation of the graph move deadSoonor will there be some sort of temp device transfer each time deadSoon is needed?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.