ONE - On-device Neural Engine
Loading...
Searching...
No Matches
moco::StopGradientGraphBuilder Class Referencefinal

GraphBuilder for StopGradient node. More...

#include <StopGradient.h>

Collaboration diagram for moco::StopGradientGraphBuilder:

Public Member Functions

bool validate (const tensorflow::NodeDef &) const override
 
void build (const tensorflow::NodeDef &, GraphBuilderContext *) const override
 
- Public Member Functions inherited from moco::GraphBuilder
virtual ~GraphBuilder ()
 

Detailed Description

GraphBuilder for StopGradient node.

Definition at line 28 of file StopGradient.h.

Member Function Documentation

◆ build()

void moco::StopGradientGraphBuilder::build ( const tensorflow::NodeDef &  node,
GraphBuilderContext context 
) const
overridevirtual

Implements moco::GraphBuilder.

Definition at line 65 of file StopGradient.cpp.

67{
68 assert(context != nullptr);
69
70 loco::Graph *graph = context->graph();
71 SymbolTable *tensor_names = context->tensor_names();
72 UpdateQueue *updates = context->updates();
73
74 // creating TF dialect StopGradient node
75 auto tf_stopgradient = graph->nodes()->create<TFStopGradient>();
76 tf_stopgradient->name(node.name());
77
78 // register string-name to node
79 TensorName output_name(node.name(), 0);
80 tensor_names->enroll(output_name, tf_stopgradient);
81
82 // Queue node input update
83 auto tf_stopgradient_update =
84 std::make_unique<TFStopGradientGraphUpdate>(tf_stopgradient, TensorName(node.input(0)));
85 updates->enroll(std::move(tf_stopgradient_update));
86}
A neural network graph.
Definition Graph.h:161
Class to store and query loco::Node* with string name key.
void enroll(const TensorName &tensor_name, loco::Node *node)
Registers a name with corresponding loco::Node *.
Class to store GraphUpdate objects.
void enroll(std::unique_ptr< GraphUpdate > &&update)
Registers GraphUpdate objects.
NodeName name(void) const
Definition TFNodeDecl.h:50

References moco::SymbolTable::enroll(), moco::UpdateQueue::enroll(), moco::GraphBuilderContext::graph(), moco::TFNode::name(), moco::GraphBuilderContext::tensor_names(), and moco::GraphBuilderContext::updates().

◆ validate()

bool moco::StopGradientGraphBuilder::validate ( const tensorflow::NodeDef &  node) const
overridevirtual

Implements moco::GraphBuilder.

Definition at line 57 of file StopGradient.cpp.

58{
59 if (node.input_size() != 1)
60 return false;
61
62 return plier::tf::has_attrs(node, {"T"});
63}
bool has_attrs(const tensorflow::NodeDef &node, const std::vector< std::string > &attr_names)
Definition Convert.cpp:35

References plier::tf::has_attrs().


The documentation for this class was generated from the following files: