Comments (5)
- switch_case 一般可以用 if 替代,你可以上传一个简单模型,我们排期支持下
- 存在控制流算子 (if / while) 时,都会产生子图
- 这个你可以把各分支分别导出 pb 并转 mnn 模型来实现。不过建议还是换成 if ,加载1个mnn比较方便
from mnn.
- switch_case 一般可以用 if 替代,你可以上传一个简单模型,我们排期支持下
- 存在控制流算子 (if / while) 时,都会产生子图
- 这个你可以把各分支分别导出 pb 并转 mnn 模型来实现。不过建议还是换成 if ,加载1个mnn比较方便
if else在推理的时候不会很慢吗,如果是一定批量输入的话
from mnn.
批量输入建议不要用控制流的方式实现,可以用 select 类似的算子替代
from mnn.
批量输入建议不要用控制流的方式实现,可以用 select 类似的算子替代
那如果是MoE这类网络呢,有什么比较好的方式,select 类似的算子在MoE场景中似乎也会回到tf.case的问题上
from mnn.
@jxt1234 大佬,我们这边仍然有switch_case的需求,如果可以的话可以在后续版本加上。感谢!
就以前面提到的测试代码为例:
tensorflow 版本: 1.1.5
import tensorflow as tf
condition = tf.placeholder(dtype=tf.int32, name="input")
def multiply():
return tf.multiply(condition, 100
def add():
return tf.add(condition, 10)
res = tf.switch_case(condition, branch_fns={
0: multiply,
1: add,
}, default=None)
with tf.Session() as sess:
output = sess.run(res,feed_dict={condition:0})
print(output)
nodes = [node.name for node in tf.get_default_graph().get_operations()]
output_graph_def = tf.graph_util.convert_variables_to_constants(
sess, sess.graph_def, output_node_names=nodes
)
tf.train.write_graph(output_graph_def, "./", "switch_case.pb", as_text=False)
使用MNNConvert转换模型提示:
The device support i8sdot:0, support fp16:0, support i8mm: 0
Start to Convert Other Model Format To MNN Model..., target version: 2.8
Start to Optimize the MNN Net...
[10:59:47] :105: These Op Not Support: Tensorflow::Case
Converted Failed!
以及用上面代码保存的测试模型的zip:
switch_case.zip
from mnn.
Related Issues (20)
- MNN Llama-3-8B-Instruct export 失败 HOT 1
- Cut MNN build size according to operators to use HOT 2
- 添加完Mutlihead attention 算子后,报错Reshape41 算子异常 HOT 1
- meta-llama3-8b-instruct 使用llm_demo 推理报错 HOT 2
- onnx转mnn之后模型推理和原模型差距太大 HOT 3
- phi2 使用 llm_demo 推理报错 HOT 2
- 有转换mobilenet V3成功的老铁吗?转为mnn之后准确率下降很多 HOT 1
- 量化后输出怎么从float改成int8
- 求助!!!!!!!!打印 input_tensor内容全部都是0 HOT 1
- fastOnnxTest 成功 但使用时输出不一致 HOT 2
- 编译示例工程代码报错
- 编译测试工具报错阻塞 HOT 3
- 问一下, 在armv8.2 cpu 手机上, 是否已支持fp16 进行卷积的推理阿? HOT 1
- c++ 链接MNN后,编译报错,无法解析的外部符号 _std_init_once_link_alternate_names_and_abort和_std_min_element_4 HOT 6
- mnncompress量化模型以后大小没有变化 HOT 3
- MNN.cv has the rotation issue in loading some photos from the phone HOT 1
- 求教 expr 中_Fill 的正确用法 HOT 3
- 鸿蒙系统编译失败 HOT 1
- Facing issue with version incapitability between protobuffer library and MNN library while performing mnnquant quantization process using python API of mnn HOT 4
- 多输入模型转换时添加--optimizePrefer 2选项 并基于此使用MNNPythonOfflineQuant离线量化,在arm cpu后端推理输出异常,与x86 cpu推理不对齐 HOT 1
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 mnn.