馬蹄鏈互助遊戲開發詳情丨馬蹄鏈互助智慧合約遊戲系統開發(案例及分析)

xiaofufu發表於2023-03-08

  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用於存放量化後的引數


  ***/本文由系統開發對接唯:MrsFu123編輯整理釋出。


  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{


  //用於逆量化時對用的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));


  }


  }


  return 0;


  }


來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/69956839/viewspace-2938695/,如需轉載,請註明出處,否則將追究法律責任。

相關文章