1
0
mirror of https://github.com/tensorflow/haskell.git synced 2024-06-02 02:53:35 +02:00
Commit Graph

171 Commits

Author SHA1 Message Date
Judah Jacobson
de16a576da Sort the ops generated in TensorFlow.GenOps.Core. (#96) 2017-04-08 07:15:28 -07:00
Judah Jacobson
55ca545915 Regenerate the Haddock docs. (#95) 2017-04-08 07:14:47 -07:00
Judah Jacobson
16d660c3bc Support a couple more ops by allowing larger tuples. (#93) 2017-04-06 19:00:18 -07:00
Judah Jacobson
d62c614695 Distinguish between "rendered" and "unrendered" Tensors. (#88)
Distinguish between "rendered" and "unrendered" Tensors.

There are now three types of `Tensor`:

- `Tensor Value a`: rendered value
- `Tensor Ref a`: rendered reference
- `Tensor Build a` : unrendered value

The extra bookkeeping makes it easier to track (and enforce) which tensors are
rendered or not.  For examples where this has been confusing in the past, see

With this change, pure ops look similar to before, returning `Tensor Build`
instead of `Tensor Value`.  "Stateful" (monadic) ops are unchanged.  For
example:

    add :: OneOf [..] t => Tensor v'1 t -> Tensor v'2 t -> Tensor Build t
    assign :: (MonadBuild m, TensorType t)
           => Tensor Ref t -> Tensor v'2 t -> m (Tensor Ref t)

The `gradients` function now requires that the variables over which it's
differentiating are pre-rendered:

    gradients :: (..., Rendered v2) => Tensor v1 a -> [Tensor v2 a]
              -> m [Tensor Value a]

(`Rendered v2` means that `v2` is either a `Ref` or a `Value`.)

Additionally, the implementation of `gradients` now takes care to render every
intermediate value when performing the reverse accumulation.  I suspect this
fixes an exponential blowup for complicated expressions.
2017-04-06 15:10:33 -07:00
Chris Mckinlay
d71f48090a call sudo consistently within OSX build script (#91)
previously I was getting the following error:

./: Can't update time for .
tar: Error exit delayed from previous errors.
2017-04-03 20:27:22 -07:00
Judah Jacobson
1f6115da5a Minor fix to codegen of INLINE pragma. (#85) 2017-04-03 20:25:55 -07:00
Judah Jacobson
a11a417ad5 Add another test of CSE and feeds. (#87)
As a follow-up to #86, check that our CSE isn't too aggressive to prevent feeds
of pure ops with distinct names.
2017-03-23 12:58:40 -07:00
Judah Jacobson
fdbfd050f8 Prevent CSE of placeholder ops. (#86)
The bug was introduced in #84.
2017-03-22 22:47:42 -07:00
Judah Jacobson
c99a23b6a7 Add versions of each op that take optional params as an extra arg. (#84)
Each op `foo :: ...` now has a corresponding `foo' :: OpParams -> ...`
which lets you set optional attributes.  `OpParams` is currently a type alias for
`OpDef -> OpDef`.  In the future we should consider more type safety, e.g.,
using type-level strings and OverloadedLabels for optional attributes.

I used it to replace a few manual `buildOp`s in our code with the codegenerated
ops, now that it's easier to set attributes.  I also removed `tensorAttr` and
`named` since it's now possible to set those op attributes directly.

Although this clutters up the API a bit, I think it's simpler than using type
classes to implement optional arguments (as in, for example, `Text.Printf`) --
especially in terms of type inference with the rest of the library.
2017-03-20 18:16:38 -07:00
Judah Jacobson
2c5c879037 Introduce a MonadBuild class, and remove buildAnd. (#83)
This change adds a class that both `Build` and `Session` are instances of:

    class MonadBuild m where
        build :: Build a -> m a

All stateful ops (generated and manually written) now have a signature that returns
an instance of `MonadBuild` (rather than just `Build`).  For example:

    assign_ :: (MonadBuild m, TensorType t)
            => Tensor Ref t -> Tensor v t -> m (Tensor Ref t)

This lets us remove a bunch of spurious calls to `build` in user code.  It also
lets us replace the pattern `buildAnd run foo` with the simpler pattern `foo >>= run`
(or `run =<< foo`, which is sometimes nicer when foo is a complicated expression).

I went ahead and deleted `buildAnd` altogether since it seems to lead to
confusion; in particular a few tests had `buildAnd run . pure` which is
actually equivalent to just `run`.
2017-03-18 12:08:53 -07:00
Judah Jacobson
9209dfc4c4 Support lists of tensors in ops. (#79)
Adds a new type `ListOf` which wraps a heterogeneous list; for example,
`ListOf (Tensor Value) '[Int32, Float]` represents a list of two
elements: a tensor of int32s and a tensor of floats.

Also changes the `Queue2` type (which suppored pairs of tensors) to
`Queue` (which supports arbitrary lists).
2017-03-17 13:53:19 -07:00
avctrh
7cc6a69866 Added installation script for OS X dependencies under tools/ (#80)
* consolidated OS X instructions to the shell script, removed step-by-step instructions from README.md
2017-03-09 16:54:24 -08:00
Greg Steuck
5414f197a1 Update to 1.0 release and newest proto-lens (#77)
* Update from rc to full 1.0 release.
* Switch to proto-lens 0.1.0.5.
2017-02-22 15:24:45 -08:00
Judah Jacobson
0c8d41250a Remove the type parameter from ResourceHandle. (#76)
This change allows us to reenable the rest of the ResourceHandle ops, and
future-proofs us against more being added.  It removes the custom logic that
assumed there was a "dtype" attribute to guess what the type parameter is
(which wasn't true in general.)

When we switch to ResourceHandle (e.g., for queues and variables) we can add
parameters to the wrapper types like "Queue" on a case-by-case basis.
2017-02-21 19:38:26 -08:00
fkm3
b3c0997a8c Add support for logging to tensorboard (#74)
Add support for logging to tensorboard

Based on @gnezdo's internal version with some differences:

* Uses a pure haskell implementation of EventWriter instead of FFI.
* Special `buildAnd*` functions were dropped in favor of using
  `mergeAllSummaries :: Build SummaryTensor` with the normal
  `build` function.
2017-02-20 19:16:42 -08:00
Judah Jacobson
dca49d8993 Update Mac build instructions. (#73)
- Use the prebuilt binaries/headers for TF 1.0rc.
- Add instructions and stack.yaml config for tensorflow-records's dependency on
  snappy.
2017-02-12 22:17:38 -08:00
Andrew Pritchard
65a1220b90 Improve comments and make naming consistent. 2017-02-11 12:53:42 -08:00
fkm3
ce6717a9f8 Use the CRC32C implementation in snappy-framing. 2017-02-11 12:53:42 -08:00
fkm3
02591ca364 Add cabal files and CI setup for TFRecords. 2017-02-11 12:53:42 -08:00
Andrew Pritchard
bf0abd6d82 Add pure-Haskell implementation of TFRecords.
The tensorflow-records package implements encoding/decoding of the
format, and the tensorflow-records-conduit package provides wrappers and
utilities for use with Conduit.
2017-02-11 12:53:42 -08:00
Greg Steuck
72631cb9f3 Uprev to TF 1.0rc1. (#69)
* Download protoc and libtensorflow instead of running bazel.
* Explicitly set permissions of protoc.
2017-02-09 14:20:43 -08:00
Judah Jacobson
4b5a57152f Add instructions to download protoc for building on Mac. (#65) 2017-01-23 09:12:09 -08:00
fkm3
4fb68f3aa3 Add example to README + make haddock link more prominent (#60) 2017-01-16 20:44:45 -08:00
Judah Jacobson
1ffc5c4383 Blacklist some more ops. (#62)
- More heterogeneous list ops
- Resource ops that don't use "dtype" as the type parameter

For the latter, we may need an upstream fix, or else to change the convention
of how we can tell what the type parameter is.
2017-01-15 11:21:09 -08:00
Greg Steuck
56a629f9da Updated TensorFlow. (#58)
* Needed to list a newly added proto in cabal file.
* Update the nightly-devel image before build.
2017-01-01 09:53:00 -08:00
Judah Jacobson
db75350969 Support type attributes that aren't used by an input/output. (#51)
We should treat such attributes as regular `DataType` values rather than type
parameters; otherwise we'll get ambiguous types.  As with other attributes,
they can either set by default or passed in as an explicit argument to the op.

Allows us to reenable a couple more ops.
2016-12-15 11:52:48 -08:00
fkm3
f170df9d13 Support fetching storable vectors + use them in benchmark (#50)
In addition, you can now fetch TensorData directly. This might be useful in
scenarios where you feed the result of a computation back in, like RNN.

Before:

benchmarking feedFetch/4 byte
time                 83.31 μs   (81.88 μs .. 84.75 μs)
                     0.997 R²   (0.994 R² .. 0.998 R²)
mean                 87.32 μs   (86.06 μs .. 88.83 μs)
std dev              4.580 μs   (3.698 μs .. 5.567 μs)
variance introduced by outliers: 55% (severely inflated)

benchmarking feedFetch/4 KiB
time                 114.9 μs   (111.5 μs .. 118.2 μs)
                     0.996 R²   (0.994 R² .. 0.998 R²)
mean                 117.3 μs   (116.2 μs .. 118.6 μs)
std dev              3.877 μs   (3.058 μs .. 5.565 μs)
variance introduced by outliers: 31% (moderately inflated)

benchmarking feedFetch/4 MiB
time                 109.0 ms   (107.9 ms .. 110.7 ms)
                     1.000 R²   (0.999 R² .. 1.000 R²)
mean                 108.6 ms   (108.2 ms .. 109.2 ms)
std dev              740.2 μs   (353.2 μs .. 1.186 ms)

After:

benchmarking feedFetch/4 byte
time                 82.92 μs   (80.55 μs .. 85.24 μs)
                     0.996 R²   (0.993 R² .. 0.998 R²)
mean                 83.58 μs   (82.34 μs .. 84.89 μs)
std dev              4.327 μs   (3.664 μs .. 5.375 μs)
variance introduced by outliers: 54% (severely inflated)

benchmarking feedFetch/4 KiB
time                 85.69 μs   (83.81 μs .. 87.30 μs)
                     0.997 R²   (0.996 R² .. 0.999 R²)
mean                 86.99 μs   (86.11 μs .. 88.15 μs)
std dev              3.608 μs   (2.854 μs .. 5.273 μs)
variance introduced by outliers: 43% (moderately inflated)

benchmarking feedFetch/4 MiB
time                 1.582 ms   (1.509 ms .. 1.677 ms)
                     0.970 R²   (0.936 R² .. 0.993 R²)
mean                 1.645 ms   (1.554 ms .. 1.981 ms)
std dev              490.6 μs   (138.9 μs .. 1.067 ms)
variance introduced by outliers: 97% (severely inflated)
2016-12-14 18:53:06 -08:00
fkm3
91f508eb5c Fix TensorData encode and decode for Bool (#49) 2016-12-12 19:40:32 -08:00
fkm3
cc08520dc7 Fix gradients calculation for min and max (#48) 2016-12-12 09:47:02 -08:00
Judah Jacobson
1539783ee5 Update type constraints to work around a ghc-8 bug. (#47)
Also removes all the ghc-8-specific logic in the .cabal files.

ghc-8 has issues with deeply nested tuples of constraints.  We can
work around it by:
- Changing TensorTypes to a regular class.  This required FlexibleContexts.
  (But we'll probably need it anyway when we support heterogeneous tensor
  lists.)
- Specializing NoneOf for long type lists.

For more details, see: https://ghc.haskell.org/trac/ghc/ticket/12175.

Also added 'directory' to tensorflow-core-ops' dependencies since it's used
in the Setup script.

One more step towards fixing #38.
2016-11-28 21:15:09 -08:00
Judah Jacobson
71bdc6f744 Update haddocks. (#46) 2016-11-23 10:55:35 -08:00
Greg Steuck
455e5a83c9 Add stack resolver version switch (#38). (#45)
The script can now be run with, e.g.
`env STACK_RESOLVER=lts-7.3 ci_build/outer_launch_tests.sh`
and will use the specified version of the resolver.

We can't quite enable this for lts-7.3 as the code is not pedantically
clean. We will reconsider when 8.0.2 is available which removes
`-Wredundant-constraints` from `-Wall`.
2016-11-23 09:47:01 -08:00
Judah Jacobson
5fa1d2ba8f Update OS X instructions (#42) to not require a separate ".so" file. (#44)
The right approach is to run `install_name_tool` on the library after renaming
its extension from ".so" to ".dylib".
2016-11-22 16:15:34 -08:00
Judah Jacobson
eb7e78d60d Add instructions to symlink ".so" to ".dylib" on OS X (#42). (#43)
I'm not sure why, but in some cases it seems linking only works if *both* the
.so and the .dylib are present in /usr/local/lib.  This may be due to a quirk
of how Bazel builds the library, and/or how ghc/stack load the library.
2016-11-22 08:34:59 -08:00
Judah Jacobson
5b4017e31b Fix the build on ghc-8.0.1 (#38). (#40)
Two issues:
- The definition of `\\` was missing parentheses.  It was probably a bug
  that this used to worked in ghc-7.10.
- Set `-fconstraint-solver-iterations=0` to work around
  https://ghc.haskell.org/trac/ghc/ticket/12175.  It looks like we can
  trigger that bug when defining a significantly complicated op.  Specifically,
  our type shenanigans ("OneOf") along with lens setters (for OpDef) seem
  to confuse GHC.

Still TODO: automate testing of different ghc versions to prevent a regression.
2016-11-21 22:20:08 -08:00
Judah Jacobson
cec666e135 Fix Ref and Build semantics for generated code. (#37)
Also:
- Make TensorFlow.Ops.{variable,assign} be the Core generated versions.
- Make ops take "Shape" as mandatory input.
2016-11-21 10:19:15 -08:00
Judah Jacobson
a277c7ddb3 Refactor OpGen. (#36)
Also fixes op lists when the same attribute specifies the length of
both an input and an output.  I added a test of "shapeN" which
previously failed with the following error:

    ERROR: Ran out of counts in toResult. Likely misuse of buildListOp.
2016-11-20 10:00:22 -08:00
Greg Steuck
2b5e41ffeb Make code --pedantic (#35)
* Enforce pedantic build mode in CI.
* Our imports drifted really far from where they should be.
2016-11-18 10:42:02 -08:00
Noon van der Silk
69fdbf677f test case to show can't calculate grad for embedding (and associated fix) (#23)
* Fix for embedding gradient calculation

- Passes vectors instead of scalars to slice
- converts the numRows to a scalar
- add `toScalar` utility function
- minor change to test case so that it actually works

* added lib for testing helper functions

* add flatSlice function
2016-11-17 13:54:36 -08:00
fkm3
fc3d398ca9 Optimize fetching (#27)
* Add MNIST data to gitignore
* Add simple tensor round-trip benchmark
* Use deepseq + cleaner imports
* Use safe version of fromIntegral in FFI code
* Don't copy data when fetching tensors

BEFORE

benchmarking feedFetch/4 byte
time                 55.79 μs   (54.88 μs .. 56.62 μs)
                     0.998 R²   (0.997 R² .. 0.999 R²)
mean                 55.61 μs   (55.09 μs .. 56.11 μs)
std dev              1.828 μs   (1.424 μs .. 2.518 μs)
variance introduced by outliers: 34% (moderately inflated)

benchmarking feedFetch/4 KiB
time                 231.4 μs   (221.9 μs .. 247.3 μs)
                     0.988 R²   (0.974 R² .. 1.000 R²)
mean                 226.6 μs   (224.1 μs .. 236.2 μs)
std dev              13.45 μs   (7.115 μs .. 27.14 μs)
variance introduced by outliers: 57% (severely inflated)

benchmarking feedFetch/4 MiB
time                 485.8 ms   (424.6 ms .. 526.7 ms)
                     0.998 R²   (0.994 R² .. 1.000 R²)
mean                 515.7 ms   (512.5 ms .. 517.9 ms)
std dev              3.320 ms   (0.0 s .. 3.822 ms)
variance introduced by outliers: 19% (moderately inflated)

AFTER

benchmarking feedFetch/4 byte
time                 53.11 μs   (52.12 μs .. 54.22 μs)
                     0.996 R²   (0.995 R² .. 0.998 R²)
mean                 54.64 μs   (53.59 μs .. 56.18 μs)
std dev              4.249 μs   (2.910 μs .. 6.076 μs)
variance introduced by outliers: 75% (severely inflated)

benchmarking feedFetch/4 KiB
time                 83.83 μs   (82.72 μs .. 84.92 μs)
                     0.999 R²   (0.998 R² .. 0.999 R²)
mean                 83.82 μs   (83.20 μs .. 84.35 μs)
std dev              1.943 μs   (1.557 μs .. 2.614 μs)
variance introduced by outliers: 20% (moderately inflated)

benchmarking feedFetch/4 MiB
time                 95.54 ms   (93.62 ms .. 97.82 ms)
                     0.999 R²   (0.998 R² .. 1.000 R²)
mean                 96.61 ms   (95.76 ms .. 97.51 ms)
std dev              1.408 ms   (1.005 ms .. 1.889 ms)
2016-11-17 10:41:49 -08:00
Greg Steuck
c430e54c3c Uprev tensorflow. (#33)
* No longer need to hide ResourceHandle ops
* Blacklisted not supported TensorArrayV2
* Ownership of feed tensors changed (1f0c5119a0230c5160d45496175b9256f097e144)
2016-11-16 21:16:20 -08:00
Greg Steuck
ea9ac9e37c Resolve #30 by using nightly. (#32)
Unfortunately bazel build is notably slower to run.
2016-11-15 16:42:52 -08:00
Greg Steuck
93e27a12c6 Uprev tensorflow. (#29)
Includes temporary blacklisting for a couple of ops that will be
supported once my fix lands in the main tensorflow repo.
2016-11-14 17:04:44 -08:00
Greg Steuck
0d4f5a9628 Added sessionTracer to log graph operations. (#26)
* Added TracingTest.
2016-11-14 15:14:51 -08:00
fkm3
630850c2d2 Add TensorFlow.Core module to start formalizing the exposed API (#17)
* Add TensorFlow.Core module to start formalizing the exposed API

* Refer to ops packages instead of modules
2016-11-10 09:47:41 -08:00
Greg Steuck
9e005e3af7 Merge pull request #22 from tensorflow/embedding-lookup-fix
Embedding lookup fix
2016-11-09 15:59:10 -08:00
Greg Steuck
d9115c716f genericLength is too generic.
Avoid folding in TF.
2016-11-09 14:20:26 -08:00
Greg Steuck
ec5c5228e1 Fixed #19 by adding previously missing reshape.
The comment did say that only flat shapes were supported though.
2016-11-09 11:54:53 -08:00
silky
9c81241439 Tests for "embedding_lookup" and minor fix
- added a test that fails for a partitioned embedding
- added a test that passes for a single embedding
2016-11-09 16:21:40 +11:00
Greg Steuck
4ec78a8fca Replaced topK with topKV2. (#21)
topK is obsolete and generating warnings.
2016-11-08 20:57:22 -08:00