Notes on bucket mechanism in mxnet

Source: Internet
Author: User
Tags mxnet

Preface

The API was thought bucket to be an interface rooted in the underlying operation (MXNet doc -_-| |). From LSTM looking over, contact with a number of related programs, and then bucketing_module.py see that part of the next, found that bucket is only an application layer mechanism, the main implementation exists in the module/bucketing_module.py inside. The principle is clear, the realization is concise, makes a mark in this.

Code & Comments

First put some related links, make a preparation.

    1. MXNet Official documents (\tucao out a document is not easy, also with timeliness ...)
    2. The Great God's blog elaborated, so pertinent
    3. Before about LSTM's blog
      Given the fact that the great God has been so vivid in this [blog], it is possible to save the province, and then say the details of the gods who have no time to take into account.
      In addition, considering that Mxnet's link often shows an unreliable symptom (\kuxia), it boils down to 1 some of the conclusions: 要使用bucket机制,初始化Module时传入的symbol应该是一个函数,这个函数在被调用时将被传入迭代器中的bucket_key参数 .

Go through the sequence of call paths.
On the fit inside bind , wait for the init operation, and later call prepare the pre-fetched data (if any) to prepare:

# module/bucketing_module.py    defPrepare Self, Data_batch):"" " prepares a data batch for forward.Parameters        ----------Data_batch:databatch        """        # Perform bind if haven ' t done so        assert  Self. binded and  Self. params_initialized Bucket_key=Data_batch.bucket_key Original_bucket_key=  Self. _curr_bucket_key Data_shapes=Data_batch.provide_data Label_shapes=Data_batch.provide_label Self. Switch_bucket (Bucket_key, Data_shapes, Label_shapes)# switch back         Self. Switch_bucket (Original_bucket_key,None,None)

Clearly, it switch_bucket is the responsibility to rebind:

# module/bucketing_module.py    defSwitch_bucket ( Self, Bucket_key, Data_shapes, label_shapes=None):assert  Self. binded,' call bind before switching bucket '        if  notBucket_keyinch  Self. _buckets:# Check if there is already ...Symbol, Data_names, label_names=  Self. _sym_gen (Bucket_key) module=Module (symbol, data_names, label_names, logger= Self. Logger, context= Self. _context, Work_load_list= Self. _work_load_list, Fixed_param_names= Self. _fixed_param_names, State_names= Self. _state_names) Module.bind (Data_shapes, Label_shapes, Self. _curr_module.for_training, Self. _curr_module.inputs_need_grad, Force_rebind=False, Shared_module= Self. _buckets[ Self. _default_bucket_key]) Self. _buckets[bucket_key]=Module Self. _curr_module=  Self. _buckets[bucket_key] Self. _curr_bucket_key=Bucket_key

The logic is clear, _curr_module there are many module, the parameters of these module all point to the same group. If the entry and exit bucket_key does not appear, bind One and put it into the *_curr_module list, if it already has (including just bind out), switch to that On the module*.

Misc

There are some other related materials that are placed here.

    1. In the previous blog, it is speculated that the bucket mechanism may be processed for the part to be filled, which is somewhat related to the io.py inside DataBatch pad variables. In the module/base_module.py , find the reference pad , found and io.py inside the note consistent, only in the time of prediction to use, Be neglected when training.
    2. exmple/rnn/bucketingThere are examples of the use of higher-level interfaces.

Notes on bucket mechanism in mxnet

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.