当你计划使用LNN对自己的模型进行量化训练并部署至 CSK6 芯片上之前,需要从模型部署所需的硬件资源、LNN支持的算子等方面继续综合评估。
你可能需要关注以下几个维度,以判断模型是否适合:
下文将从以上几个维度进行分述。
CSK6 芯片面向轻量级端侧AI应用设计,考虑到芯片有限的PSRAM、SRAM、Flash等资源,建议您采用小模型(如squeezenet、mobilenet、mobilenetv2、resnet18 等)。
LNN支持int8量化,因此int32初始模型大小不能超过32MB。
PyTorch(float32) | linger算子名称 | linger导出onnx算子名称 | 支持关闭的设置 |
---|---|---|---|
nn.BatchNorm2d | BatchNorm2dInt | BatchNorm2dInt | - |
nn.LayerNorm2d | LayerNorm2dInt | LayerNorm2dInt | - |
nn.Linear | LinearInt | LinearInt | - |
nn.Conv1d | Conv1dInt | Conv1dInt | - |
nn.Conv2d | Conv2dInt | Conv2dInt | - |
nn.ConvTranspose2d | ConvTranspose2dInt | ConvTranspose2dInt | - |
nn.AvgPool2d | AvgPool2dInt | AvgPool2dInt | - |
nn.MaxPool2d | iqMaxPool2d | MaxPool2d | - |
nn.GRU | GRUInt | GRUInt/GRUInt_Is8_Is64/GRUInt_Is8_Is64_If32 | - |
nn.LSTM | LSTMInt | LSTMInt/LSTMInt_Is8_Is64/LSTMInt_Is8_Is64_If32_If32 | - |
nn.Relu | iqRelu | Relu | - |
nn.RELU6 | ReLU6Int | Clip | - |
torch.bmm | BmmInt | BmmInt | - |
torch.sigmoid | iqSigmoid | iqSigmoid | linger.SetIQTensorSigmoid(False) |
torch.tanh | iqTanh | iqTanh | linger.SetIQTensorTanh(False) |
torch.clamp | iqClamp | iqClamp | linger.SetIQTensorClamp(False) |
torch.cat | iqCat | iqCat | linger.SetIQTensorCat(False) |
torch.transpose | iqTranspose | Transpose | - |
view | iqView | Reshape | - |
reshape | iqReshape | Reshape | - |
squeeze | iqSqueeze | Squeeze | - |
unsqueeze | iqUnsqueeze | Unsqueeze | - |
flatten | iqFlatten | Flatten | - |
split | - | - | - |
slice | slice | Slice | - |
sum | iqSum | iqSum | linger.SetIQTensorSum(False) |
add | iqAdd | iqAdd | linger.SetIQTensorAdd(False) |
sub | - | - | - |
mul | iqMul | iqMul | linger.SetIQTensorMul(False) |
div | iqDiv | iqDiv | linger.SetIQTensorDiv(False) |
upsample | - | - | - |
nn.Embedding | EmbeddingInt | Gather | - |
quant | quant | Quant | - |
dequant | dequant | Dequant | - |
requant | Requant | Requant | - |
layernorm | LayerNormInt | LayerNormInt | - |
softmax | SoftmaxInt | SoftmaxInt | - |
logsoftmax | LogSoftmaxInt | LogSoftmaxInt | - |
flip | iqFlip | Slice | - |
var | iqVar | iqVar | - |
- | channel_shuffle | ShuffleChannel | SetFunctionChannelShuffleQuant(False) |
{2,3,4,5}
{4,5}
输入只支持2维/3维,且3维输入数据大小有限制。假设输入维度为CHW,数据位宽为data_bytes,限制条件如下: