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

keras.layer里Embedding的trt实现 #21

Closed
YuzhouPeng opened this issue Jun 24, 2021 · 8 comments
Closed

keras.layer里Embedding的trt实现 #21

YuzhouPeng opened this issue Jun 24, 2021 · 8 comments
Labels

Comments

@YuzhouPeng
Copy link

感谢大佬做的项目!帮助很大,已star
我遇到了一个问题,我在做keras.layer.Embedding层的trt实现,想问下可否使用tensorRT自带的embLayerNormPlugin插件来实现功能??我的python和C++源码放在下面:
python代码:
微信图片_20210624171827
python运行的结果 从一个32长度数组变成32x128tensor:
微信图片_20210624171831

@yuanzexi
Copy link
Collaborator

@YuzhouPeng 可以的~ Forward 的 Plugins 目录中也有引入 TensorRT 官方的 embLayerNormPlugin 的。

@YuzhouPeng
Copy link
Author

@yuanzexi 大佬,我还想请教下,embLayerNormPlugin 里面需要输入layernorm,word embedding,token embeddingg等参数,而且输入有三个,但是我keras使用embedding的时候只输入了一个32位数组,像这种情况embLayerNormPlugin 的那些参数该怎么设置比较好呢?
屏幕截图 2021-06-28 085335

@yuanzexi
Copy link
Collaborator

yuanzexi commented Jun 28, 2021

@YuzhouPeng 对于 Keras.Embedding 的操作,我们是用 Gather 层实现的 https://github.com/Tencent/Forward/blob/master/source/fwd_keras/keras_cvt/keras_desc_creators/keras_gather_creator.h
你可以看看是否满足需求。如果你确实需要使用 EmbedLayerNorm plugin 来实现,你可以根据你自己的需求来设置那些输入和参数。

@chenjun2hao
Copy link

@yuanzexi , when i build the demo/fwd_cpp, it put the error:

[ 75%] Linking CXX executable test_fwd_engine
CMakeFiles/test_fwd_engine.dir/test_fwd_engine.cpp.o:在函数‘main’中:
test_fwd_engine.cpp:(.text+0x1c8):对‘fwd::TrtForwardEngine::Load(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&)’未定义的引用
collect2: error: ld returned 1 exit status
CMakeFiles/test_fwd_engine.dir/build.make:91: recipe for target 'test_fwd_engine' failed
make[2]: *** [test_fwd_engine] Error 1
CMakeFiles/Makefile2:72: recipe for target 'CMakeFiles/test_fwd_engine.dir/all' failed
make[1]: *** [CMakeFiles/test_fwd_engine.dir/all] Error 2
make[1]: *** 正在等待未完成的任务....
[100%] Linking CXX executable test_fwd_torch
CMakeFiles/test_fwd_torch.dir/test_fwd_torch.cpp.o:在函数‘main’中:
test_fwd_torch.cpp:(.text+0x85c):对‘fwd::TorchBuilder::SetInferMode(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&)’未定义的引用
test_fwd_torch.cpp:(.text+0x9cf):对‘fwd::TorchBuilder::Build(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, std::vector<c10::IValue, std::allocator<c10::IValue> > const&)’未定义的引用
test_fwd_torch.cpp:(.text+0xaa2):对‘fwd::TorchEngine::Save(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&) const’未定义的引用
test_fwd_torch.cpp:(.text+0xaf4):对‘fwd::TorchEngine::Load(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&) const’未定义的引用
../libs/libfwd_torch.so:对‘c10::Error::Error(c10::SourceLocation, std::string)’未定义的引用
../libs/libfwd_torch.so:对‘c10::detail::infer_schema::make_function_schema(std::string&&, std::string&&, c10::ArrayRef<c10::detail::infer_schema::ArgumentDef>, c10::ArrayRef<c10::detail::infer_schema::ArgumentDef>)’未定义的引用
../libs/libfwd_torch.so:对‘c10::Symbol::fromQualString(std::string const&)’未定义的引用
../libs/libfwd_torch.so:对‘at::Tensor::toString() const’未定义的引用
../libs/libfwd_torch.so:对‘torch::jit::Object::find_method(std::string const&) const’未定义的引用
../libs/libfwd_torch.so:对‘torch::jit::SubgraphRewriter::runOnGraph(std::shared_ptr<torch::jit::Graph>&, std::vector<std::function<bool (torch::jit::Match const&, std::unordered_map<std::string, torch::jit::Value*, std::hash<std::string>, std::equal_to<std::string>, std::allocator<std::pair<std::string const, torch::jit::Value*> > > const&)>, std::allocator<std::function<bool (torch::jit::Match const&, std::unordered_map<std::string, torch::jit::Value*, std::hash<std::string>, std::equal_to<std::string>, std::allocator<std::pair<std::string const, torch::jit::Value*> > > const&)> > > const&)’未定义的引用
../libs/libfwd_torch.so:对‘torch::jit::SubgraphRewriter::RegisterRewritePattern(std::string const&, std::string const&)’未定义的引用
../libs/libfwd_torch.so:对‘torch::jit::Method::operator()(std::vector<c10::IValue, std::allocator<c10::IValue> >, std::unordered_map<std::string, c10::IValue, std::hash<std::string>, std::equal_to<std::string>, std::allocator<std::pair<std::string const, c10::IValue> > > const&)’未定义的引用
../libs/libfwd_torch.so:对‘torch::jit::Value::debugNameBase() const’未定义的引用
../libs/libfwd_torch.so:对‘torch::jit::parseSchemaOrName(std::string const&)’未定义的引用
../libs/libfwd_torch.so:对‘torch::jit::load(std::string const&, c10::optional<c10::Device>, std::unordered_map<std::string, std::string, std::hash<std::string>, std::equal_to<std::string>, std::allocator<std::pair<std::string const, std::string> > >&)’未定义的引用
collect2: error: ld returned 1 exit status
CMakeFiles/test_fwd_torch.dir/build.make:105: recipe for target 'test_fwd_torch' failed
make[2]: *** [test_fwd_torch] Error 1
CMakeFiles/Makefile2:109: recipe for target 'CMakeFiles/test_fwd_torch.dir/all' failed
make[1]: *** [CMakeFiles/test_fwd_torch.dir/all] Error 2
Makefile:83: recipe for target 'all' failed
make: *** [all] Error 2

我已经切换几个tag了。提前谢谢了。

@zhaoyiluo
Copy link
Collaborator

Hello @chenjun2hao

我们刚测试了下,发现 build.sh 可以成功运行,推测可能是环境配置造成的错误。

希望你这边可以提供这些信息,以便我们做进一步判断。

  1. 提供修改后的 build.sh 文件内容

  2. 注释 build.sh 的最后一行 make -j,并运行 build.sh,提供脚本运行的结果

谢谢~

@chenjun2hao
Copy link

@zhaoyiluo ,你好。动态库是可以编译出来的。但是用动态库编译demo下来的exe的时候报上面的错误。我用另外一台电脑测试,也出现同样的问题。

@github-actions
Copy link

This issue is stale because it has been open 30 days with no activity. Remove stale label or comment or this will be closed in 5 days.

@github-actions github-actions bot added the Stale label Aug 15, 2021
@github-actions
Copy link

This issue was closed because it has been stalled for 5 days with no activity.

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

No branches or pull requests

4 participants