Comments (14)
因为目前不支持count_include_pad=False的avgpool2d,如果是same padding的情况下实现会比较简单,但是如果是其他情况下,需要额外添加一个mask乘的操作,会有点麻烦
from tinyneuralnetwork.
已经添加了使用乘mask的等效实现的count_include_pad=False的avgpool2d,可以重新拉一下试试
from tinyneuralnetwork.
ok 重新拉去后这个问题就消失了,作者太给力了然后我往下运行,出现了:
基本上是光流和transformer相关的,这些算子作者有继续支持的计划吗?
除了error,logs中打印了许多的warning,如:
和
对于这些warning如果不修改的话会导致转换后的模型输出不正确是吗?
from tinyneuralnetwork.
对于这些warning如果不修改的话会导致转换后的模型输出不正确是吗?
不会,图1是pytorch使用floordiv的warning,图2只是int64自动下转成int32的例行打印。两者都跟精度没关系。
ok 重新拉去后这个问题就消失了,作者太给力了然后我往下运行,出现了: 基本上是光流和transformer相关的,这些算子作者有继续支持的计划吗?
不知道哪些是常量操作,如果是常量操作可以直接跳过。方便提供下模型定义不?
from tinyneuralnetwork.
您好,我列一下模型中调用算子的地方
- grid_sample
import torch.nn.functional as F
output = F.grid_sample(
x,
grid_flow,
mode=interpolation,
padding_mode=padding_mode,
align_corners=align_corners)
- fill_
mask = x_window_pooled.new(T, nWh, nWw).fill_(1)
- img2col这个是
nn.Unfold
中调用了的
return torch._C._nn.im2col(input, _pair(kernel_size), _pair(dilation), _pair(padding), _pair(stride))
相应的'nn.Fold'中调用了col2im
- new_zeros
flow = ref[0].new_zeros(n, 2, h // 32, w // 32)
- new_ones
normalizer = x.new_ones(b, n, 49).view(-1, self.n_vecs, 49).permute(0, 2, 1)
- roll
lambda t: torch.roll(t, shifts=(-self.expand_size[0], -self.expand_size[1]), dims=(2, 3)), (k, v)
这样应该会清楚很多哈
from tinyneuralnetwork.
按难度排个序吧
简单
new_zeros, new_ones
直接跳过,没啥可说的
fill_
有直接对应
一般
roll
可以用strided_slice配合cat实现
img2col, col2im
可以用arange后的数据跑一遍,然后用gather_nd实现
困难
grid_sample
貌似没有直接对应
from tinyneuralnetwork.
不好意思,第一次搞转化,直接跳过的 new_zeros, new_ones 还是麻烦您说一下。 fill_有直接对应的是啥意思呢?感谢
from tinyneuralnetwork.
@quhaoooo 参考这里 https://github.com/alibaba/TinyNeuralNetwork/blob/main/tinynn/converter/operators/torch/__init__.py#L189 ,就是不需要设置成不需要追踪的op就好了
from tinyneuralnetwork.
@peterjc123 好的,请问一下这两个算子为什么是可以设置成不需要跟踪,另外至于fill_呢。 感谢
from tinyneuralnetwork.
好的,请问一下这两个算子为什么是可以设置成不需要跟踪,
因为他跟输入没关系啊,新生成了一个常量
另外至于fill_呢。 感谢
你是要实现吗?可以参考 https://github.com/alibaba/TinyNeuralNetwork/blob/main/docs/FAQ_zh-CN.md#%E7%AE%97%E5%AD%90%E4%B8%8D%E6%94%AF%E6%8C%81%E5%A6%82%E4%BD%95%E5%A4%84%E7%90%86 pytorch里的 fill 就是对应 tflite 的 fill
from tinyneuralnetwork.
新生成的变量不需要跟踪,但是通过您的代码也会转成tfl是吧?
对于fill转换的实现,按照 https://github.com/alibaba/TinyNeuralNetwork/blob/main/docs/FAQ_zh-CN.md#%E7%AE%97%E5%AD%90%E4%B8%8D%E6%94%AF%E6%8C%81%E5%A6%82%E4%BD%95%E5%A4%84%E7%90%86
查阅TorchScript和TFLite的Schema,选取两边对应的OP
似乎在https://github.com/alibaba/TinyNeuralNetwork/blob/main/tinynn/converter/schemas/torch/aten_schema.py 没有找到fill_对应的OP
from tinyneuralnetwork.
@quhaoooo 话说其实fill产生的也是常量,schema里面没有是因为之前我们生成schema的时候过滤了大部分inplace的tensor操作。我们不完全支持inplace的操作,尤其是 对于某个tensor的一部分(使用slice或者select)做inplace操作的那就更不支持了。当然这都是对于变量来说了,常量不受任何影响。
新生成的变量不需要跟踪,但是通过您的代码也会转成tfl是吧?
会正常利用torchscript中的步骤计算其值,但是不会加入tflite计算图,直到遇到第一个包含变量输入且使用某常量值的op,在此时他会以常量加入计算图。(这个过程一般被称为常量折叠,constant folding,有兴趣的话可以自己了解下)
from tinyneuralnetwork.
@peterjc123 好的,我去了解。谢谢大佬
from tinyneuralnetwork.
未添加的op已经记录在 #123 中了
from tinyneuralnetwork.
Related Issues (20)
- Meet Detailed error: Tensor-likes are not close! using TFLiteConverter HOT 2
- [Converter] Need transpose optimization HOT 2
- Float model failed to convert to TFLite
- [converter] map gather(+reshape) ops with seperate consecutive indices to split(unpack) ops
- tinynn.converter module not found! HOT 2
- [CI] several tests for modifier failed
- Whether to support pytorch to keras HOT 1
- TransposeConv wrong shape? HOT 15
- change input to INT8 after converting to tflite HOT 2
- [converter] implement torch's `aten::scaled_dot_product_attention` operator HOT 2
- Request: clamp would be more efficient to go to Bounded Relu than Maximum + Minimum HOT 3
- Do not support PReLU module? HOT 5
- torch.max not working HOT 2
- OneShotChannelPruner results in the miss of some operators HOT 4
- KeyError when executing quantization HOT 5
- PyTorch 转 TFLite 使用 int8 量化 HOT 4
- Does tinynn support following int16 quantization? HOT 1
- jit.trace succeed but tinynn tracer failed HOT 1
- It became larger after converting to tflite model HOT 4
- how to do Post-training integer quantization with int16 activation HOT 4
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from tinyneuralnetwork.