zhihu / cuBERT

Fast implementation of BERT inference directly on NVIDIA (CUDA, CUBLAS) and Intel MKL

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

cubert是否支持多分类?

xuqiang opened this issue · comments

bert做四分类任务,希望输出每个instance在4个分类上的概率,试了下cuBERT_LOGITS,发现结果和tf预测的结果不一致。问下cubert是否支持这个功能(每个instance在各个分类上的概率)?

支持的

可以把测试文件+模型发给我们看下

可以把测试文件+模型发给我们看下

方便留个联系方式吗?qq或者微信

测试程序是改了下 test/cuBERT_test.cpp

`

TEST_F(cuBertTest, compute) {
int max_batch_size = 32;
int batch_size = 1;
int seq_length = 32;
int num_label = 13;

int input_ids[batch_size * seq_length] = { 101, 5933, 3697, 6656, 4285, 2165, 7735, 6478, 2090, 3365, 8222, 102, 5933, 3697, 6656, 4285, 2165, 7735, 6478, 2090, 3365, 8222, 113, 2682, 2661, 114, 102, 0, 0, 0, 0, 0 };
int8_t input_mask[batch_size * seq_length] = { 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0 };
int8_t segment_ids[batch_size * seq_length] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0 };
float logits[batch_size * num_label];
//random_input(input_ids, input_mask, segment_ids, batch_size * seq_length);

void* model = cuBERT_open("modelb.pb", max_batch_size, seq_length, 12, 12);
cuBERT_compute(model, batch_size, input_ids, input_mask, segment_ids, logits);
cuBERT_close(model);

for(int i = 0; i < num_label; ++i) {
    std::cout << i << " " << logits[i] << std::endl;
}

for(int i = 0; i < num_label; ++i) {
    std::cout << logits[i] << ", ";
}
std::cout << std::endl;

}
`

logits的值看着不对。

我看cubert的源代码,看着也不太能支持多分类

https://github.com/zhihu/cuBERT/blob/master/src/cuBERT/Bert.cpp#L51

this->_logits = static_cast<T *>(cuBERT::malloc(sizeof(T) * max_batch_size));

哦,这里可能是个 bug,少乘了 num_labels,包括下面拷贝也是

cuBERT::memcpyAsync(logits, _logits, sizeof(T) * batch_size, 2, streamId);

QQ: 372684992

修了下这个问题,回头我发个pull request。