Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

julia 1.7.2 using ONNXNaiveNASflux predict wiill get error #67

Open
lpiert opened this issue Feb 25, 2022 · 4 comments
Open

julia 1.7.2 using ONNXNaiveNASflux predict wiill get error #67

lpiert opened this issue Feb 25, 2022 · 4 comments

Comments

@lpiert
Copy link

lpiert commented Feb 25, 2022

using ONNXNaiveNASflux
using MLDatasets
train_x, train_y = MNIST.traindata(2)
data=train_x[:,:,1]
input = reshape(data,(1,1,28,28))
model = ONNXNaiveNASflux.load("mnist-1.onnx")
out = model(input)

exe top these ,will get error "ERROR: LoadError: AssertionError: Optype Div not supported!" ONNX 0.11 has same proplem.

@DrChainsaw
Copy link
Owner

Thanks for the report.

The error states that the model uses the Div operator which ONNXNaiveNASflux does not yet support. I can add support for it, but it would be good if you can provide a link to the model so I can see if there are other ops in there which needs to be added.

You can register the Div operator yourself by running this before you try to load the model:

ONNXNaiveNASflux.verts[:Div] = (name, inputs, params; kwargs...) -> ONNXNaiveNASflux.elemwisevertex(name, inputs, params, /, 1; kwargs...)
ONNXNaiveNASflux.refresh()

@lpiert
Copy link
Author

lpiert commented Feb 27, 2022

Thanks for the report.

The error states that the model uses the Div operator which ONNXNaiveNASflux does not yet support. I can add support for it, but it would be good if you can provide a link to the model so I can see if there are other ops in there which needs to be added.

You can register the Div operator yourself by running this before you try to load the model:

ONNXNaiveNASflux.verts[:Div] = (name, inputs, params; kwargs...) -> ONNXNaiveNASflux.elemwisevertex(name, inputs, params, /, 1; kwargs...)
ONNXNaiveNASflux.refresh()

Thanks for your support. The model onnx link: https://github.com/onnx/models/blob/main/vision/classification/mnist/model/mnist-1.onnx

@DrChainsaw
Copy link
Owner

I had a look at the model and it seems to be a very old type of model which is using version 1 of the ONNX spec (current version is 8). It seems to use a very different mechanism for loading model parameters (storing them as constant nodes in the graph) than the one implemented in this package (initializers).

The consequence is that in order to hoist it into a Flux model I would need to implement some form of constant propagation on the protostructs. I think it would be possible to add support for it but it would require quite a bit of effort as working with the "raw" protos is quite cumbersome.

Given that the model is for a toy-dataset, is there any chance that you just tried this to see if the library worked? If so, I would prefer to just put "implement constant propagation" in the backlog for now and revisit if it surfaces again. Implementing it now might hamper future additions so it is not a one-time cost to support it.

To add a little bit of context: Flux and ONNX use very different layer definitions (which is a natural consequence of them being developed independently) so not every valid ONNX model is a valid Flux model and vice versa. In many cases it is possible to transform to an equivalent model, but there is no method which is guaranteed to always work. This problem is not unique to Flux vs ONNX: All the major frameworks suffer from this to some extent.

@lpiert
Copy link
Author

lpiert commented Mar 1, 2022

我查看了模型,它似乎是一种非常古老的模型,使用的是 ONNX 规范的版本 1(当前版本是 8)。它似乎使用了一种非常不同的机制来加载模型参数(将它们存储为图中的常量节点),而不是在这个包中实现的机制(初始化程序)。

结果是,为了将其提升到 Flux 模型中,我需要在原型结构上实现某种形式的常量传播。我认为添加对它的支持是可能的,但它需要相当多的努力,因为使用“原始”原型非常麻烦。

鉴于该模型适用于玩具数据集,您是否有机会尝试此操作以查看该库是否有效?如果是这样,我宁愿暂时将“实现恒定传播”放在积压中,如果它再次出现,请重新访问。现在实施它可能会妨碍未来的添加,因此支持它不是一次性成本。

添加一点上下文:Flux 和 ONNX 使用非常不同的层定义(这是它们独立开发的自然结果),因此并非每个有效的 ONNX 模型都是有效的 Flux 模型,反之亦然。在许多情况下,可以转换为等效模型,但没有一种方法可以保证始终有效。这个问题并不是 Flux 与 ONNX 所独有的:所有主要的框架都在一定程度上受到了这个问题的影响。

thanks. I can use other versions of model files, but I will use Julia as the architecture later in the technical research phase.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants