samskalicky commented on issue #15921: [WIP] dynamic custom operator support
URL: https://github.com/apache/incubator-mxnet/pull/15921#issuecomment-526477697
 
 
   @wkcn should we consider removing the nnvm pvalue restriction that attrs can 
be set multiple time here:
   
   
https://github.com/dmlc/nnvm/blob/dab5ce8ab6adbf4edd8bd2fa89f1a99f343b6e38/include/nnvm/op.h#L461-L464
   
   Or add an argument to optionally allow override, but default to current 
behavior?
   
   Like this:
   
   ‘’’
     inline Op& set_attr(const std::string& attr_name,  // NOLINT(*)
                         const ValueType& value,
                         int plevel = 10, bool override=false);
   
   template<typename ValueType>
   inline Op& Op::set_attr(  // NOLINT(*)
       const std::string& attr_name,
       const ValueType& value,
       int plevel,
       bool override) {
     CHECK_GT(plevel, 0)
         << "plevel in set_attr must be greater than 0";
     // update the attribute map of the key by creating new empty if needed.
     UpdateAttrMap(attr_name,
                   [this, attr_name, value, plevel](any* pmap) {
         // the callback is in lockscope so is threadsafe.
         if (pmap->empty()) {
           OpMap<ValueType> pm;
           pm.attr_name_ = attr_name;
           *pmap = std::move(pm);
         }
         CHECK(pmap->type() == typeid(OpMap<ValueType>))
             << "Attribute " << attr_name
             << " of operator " << this->name
             << " is registered as inconsistent types"
             << " previously " << pmap->type().name()
             << " current " << typeid(OpMap<ValueType>).name();
         std::vector<std::pair<ValueType, int> >& vec =
             nnvm::get<OpMap<ValueType> >(*pmap).data_;
         // resize the value type.
         if (vec.size() <= index_) {
           vec.resize(index_ + 1,
                      std::make_pair(ValueType(), 0));
         }
         std::pair<ValueType, int>& p = vec[index_];
         CHECK(p.second != plevel && !override)
             << "Attribute " << attr_name
             << " of operator " << this->name
             << " is already registered with same plevel=" << plevel;
         if (p.second < plevel) {
           vec[index_] = std::make_pair(value, plevel);
         }
       });
     return *this;
   }
   ‘’’

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
[email protected]


With regards,
Apache Git Services

Reply via email to