# mxnet.symbol.Symbol.bind¶

Symbol.bind(ctx, args, args_grad=None, grad_req='write', aux_states=None, group2ctx=None, shared_exec=None)[source]

Binds the current symbol to an executor and returns it.

We first declare the computation and then bind to the data to run. This function returns an executor which provides method forward() method for evaluation and a outputs() method to get all the results.

Example

>>> a = mx.sym.Variable('a')
>>> b = mx.sym.Variable('b')
>>> c = a + b
<Symbol _plus1>
>>> ex = c.bind(ctx=mx.cpu(), args={'a' : mx.nd.ones([2,3]), 'b' : mx.nd.ones([2,3])})
>>> ex.forward()
[<NDArray 2x3 @cpu(0)>]
>>> ex.outputs[0].asnumpy()
[[ 2.  2.  2.]
[ 2.  2.  2.]]

Parameters
• ctx (Context) – The device context the generated executor to run on.

• args (list of NDArray or dict of str to NDArray) –

Input arguments to the symbol.

• If the input type is a list of NDArray, the order should be same as the order of list_arguments().

• If the input type is a dict of str to NDArray, then it maps the name of arguments to the corresponding NDArray.

• In either case, all the arguments must be provided.

• args_grad (list of NDArray or dict of str to NDArray, optional) –

When specified, args_grad provides NDArrays to hold the result of gradient value in backward.

• If the input type is a list of NDArray, the order should be same as the order of list_arguments().

• If the input type is a dict of str to NDArray, then it maps the name of arguments to the corresponding NDArray.

• When the type is a dict of str to NDArray, one only need to provide the dict for required argument gradient. Only the specified argument gradient will be calculated.

• grad_req ({'write', 'add', 'null'}, or list of str or dict of str to str, optional) –

• ’null’ means no action is taken, the gradient may not be calculated.

• aux_states (list of NDArray, or dict of str to NDArray, optional) –

Input auxiliary states to the symbol, only needed when the output of list_auxiliary_states() is not empty.

• If the input type is a list of NDArray, the order should be same as the order of list_auxiliary_states().

• If the input type is a dict of str to NDArray, then it maps the name of auxiliary_states to the corresponding NDArray,

• In either case, all the auxiliary states need to be provided.

• group2ctx (Dict of string to mx.Context) – The dict mapping the ctx_group attribute to the context assignment.

• shared_exec (mx.executor.Executor) – Executor to share memory with. This is intended for runtime reshaping, variable length sequences, etc. The returned executor shares state with shared_exec, and should not be used in parallel with it.

Returns

executor – The generated executor

Return type

Executor

Notes

Auxiliary states are the special states of symbols that do not correspond to an argument, and do not have gradient but are still useful for the specific operations. Common examples of auxiliary states include the moving_mean and moving_variance states in BatchNorm. Most operators do not have auxiliary states and in those cases, this parameter can be safely ignored.

One can give up gradient by using a dict in args_grad and only specify gradient they interested in.