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 Source
A type of graph node which has no outputs. These nodes are valuable for causing side effects when they are run.
BuildOp ControlNode Source | |
OpResult ControlNode Source | |
Nodes ControlNode Source | |
(~) * a () => Fetchable ControlNode a Source |
Ops
opDefWithName :: PendingNodeName -> OpType -> OpDef Source
The Build monad
data GraphState Source
Monad m => MonadState GraphState (BuildT m) Source |
render :: Tensor v a -> Build (Tensor v a) Source
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.
An action for building nodes in a TensorFlow graph.
Used to manage build state internally as part of the Session
monad.
addInitializer :: ControlNode -> Build () Source
Registers the given node to be executed before the next
run
.
hoistBuildT :: (forall a. m a -> n a) -> BuildT m b -> BuildT n b Source
This is Control.Monad.Morph.hoist sans the dependency.
evalBuildT :: Monad m => BuildT m a -> m a Source
runBuildT :: BuildT m a -> m (a, GraphState) Source
asGraphDef :: Build a -> GraphDef Source
Produce a GraphDef proto representation of the nodes that are rendered in
the given Build
action.
addGraphDef :: GraphDef -> Build () Source
flushInitializers :: Monad m => BuildT m [NodeName] Source
Get all the initializers that have accumulated so far, and clear that buffer.
flushNodeBuffer :: Monad m => BuildT m [NodeDef] Source
Get all the NodeDefs that have accumulated so far, and clear that buffer.
Creating and looking up Ops
getOrAddOp :: Op -> Build NodeName Source
Render the given op if it hasn't been rendered already, and return its name.
addNewOp :: OpDef -> Build NodeDef Source
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 Source
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 Source
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 Source
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 Source
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 Source
Prepend a scope to all nodes rendered in the given Build
action.
withNodeDependencies :: Set NodeName -> Build a -> Build a Source
Add control inputs to all nodes rendered in the given Build
action.
Internal Summary related bits.
addSummary :: SummaryTensor -> Build () Source
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 Source
Synonym for the tensors that return serialized Summary proto.
collectAllSummaries :: Monad m => BuildT m [SummaryTensor] Source
Retrieves the summary ops collected thus far. Typically this only
happens once, but if buildWithSummary
is used
repeatedly, the values accumulate.