Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

Code Block
languagepy
def merge_dicts(*dict_args):
   """Merge arg_params and aux_params to populate shared_buffer"""
   result = {}
   for dictionary in dict_args:
       result.update(dictionary)
   return result

Now let’s see a use example:
Code Block
languagepy
device = mx.gpu(0)
sym, arg_params, aux_params =
   mx.model.load_checkpoint(model_name, num_epochs)
executor = sym.simple_bind(ctx=device,
   data=data_shape,
   softmax_label=(batch_size,),
   shared_buffer=merge_dicts(arg_params, aux_params),,
   grad_req='null',
   force_rebind=True)

Now we can simply update data in the executor’s arg dict and run the forward pass:
Code Block
languagepy
executor.arg_dict["data"][:] = my_data_batch
executor.forward(is_train=False)
predictions = executor.outputs[0].asnumpy()

...