FDF互助游戲開發(fā)原理丨FDF互助智能合約游戲系統(tǒng)開發(fā)(開發(fā)規(guī)則及詳情)
From Web1.0 to Web3.0,from user read-only to user owned.Web1.0 is a read-only network,a static and one-way network,representing browsers and e-commerce;Web 2.0 pays more attention to user interaction.Users are both browsers and content producers.
The mode of development is from"read"to"write",and the representative products are social media and short video platforms;Web3.0 is the Internet of Value,and Web3.0 is a set of inclusive protocols that provide building blocks for application manufacturers
void Calibration::_fake_quant_weights(){
//找到權(quán)重中最大值(絕對值)的lamda函數(shù)
auto findAbsMax=[&](const float*weights,const int size){
float absMax=0;
for(int i=0;i<size;i++){
if(std::fabs(weights<i>)>absMax){
absMax=std::fabs(weights<i>);
}
}
return absMax;
};
for(const auto&op:_originaleModel->oplists){
//跳過指定不需要量化的op,以及非Convolution
std::vector<std::string>::iterator iter=std::find(_skip_quant_ops.begin(),_skip_quant_ops.end(),op->name);
if(iter!=_skip_quant_ops.end()){需求及詳情I35模式7O98開發(fā)O7I8
continue;
}
const auto opType=op->type;
if(opType!=MNN::OpType_Convolution&&opType!=MNN::OpType_ConvolutionDepthwise){
continue;
}開發(fā)功能及源碼:MrsFu123
auto param=op->main.AsConvolution2D();
const int kernelNum=param->common->outputCount;
std::vector<float>weights=param->weight;
const int weightSize=weights.size();
const int kernelSize=weightSize/kernelNum;
//對每個kernel進(jìn)行量化
for(int i=0;i<kernelNum;i++){
const int offset=i*kernelSize;
float absMax=findAbsMax(weights.data()+offset,kernelSize);
float scale=absMax/_weightClampValue;//根據(jù)最大值計算縮放因子
if(absMax<1e-6f){
scale=absMax;
}
for(int j=0;j<kernelSize;j++){
float value=weights[offset+j];
float quantValue=std::round(value/scale);//量化到int8的值
float clampedValue=std::max(std::min(quantValue,_weightClampValue),-_weightClampValue);//小于-127的部分,映射到-127
float dequantValue=scale*clampedValue;
param->weight[offset+j]=dequantValue;//反量化
}
}
}
}