欢迎光临散文网 会员登陆 & 注册

马蹄链智能合约开发详情丨DAPP马蹄链智能合约流动性质押挖矿系统开发技术方案及逻辑

2023-03-08 15:07 作者:bili_33032327742  | 我要投稿

  Web3.0技术可分为基础层技术、平台层技术、交互层技术。相较于Web2.0时代,Web3.0涉及细分技术类别更多、范围更广,其中区块链技术由于其去中心化的特征,成为Web3.0核心底层基础技术。


  int SymmetricQuantizeWeight(const float*weight,const int size,int8_t*quantizedWeight,float*scale,


  const int channels,float weightClampValue){


  /**对参数进行量化


  *weight为乘上scale后的权重,


  *quantizedWeight用于存放量化后的参数


  ***/


  DCHECK((size%channels)==0)<<"weight size error!";


  const int channelStride=size/channels;


  const int quantizedMaxValue=weightClampValue;//127


  for(int c=0;c<channels;++c){//对每个channel分别量化


  const auto weightChannelStart=weight+c*channelStride;


  auto quantizedWeightChannelStart=quantizedWeight+c*channelStride;


  //获取该channel内最大最小值


  auto minmaxValue=std::minmax_element(weightChannelStart,weightChannelStart+channelStride);


  const float dataAbsMax=std::fmax(std::fabs(*minmaxValue.first),std::fabs(*minmaxValue.second));


  float scaleDataToInt8=1.0f;


  if(dataAbsMax==0){


  scale[c]=0.0f;


  }else{案例及详解I59模式2OO7开发3O69


  //用于逆量化时对用的scale


  scale[c]=dataAbsMax/quantizedMaxValue;


  //映射到int8空间上的scale


  scaleDataToInt8=quantizedMaxValue/dataAbsMax;


  }


  for(int i=0;i<channelStride;++i){


  //将输入权重乘上scale映射到int8上之后,对不在[-127,127]区间的都截断设置为-127或者127.


  const int32_t quantizedInt8Value=static_cast<int32_t>(roundf(weightChannelStart<i>*scaleDataToInt8));


  quantizedWeightChannelStart<i>=


  std::min(quantizedMaxValue,std::max(-quantizedMaxValue,quantizedInt8Value));


  }功能及开发:yy625019


  }


  return 0;


  }


马蹄链智能合约开发详情丨DAPP马蹄链智能合约流动性质押挖矿系统开发技术方案及逻辑的评论 (共 条)

分享到微博请遵守国家法律