Safe Haskell | None |
---|---|
Language | Haskell2010 |
- newtype ControlNode = ControlNode {
- unControlNode :: Op
- data Unique
- explicitName :: Text -> PendingNodeName
- implicitName :: PendingNodeName
- opDef :: OpType -> OpDef
- opDefWithName :: PendingNodeName -> OpType -> OpDef
- opName :: Lens' OpDef PendingNodeName
- opType :: Lens' OpDef OpType
- opAttr :: Attribute a => Text -> Lens' OpDef a
- opInputs :: Lens' OpDef [Output]
- opControlInputs :: Lens' OpDef [NodeName]
- data GraphState
- render :: Tensor v a -> Build (Tensor v a)
- renderNodeName :: Tensor v a -> Build NodeName
- renderedNodeDefs :: Lens' GraphState (Map NodeName NodeDef)
- data BuildT m a
- type Build = BuildT Identity
- addInitializer :: ControlNode -> Build ()
- hoistBuildT :: (forall a. m a -> n a) -> BuildT m b -> BuildT n b
- evalBuildT :: Monad m => BuildT m a -> m a
- runBuildT :: BuildT m a -> m (a, GraphState)
- asGraphDef :: Build a -> GraphDef
- addGraphDef :: GraphDef -> Build ()
- flushInitializers :: Monad m => BuildT m [NodeName]
- flushNodeBuffer :: Monad m => BuildT m [NodeDef]
- getOrAddOp :: Op -> Build NodeName
- addNewOp :: OpDef -> Build NodeDef
- renderOutput :: Output -> Build Text
- colocateWith :: forall a v b. Tensor v b -> Build a -> Build a
- withStateLens :: MonadState s m => Lens' s a -> (a -> a) -> m b -> m b
- withDevice :: Maybe Device -> Build a -> Build a
- withNameScope :: Text -> Build a -> Build a
- withNodeDependencies :: Set NodeName -> Build a -> Build a
- addSummary :: SummaryTensor -> Build ()
- type SummaryTensor = Tensor Value ByteString
- collectAllSummaries :: Monad m => BuildT m [SummaryTensor]
Graph node types
newtype ControlNode
A type of graph node which has no outputs. These nodes are valuable for causing side effects when they are run.
BuildOp ControlNode | |
OpResult ControlNode | |
Nodes ControlNode | |
(~) * a () => Fetchable ControlNode a |
Ops
explicitName :: Text -> PendingNodeName
opDefWithName :: PendingNodeName -> OpType -> OpDef
opName :: Lens' OpDef PendingNodeName
opControlInputs :: Lens' OpDef [NodeName]
The Build monad
data GraphState
Monad m => MonadState GraphState (BuildT m) |
render :: Tensor v a -> Build (Tensor v a)
Render a Tensor
, fixing its name, scope, device and control inputs from
the Build
context. Also renders any dependencies of the Tensor
that
weren't already rendered.
This operation is idempotent; render >=> render === render
. However,
rendering a (previously un-rendered) Tensor
in two different contexts
may result in two different Tensor
s.
renderNodeName :: Tensor v a -> Build NodeName
Render a Tensor
and get its node's name.
renderedNodeDefs :: Lens' GraphState (Map NodeName NodeDef)
data BuildT m a
An action for building nodes in a TensorFlow graph.
Used to manage build state internally as part of the Session
monad.
addInitializer :: ControlNode -> Build ()
Registers the given node to be executed before the next
run
.
hoistBuildT :: (forall a. m a -> n a) -> BuildT m b -> BuildT n b
This is Control.Monad.Morph.hoist sans the dependency.
evalBuildT :: Monad m => BuildT m a -> m a
runBuildT :: BuildT m a -> m (a, GraphState)
asGraphDef :: Build a -> GraphDef
Produce a GraphDef proto representation of the nodes that are rendered in
the given Build
action.
addGraphDef :: GraphDef -> Build ()
flushInitializers :: Monad m => BuildT m [NodeName]
Get all the initializers that have accumulated so far, and clear that buffer.
flushNodeBuffer :: Monad m => BuildT m [NodeDef]
Get all the NodeDefs that have accumulated so far, and clear that buffer.
Creating and looking up Ops
getOrAddOp :: Op -> Build NodeName
Render the given op if it hasn't been rendered already, and return its name.
addNewOp :: OpDef -> Build NodeDef
Add a new node for a given OpDef
. This is used for making "stateful" ops
which are not safe to dedup (e.g, "variable" and "assign").
renderOutput :: Output -> Build Text
Render an Output
and return a string representation for the TensorFlow
foreign APIs.
Modifying all nodes in a Build action
colocateWith :: forall a v b. Tensor v b -> Build a -> Build a
Places all nodes rendered in the given Build
action on the same
device as the given Tensor (see also withDevice
). Make sure that
the action has side effects of rendering the desired tensors. A pure
return would not have the desired effect.
withStateLens :: MonadState s m => Lens' s a -> (a -> a) -> m b -> m b
Modify some part of the state, run an action, and restore the state after that action is done.
withDevice :: Maybe Device -> Build a -> Build a
Set a device for all nodes rendered in the given Build
action
(unless further overridden by another use of withDevice).
withNameScope :: Text -> Build a -> Build a
Prepend a scope to all nodes rendered in the given Build
action.
withNodeDependencies :: Set NodeName -> Build a -> Build a
Add control inputs to all nodes rendered in the given Build
action.
Internal Summary related bits.
addSummary :: SummaryTensor -> Build ()
Records the given summary action in Build for retrieval with
collectAllSummaries
. The summary op is required to produce a
Summary protocol buffer in string form. For safety, use the
pre-composed functions: Logging.scalarSummary and
Logging.histogramSummary.
type SummaryTensor = Tensor Value ByteString
Synonym for the tensors that return serialized Summary proto.
collectAllSummaries :: Monad m => BuildT m [SummaryTensor]
Retrieves the summary ops collected thus far. Typically this only
happens once, but if buildWithSummary
is used
repeatedly, the values accumulate.