mxnet
|
Symbol is used to represent dynamically generated symbolic computation graph. More...
#include <symbolic.h>
Classes | |
struct | DataEntry |
an entry that represents output data from a node More... | |
Public Member Functions | |
Symbol | Copy () const |
copy the symbol More... | |
void | Print (std::ostream &os) const |
print the symbol info to output stream. More... | |
std::vector< std::string > | ListArguments () const |
List the arguments names. More... | |
std::vector< std::string > | ListOutputs () const |
std::vector< std::string > | ListAuxiliaryStates () const |
Symbol | operator[] (size_t index) const |
get the index th element from the returned tuple. More... | |
void | Compose (const std::vector< Symbol > &args, const std::string &name) |
Compose the symbol with arguments, this changes current symbol. More... | |
void | Compose (const std::unordered_map< std::string, Symbol > &kwargs, const std::string &name) |
Compose the symbol with arguments, this changes the current symbol. The kwargs passed in can be in-complete,. More... | |
bool | GetName (std::string *out) |
Get name from the symbol. This only works for symbol with outputs from single operators. For grouped sybmbol, an error will be raised. More... | |
void | SetAttr (const std::string &key, const std::string &value) |
set additional attributes of the symbol, This only works for symbol with outputs from single operators. For grouped sybmbol, an error will be raised. More... | |
bool | GetAttr (const std::string &key, std::string *out) |
Get attributes from the symbol. This only works for symbol with outputs from single operators. For grouped sybmbol, an error will be raised. More... | |
std::map< std::string, std::string > | ListAttr () |
Get attribute dictionary from the symbol and all children. Each attribute name is pre-pended with the symbol name. For grouped sybmbol, an error will be raised. More... | |
std::map< std::string, std::string > | ListAttrShallow () |
Get attribute dictionary from the symbol. This only works for symbol with outputs from single operators. For grouped sybmbol, an error will be raised. More... | |
Symbol | operator() (const std::vector< Symbol > &args, const std::string &name) const |
Apply the symbol as a function, compose with arguments. More... | |
Symbol | operator() (const std::unordered_map< std::string, Symbol > &kwargs, const std::string &name) const |
compose with named arguments More... | |
Symbol | GetInternals () const |
Symbol | Grad (const std::vector< std::string > &wrt) const |
get the gradient graph More... | |
bool | InferShape (std::vector< TShape > *arg_shapes, std::vector< TShape > *out_shapes, std::vector< TShape > *aux_shapes, bool partial_infer=false) const |
infer the shapes of outputs and unknown input arguments More... | |
bool | InferShape (const std::unordered_map< std::string, TShape > &known_arg_shapes, std::vector< TShape > *arg_shapes, std::vector< TShape > *out_shapes, std::vector< TShape > *aux_shapes, bool partial_infer=false) const |
infer the shapes by providing shapes of known arguments. More... | |
bool | InferType (std::vector< int > *arg_types, std::vector< int > *out_types, std::vector< int > *aux_types) const |
infer the types of outputs and unknown input arguments More... | |
bool | InferType (const std::unordered_map< std::string, int > &known_arg_types, std::vector< int > *arg_types, std::vector< int > *out_types, std::vector< int > *aux_types) const |
infer the types by providing types of known arguments. More... | |
void | Save (dmlc::JSONWriter *writer) const |
interface for json serialization. More... | |
void | Load (dmlc::JSONReader *reader) |
interface for json serialization. More... | |
size_t | NumOutputs () const |
get number of outputs of this symbol More... | |
Static Public Member Functions | |
static Symbol | Create (OperatorProperty *op) |
create Symbol by wrapping OperatorProperty This function takes the ownership of op More... | |
static Symbol | CreateGroup (const std::vector< Symbol > &symbols) |
create equivalence of symbol by grouping the symbols together More... | |
static Symbol | CreateVariable (const std::string &name) |
create variable symbol node More... | |
Protected Attributes | |
std::vector< DataEntry > | heads_ |
the head nodes of Symbols This head is only effective when More... | |
Friends | |
class | StaticGraph |
let static graph know the contents More... | |
Symbol is used to represent dynamically generated symbolic computation graph.
This class is used as a tool to generate computation graphs(aka. configuration) of the network. Symbol is always composite, the head Node is the output node of the symbol. An atomic symbol can be seen as a special case of the composite symbol with only the head node.
void mxnet::Symbol::Compose | ( | const std::vector< Symbol > & | args, |
const std::string & | name | ||
) |
Compose the symbol with arguments, this changes current symbol.
The positional arguments passed in must be complete(contain all arguments).
args | positional arguments for the symbol |
name | name of returned symbol. |
void mxnet::Symbol::Compose | ( | const std::unordered_map< std::string, Symbol > & | kwargs, |
const std::string & | name | ||
) |
Compose the symbol with arguments, this changes the current symbol. The kwargs passed in can be in-complete,.
The rest of the symbols will remain the same name.
kwargs | keyword arguments for the symbol |
name | name of returned symbol. |
Symbol mxnet::Symbol::Copy | ( | ) | const |
copy the symbol
|
static |
create Symbol by wrapping OperatorProperty This function takes the ownership of op
op | the OperatorProperty of the Operator |
create equivalence of symbol by grouping the symbols together
symbols | list of symbols |
|
static |
create variable symbol node
name | name of the variable |
bool mxnet::Symbol::GetAttr | ( | const std::string & | key, |
std::string * | out | ||
) |
Get attributes from the symbol. This only works for symbol with outputs from single operators. For grouped sybmbol, an error will be raised.
key | Key of the attribute. |
out | the output value of the attribute. |
Symbol mxnet::Symbol::GetInternals | ( | ) | const |
bool mxnet::Symbol::GetName | ( | std::string * | out | ) |
Get name from the symbol. This only works for symbol with outputs from single operators. For grouped sybmbol, an error will be raised.
out | the output value of the name. |
Symbol mxnet::Symbol::Grad | ( | const std::vector< std::string > & | wrt | ) | const |
get the gradient graph
wrt | with respect to the input |
bool mxnet::Symbol::InferShape | ( | std::vector< TShape > * | arg_shapes, |
std::vector< TShape > * | out_shapes, | ||
std::vector< TShape > * | aux_shapes, | ||
bool | partial_infer = false |
||
) | const |
infer the shapes of outputs and unknown input arguments
arg_shapes | the shape of input arguments of the operator this should be of same length as the vector returned by ListArguments in_shape allows unknown elements, which are checked by shape.ndim() == 0. For unknown shapes, InferShape will try to fill in the correct Shape in in_shape For known shapes, InferShape will check shape consistency |
common practice: set the shape of data input, and usually weight's shape can be inferred
out_shapes | Use to store the inferred shapes of outputs. |
aux_shapes | Use to store the inferred shapes of auxiliary states |
partial_infer | Return partially inferred results if true. |
dmlc::Error | if the known arg_shapes are inconsistent. |
bool mxnet::Symbol::InferShape | ( | const std::unordered_map< std::string, TShape > & | known_arg_shapes, |
std::vector< TShape > * | arg_shapes, | ||
std::vector< TShape > * | out_shapes, | ||
std::vector< TShape > * | aux_shapes, | ||
bool | partial_infer = false |
||
) | const |
infer the shapes by providing shapes of known arguments.
known_arg_shapes | map of argument name to shape of arguments with known shapes. |
arg_shapes | used to store inferred shapes of arguments. |
out_shapes | used to store inferred shapes of outputs. |
aux_shapes | Use to store the inferred shapes of auxiliary states |
partial_infer | Return partially inferred results if true. |
dmlc::Error | if the known arg_shapes are inconsistent. |
bool mxnet::Symbol::InferType | ( | std::vector< int > * | arg_types, |
std::vector< int > * | out_types, | ||
std::vector< int > * | aux_types | ||
) | const |
infer the types of outputs and unknown input arguments
arg_types | the type of input arguments of the operator this should be of same length as the vector returned by ListArguments in_type allows unknown elements, which are checked by type.ndim() == 0. For unknown types, Infertype will try to fill in the correct type in in_type For known types, Infertype will check type consistency |
common practice: set the type of data input, and usually weight's type can be inferred
out_types | Use to store the inferred types of outputs. |
aux_types | Use to store the inferred types of auxiliary states |
dmlc::Error | if the known arg_types are inconsistent. |
bool mxnet::Symbol::InferType | ( | const std::unordered_map< std::string, int > & | known_arg_types, |
std::vector< int > * | arg_types, | ||
std::vector< int > * | out_types, | ||
std::vector< int > * | aux_types | ||
) | const |
infer the types by providing types of known arguments.
known_arg_types | map of argument name to type of arguments with known types. |
arg_types | used to store inferred types of arguments. |
out_types | used to store inferred types of outputs. |
aux_types | Use to store the inferred types of auxiliary states |
dmlc::Error | if the known arg_types are inconsistent. |
std::vector<std::string> mxnet::Symbol::ListArguments | ( | ) | const |
List the arguments names.
The position of the returned list also corresponds to calling position in operator()
std::map<std::string, std::string> mxnet::Symbol::ListAttr | ( | ) |
Get attribute dictionary from the symbol and all children. Each attribute name is pre-pended with the symbol name. For grouped sybmbol, an error will be raised.
std::map<std::string, std::string> mxnet::Symbol::ListAttrShallow | ( | ) |
Get attribute dictionary from the symbol. This only works for symbol with outputs from single operators. For grouped sybmbol, an error will be raised.
std::vector<std::string> mxnet::Symbol::ListAuxiliaryStates | ( | ) | const |
std::vector<std::string> mxnet::Symbol::ListOutputs | ( | ) | const |
void mxnet::Symbol::Load | ( | dmlc::JSONReader * | reader | ) |
interface for json serialization.
reader | the JSON read to read json. |
|
inline |
get number of outputs of this symbol
Symbol mxnet::Symbol::operator() | ( | const std::vector< Symbol > & | args, |
const std::string & | name | ||
) | const |
Apply the symbol as a function, compose with arguments.
args | positional arguments for the symbol |
name | name of returned symbol. |
Symbol mxnet::Symbol::operator() | ( | const std::unordered_map< std::string, Symbol > & | kwargs, |
const std::string & | name | ||
) | const |
compose with named arguments
kwargs | keyword arguments for the symbol |
name | name of returned symbol. |
Symbol mxnet::Symbol::operator[] | ( | size_t | index | ) | const |
get the index th element from the returned tuple.
index | index of multi output |
void mxnet::Symbol::Print | ( | std::ostream & | os | ) | const |
print the symbol info to output stream.
os | the output stream we like to print to |
void mxnet::Symbol::Save | ( | dmlc::JSONWriter * | writer | ) | const |
interface for json serialization.
writer | the JSON writer write json. |
void mxnet::Symbol::SetAttr | ( | const std::string & | key, |
const std::string & | value | ||
) |
set additional attributes of the symbol, This only works for symbol with outputs from single operators. For grouped sybmbol, an error will be raised.
key | the key of the attribute |
value | the value of the attribute. |
|
friend |
let static graph know the contents
|
protected |
the head nodes of Symbols This head is only effective when