Skip to content

Commit 5821d6c

Browse files
committed
fix unnecessary operations
1 parent 4d6b804 commit 5821d6c

File tree

1 file changed

+5
-5
lines changed

1 file changed

+5
-5
lines changed

src/llama-graph.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1572,33 +1572,33 @@ void llm_graph_context::build_pooling(
15721572
ggml_tensor * inp_cls = build_inp_cls();
15731573
inp = ggml_get_rows(ctx0, inp, inp_cls);
15741574

1575-
if (cls != nullptr) {
1575+
if (cls) {
15761576
// classification head
15771577
// https://github.com/huggingface/transformers/blob/5af7d41e49bbfc8319f462eb45253dcb3863dfb7/src/transformers/models/roberta/modeling_roberta.py#L1566
15781578
cur = ggml_mul_mat(ctx0, cls, inp);
1579-
if (cls_b != nullptr) {
1579+
if (cls_b) {
15801580
cur = ggml_add(ctx0, cur, cls_b);
15811581
}
15821582
cur = ggml_tanh(ctx0, cur);
15831583

15841584
if (cls_norm) {
15851585
// normalization head
1586-
cur = build_norm(cur, cls_norm, nullptr, LLM_NORM, 0);
1586+
cur = build_norm(cur, cls_norm, NULL, LLM_NORM, -1);
15871587
}
15881588

15891589
// some models don't have `cls_out`, for example: https://huggingface.co/jinaai/jina-reranker-v1-tiny-en
15901590
// https://huggingface.co/jinaai/jina-reranker-v1-tiny-en/blob/cb5347e43979c3084a890e3f99491952603ae1b7/modeling_bert.py#L884-L896
15911591
if (cls_out) {
15921592
cur = ggml_mul_mat(ctx0, cls_out, cur);
1593-
if (cls_out_b != nullptr) {
1593+
if (cls_out_b) {
15941594
cur = ggml_add(ctx0, cur, cls_out_b);
15951595
}
15961596
}
15971597
} else if (cls_out) {
15981598
// Single layer classification head (direct projection)
15991599
// https://github.com/huggingface/transformers/blob/f4fc42216cd56ab6b68270bf80d811614d8d59e4/src/transformers/models/bert/modeling_bert.py#L1476
16001600
cur = ggml_mul_mat(ctx0, cls_out, inp);
1601-
if (cls_out_b != nullptr) {
1601+
if (cls_out_b) {
16021602
cur = ggml_add(ctx0, cur, cls_out_b);
16031603
}
16041604
} else {

0 commit comments

Comments
 (0)