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

ggml : deprecate GGML_TASK_FINALIZE #284

Closed
ggerganov opened this issue Jun 25, 2023 · 2 comments · Fixed by ggerganov/llama.cpp#1995
Closed

ggml : deprecate GGML_TASK_FINALIZE #284

ggerganov opened this issue Jun 25, 2023 · 2 comments · Fixed by ggerganov/llama.cpp#1995
Labels
good first issue Good for newcomers performance Speed related topics refactoring Refactoring

Comments

@ggerganov
Copy link
Owner

The initial design of the compute tasks in ggml was each one to have 3 separate stages:

  • GGML_TASK_INIT
  • GGML_TASK_COMPUTE
  • GGML_TASK_FINALIZE

So far, the GGML_TASK_FINALIZE step has been left completely unused and it seems it won't find any applications in the future. Therefore, it is best to remove it all together. This will simplify the code a little bit and also bring performance improvements as there will be fewer thread synchronization points during the graph computation

Related:

@ggerganov ggerganov added enhancement New feature or request good first issue Good for newcomers refactoring Refactoring performance Speed related topics and removed enhancement New feature or request labels Jun 25, 2023
@ggerganov ggerganov changed the title ggml : deprecate GGML_TASK_FINALIZE ggml : deprecate GGML_TASK_FINALIZE Jun 25, 2023
goerch added a commit to goerch/ggml that referenced this issue Jun 25, 2023
@rlanday
Copy link

rlanday commented Sep 7, 2023

Hi, I took a look at this and found that GGML_TASK_FINALIZE is used by ggml_compute_forward_cross_entropy_loss_f32():

https://github.com/ggerganov/llama.cpp/blob/178b1850ebd21b349cebbee887950e435c5aa2d3/ggml.c#L15453

Please advise.

@ggerganov
Copy link
Owner Author

INIT and FINALIZE are now optional and disabled for the majority of ops:

ggml/src/ggml.c

Lines 4080 to 4116 in 79ea7a4

// WARN:
// Mis-confguration can lead to problem that's hard to reason about:
// * At best it crash or talks nosense.
// * At worst it talks slightly difference but hard to perceive.
//
// An op has to enable INIT or FINALIZE when any of it's branch needs that pass.
// Take care about compile options (e.g., GGML_USE_xxx).
static bool GGML_OP_HAS_INIT [GGML_OP_COUNT] = { 0 };
static bool GGML_OP_HAS_FINALIZE[GGML_OP_COUNT] = { 0 };
static void ggml_setup_op_has_task_pass(void) {
{ // INIT
bool * p = GGML_OP_HAS_INIT;
p[GGML_OP_ACC ] = true;
p[GGML_OP_MUL_MAT ] = true;
p[GGML_OP_OUT_PROD ] = true;
p[GGML_OP_SET ] = true;
p[GGML_OP_GET_ROWS_BACK ] = true;
p[GGML_OP_DIAG_MASK_INF ] = true;
p[GGML_OP_DIAG_MASK_ZERO ] = true;
p[GGML_OP_CONV_1D ] = true;
p[GGML_OP_CONV_2D ] = true;
p[GGML_OP_CONV_TRANSPOSE_2D ] = true;
p[GGML_OP_FLASH_ATTN_BACK ] = true;
p[GGML_OP_CROSS_ENTROPY_LOSS ] = true;
p[GGML_OP_ADD_REL_POS ] = true;
}
{ // FINALIZE
bool * p = GGML_OP_HAS_FINALIZE;
p[GGML_OP_CROSS_ENTROPY_LOSS ] = true;
}
}

This is good enough for now

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
good first issue Good for newcomers performance Speed related topics refactoring Refactoring
Projects
Status: Done
Development

Successfully merging a pull request may close this issue.

2 participants