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

使用C-API,链接libpaddle_capi_whole.a库,运行的时候遇到UnKnown class type: data #2863

Closed
fingthinking opened this issue Jul 14, 2017 · 19 comments
Assignees

Comments

@fingthinking
Copy link

fingthinking commented Jul 14, 2017

在使用公司发布的capi静态库版本:
image
中的libpaddle_capi_whole.a进行编译的时候;
在使用
image
image
machine_create_for_inference方法的时候
遇到了UnKnow class type: data的问题:F0714 15:02:00.653980 30167 ClassRegistrar.h:65] Check failed: mapGet(type, creatorMap_, &creator) Unknown class type: data
其中config的配置文件Json格式片段如下:

type: "nn"
layers {
  name: "word"
  type: "data"
  size: 48127
  active_type: ""
}
layers {
  name: "__embedding_0__"
  type: "mixed"
  size: 128
  active_type: ""
  inputs {
    input_layer_name: "word"
    input_parameter_name: "___embedding_0__.w0"
    proj_conf {
      type: "table"
      name: "___embedding_0__.w0"
      input_size: 48127
      output_size: 128
    }
  }
}

type:data在capi中无法使用,请问这种情况如何解决?

@hedaoyuan
Copy link
Contributor

hedaoyuan commented Jul 14, 2017

@fingthinking
链接libpaddle_capi_whole.a的时候需要加上-Wl,--whole-archive libpaddle_capi_whole.a -Wl,--no-whole-archive。lib中的每个layer.o都是独立的。这个是为了后续可以裁剪不必要的layer做的。

@hedaoyuan hedaoyuan self-assigned this Jul 14, 2017
@fingthinking
Copy link
Author

@hedaoyuan 我按照你的回复,在BCLOUD中添加了参数,
image
我的配置为:WholeArchives("./lib/libpaddle_capi_whole.a")
但是错误仍未解决。

@hedaoyuan
Copy link
Contributor

可以看一下最终的链接参数是否生成了-Wl,--whole-archive libpaddle_capi_whole.a -Wl,--no-whole-archive
另外,可以用readelf -sW binary |grep DataLaye看一下是否连接了DataLayer。binary 替换成你生成的程序。

@hedaoyuan
Copy link
Contributor

@fingthinking 可以解决问题吗?

@fingthinking
Copy link
Author

@hedaoyuan 现在有点其他事,如果解决了,我会在issue中说,谢谢

@fingthinking
Copy link
Author

@hedaoyuan
image
这种应该是链接了DataLayer吧,但是还是会报错,Unknow class type: data.
至于是否生成了链接参数,这个比较难看,make中使用的是bcloud local命令来编译的,我无法查看

@hedaoyuan
Copy link
Contributor

hedaoyuan commented Jul 14, 2017

你把readelf -sW那条命令的输出用问题的形式贴全一下吧。从图片上看,并没有正确链接libpaddle_capi_whole.a。你可以对比看一下libpaddle_capi_whole.a中的DataLayer相关符号。

@hedaoyuan
Copy link
Contributor

@fingthinking
你这个还是属于没有正确链接libpaddle_capi_whole.a库。正确链接后镜像中的DataLayer相关符号远多于4条,你可以直接看一下libpaddle_capi_whole.a中的DataLayer符号。
另外,你可以修改成链接libpaddle_capi_shared.so是一下,运行时需要指定libpaddle_capi_shared.so的位置。

@hedaoyuan hedaoyuan changed the title 使用C-API运行的时候遇到UnKnown class type: data 使用C-API,链接libpaddle_capi_whole.a库,运行的时候遇到UnKnown class type: data Jul 14, 2017
@fingthinking
Copy link
Author

fingthinking commented Jul 14, 2017

@hedaoyuan
image
根据BCLOUD使用手册中的
image
按照上面说的,替换了libpaddle_capi_shared.so,又出现了unknown command line flag 'use_gpu'错误,直接在初始化的时候就报错了。
image

@hedaoyuan
Copy link
Contributor

hedaoyuan commented Jul 14, 2017

你第一个comment中的代码没有贴全,是按照这个方式写的吗?
https://github.com/PaddlePaddle/Paddle/blob/develop/paddle/capi/examples/model_inference/dense/main.c#L9
另外,最好不要贴图片。

@fingthinking
Copy link
Author

@hedaoyuan

char* argv[] = {(char*)"--use_gpu=False"};
    // init paddle

    CHECK(paddle_init(1, (char**)argv));
    long size=-1;
    void* buf = cpu::ci::read_config(this->_config_bin_str, &size);
    std::cout<<"size:-----"<<size<<std::endl;
    paddle_gradient_machine machine;
    // Create a gradient machine for inference.
    CHECK(paddle_gradient_machine_create_for_inference(&machine, buf, (int) size));
    CHECK(paddle_gradient_machine_load_parameter_from_disk(machine, this->_param_str));

这种方式调用的,到create_for_inference函数中就挂了

@hedaoyuan
Copy link
Contributor

paddle_gradient_machine_create_for_inference的时候报了unknown command line flag 'use_gpu'错误?这个确实比较奇怪,create的时候并不处理命令行参数。

@hedaoyuan
Copy link
Contributor

在这段code之前有调用gflags::ParseCommandLineFlags吗?

@fingthinking
Copy link
Author

@hedaoyuan 在paddle_init里面会调用google::gflags::ParseCommandLineFlags

@hedaoyuan
Copy link
Contributor

paddle_init里面会调用。但你现在是在paddle_gradient_machine_create_for_inference里面报错?

@fingthinking
Copy link
Author

@hedaoyuan 情况是,如果使用so库,则在paddle_init中就会报错了,但是如果使用whole.a,则init是正确了,但是到了paddle_gradient_machine_create_for_inference又报错了。也是比较无奈。

@hedaoyuan
Copy link
Contributor

whole.a的错误是前面说的Unknown class type: data那个吧,解决办法是在上面的comment说的方法。
用.so,会在paddle_init中报错,是指的unknown command line flag use_gpu错误这个把,这个确实比较奇怪,如果指明了参数--use_gpu,不应该会报这样的错。@fingthinking 你试一下这里的例子

@fingthinking
Copy link
Author

@hedaoyuan 好的,我纯粹的使用demo的例子试试能不能运行了,不使用公司的环境。

@hedaoyuan
Copy link
Contributor

嗯,自己编译例子里的demo试一下。一条编译命令就够了。

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