这个已经是INT16的量化了
这个已经是INT16的量化了
重新梳理下当前的情况:
1.先在MLU的容器 内 将CPU结果和 370或者是GPU 保持一致。
MLU容器内的pt是需要unzip的,先保证unzip的模型在运行结果正确。
2.unzip 模型结果一致后进行模型量化
可以调整下后models/yolo.py的 class Detect(nn.Module): -> def forward(self, x): 中 x 直接return ;
参看如下:
for i in range(self.nl):
x[i] = self.m[i](x[i])
y = x[i].sigmoid()
print("Detect forward i:{}".format(i))
z.append(y)
return tuple(z)
3. 对比下cpu 和 mlu的结果情况
4.还有一个需要注意的点,如果MLU 容器结果不对,可以对下网络结构,可能是因为结构对齐导致的问题:
models/experimental.py 中默认会进行fuse,可以注释掉,参考如下
def attempt_load(weights, map_location=None):
# Loads an ensemble of models weights=[a,b,c] or a single model weights=[a] or weights=a
model = Ensemble()
for w in weights if isinstance(weights, list) else [weights]:
attempt_download(w)
ckpt = torch.load(w, map_location=map_location) # load
#model.append(ckpt['ema' if ckpt.get('ema') else 'model'].float().fuse().eval()) # FP32 model
model.append(ckpt['ema' if ckpt.get('ema') else 'model'].float().eval()) # FP32 model
量化模型检查,存在scale该key,部分信息如下
model.75.conv.weight
model.75.conv.bias
model.75.conv.scale
model.75.conv.quantized_mode : scale = tensor([2], dtype=torch.int32)
model.76.conv.weight
model.76.conv.bias
model.76.conv.scale
model.76.conv.quantized_mode : scale = tensor([2], dtype=torch.int32)
请登录后评论