1
0
Fork 0
mirror of https://github.com/tensorflow/haskell.git synced 2024-11-05 10:39:44 +01:00
Commit graph

27 commits

Author SHA1 Message Date
fkm3
a86d424cac Add initializedValue function for Variable (#124) 2017-05-20 21:42:45 -07:00
fkm3
b86945f008 Support Variable in TensorFlow.Gradient and use in mnist example (#116) 2017-05-17 13:20:51 -07:00
fkm3
ddb4fe4f90 Add ToTensor class 2017-05-16 23:05:33 -07:00
fkm3
0f04e5a50d Expand Rendered class to support ResourceHandle wrappers like Variable
This allows functions like `feed`, `colocateWith`, and (in a later commit)
`gradients` to work with `Variable`.
2017-05-15 19:55:34 -07:00
Judah Jacobson
64971c876a Consolidate some packages. (#111)
- Merge tensorflow-nn and tensorflow-queue into tensorflow-ops.
  They don't add extra dependencies and each contain a single module, so I
  don't think it's worth separating them at the package level.
- Remove google-shim in favor of direct use of test-framework.
2017-05-10 15:26:03 -07:00
Jarl Christian Berentsen
37e3c9b084 Whitespace 2017-05-05 16:49:27 -07:00
Jarl Christian Berentsen
d153d0aded Fixed matMul gradients for transposed arguments 2017-05-05 16:49:27 -07:00
Jarl Christian Berentsen
51014a015c Implemented TileGrad
Some notes about static shape inference
2017-05-05 16:49:27 -07:00
Jarl Christian Berentsen
97b4bb5bab Added reduceSum to Ops 2017-05-05 16:49:27 -07:00
Christian Berentsen
eca4ff8981 Implemented ReluGradGrad and FillGrad (#102)
Added testReluGrad, testReluGradGrad and testFillGrad
2017-04-30 11:18:06 -07:00
Judah Jacobson
51c883684b Clarify the behavior of readValue in a comment. (#99)
Also add a unit test corresponding to that comments' example code.
2017-04-16 15:31:26 -07:00
Judah Jacobson
42f4fc647e Add resource-based variable ops. (#98)
The main difference between these and the `Ref`-bases ops is the explicit
`readValue` op.  I'm not sure how this should interact with gradients
and save/restore, so I'm keeping it as a separate module for now.  Once we
figure out the details, we can merge it into `TensorFlow.Ops` and replace
all uses of the old `Ref`-based ops.  (That would also fix #92.)

Also replaces our special case newtype `ResourceHandle` to
`Tensor Value ResourceHandle`, where `ResourceHandle` is the TF proto
corresponding to `DT_RESOURCE`.
2017-04-16 09:24:02 -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
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
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
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
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
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
fkm3
03a3a6d086 Misc MNIST example cleanup (#9)
* Use native oneHot op in the example code. It didn't exist when this was originally written.
* Misc cleanup in MNIST example

- Use unspecified dimension for batch size in model. This simplifies the
  code for the test set.
- Move error rate calculation into model.
2016-10-26 11:14:38 -07:00
Greg Steuck
67690d1499 Initial commit 2016-10-24 19:26:42 +00:00