Table Of Contents
Table Of Contents

Symbol.simple_bind

Symbol.simple_bind(ctx, grad_req='write', type_dict=None, stype_dict=None, group2ctx=None, shared_arg_names=None, shared_exec=None, shared_buffer=None, **kwargs)[source]

Bind current symbol to get an executor, allocate all the arguments needed. Allows specifying data types.

This function simplifies the binding procedure. You need to specify only input data shapes. Before binding the executor, the function allocates arguments and auxiliary states that were not explicitly specified. Allows specifying data types.

Example

>>> x = mx.sym.Variable('x')
>>> y = mx.sym.FullyConnected(x, num_hidden=4)
>>> exe = y.simple_bind(mx.cpu(), x=(5,4), grad_req='null')
>>> exe.forward()
[<NDArray 5x4 @cpu(0)>]
>>> exe.outputs[0].asnumpy()
array([[ 0.,  0.,  0.,  0.],
       [ 0.,  0.,  0.,  0.],
       [ 0.,  0.,  0.,  0.],
       [ 0.,  0.,  0.,  0.],
       [ 0.,  0.,  0.,  0.]], dtype=float32)
>>> exe.arg_arrays
[<NDArray 5x4 @cpu(0)>, <NDArray 4x4 @cpu(0)>, <NDArray 4 @cpu(0)>]
>>> exe.grad_arrays
[<NDArray 5x4 @cpu(0)>, <NDArray 4x4 @cpu(0)>, <NDArray 4 @cpu(0)>]
Parameters:
  • ctx (Context) – The device context the generated executor to run on.
  • grad_req (string) –

    {‘write’, ‘add’, ‘null’}, or list of str or dict of str to str, optional To specify how we should update the gradient to the args_grad.

    • ’write’ means every time gradient is written to specified args_grad NDArray.
    • ’add’ means every time gradient is added to the specified NDArray.
    • ’null’ means no action is taken, the gradient may not be calculated.
  • type_dict (Dict of str->numpy.dtype) – Input type dictionary, name->dtype
  • stype_dict (Dict of str->str) – Input storage type dictionary, name->storage_type
  • group2ctx (Dict of string to mx.Context) – The dict mapping the ctx_group attribute to the context assignment.
  • shared_arg_names (List of string) – The argument names whose NDArray of shared_exec can be reused for initializing the current executor.
  • shared_exec (Executor) – The executor whose arg_arrays, arg_arrays, grad_arrays, and aux_arrays can be reused for initializing the current executor.
  • shared_buffer (Dict of string to NDArray) – The dict mapping argument names to the NDArray that can be reused for initializing the current executor. This buffer will be checked for reuse if one argument name of the current executor is not found in shared_arg_names. The `NDArray`s are expected have default storage type.
  • kwargs (Dict of str->shape) – Input shape dictionary, name->shape
Returns:

executor – The generated executor

Return type:

mxnet.Executor