Restore clip's cb() to its rightful glory - extract common debugging elements in llama#17914
Restore clip's cb() to its rightful glory - extract common debugging elements in llama#17914pwilkin merged 18 commits intoggml-org:masterfrom
Conversation
tools/mtmd/clip.cpp
Outdated
| std::string t_name = std::string(name) + "_" + std::to_string(il); | ||
| ggml_tensor * args[] = { t }; | ||
| ggml_tensor * res = ggml_custom_4d(ctx0, t->type, t->ne[0], t->ne[1], t->ne[2], t->ne[3], args, 1, print_debug, 1, nullptr); | ||
| strcpy(res->name, t_name.c_str()); |
There was a problem hiding this comment.
Or even better, ggml_format_name
tools/mtmd/clip.cpp
Outdated
| ggml_tensor * args[] = { t }; | ||
| ggml_tensor * res = ggml_custom_4d(ctx0, t->type, t->ne[0], t->ne[1], t->ne[2], t->ne[3], args, 1, print_debug, 1, nullptr); | ||
| strcpy(res->name, t_name.c_str()); | ||
| ggml_build_forward_expand(gf, res); |
There was a problem hiding this comment.
I think we should guard the whole thing under ctx->debug_graph. seems like it's got removed by mistake?
tools/mtmd/clip.cpp
Outdated
| #include "ggml-cpp.h" | ||
| #include "ggml-alloc.h" | ||
| #include "ggml-backend.h" | ||
| #include "ggml/src/ggml-impl.h" |
There was a problem hiding this comment.
This should be removed - we cannot include internal header from ggml
tools/mtmd/clip.cpp
Outdated
| #include <cstring> | ||
| #include <fstream> | ||
| #include <map> | ||
| #include <memory> |
There was a problem hiding this comment.
some of these are already included by clip-impl.h - do we really need to include them again here?
|
All right, based on the convo with @ngxson I've decided to tackle this properly:
|
|
I would very much like to extend the callback procedure to (a) make it also possible in other clients (such as |
common/debug.cpp
Outdated
| * @param user_data user data to pass at each call back | ||
| * @return true to receive data or continue the graph, false otherwise | ||
| */ | ||
| template<bool abort> |
There was a problem hiding this comment.
maybe this make things more clear:
| template<bool abort> | |
| template<bool check_nan_value> |
tools/mtmd/CMakeLists.txt
Outdated
| ) | ||
|
|
||
| target_link_libraries (mtmd PUBLIC ggml llama) | ||
| target_link_libraries (mtmd PUBLIC ggml llama common) |
There was a problem hiding this comment.
libmtmd can never be linked against common - the same way libllama cannot be linked against it
instead, you must extend the mtmd_context_params to accept a cb_eval, similar to how llama_context_params works
…D_DEBUG_GRAPH with same functionality
…ctorize debug.cpp to use common debug code.
Co-authored-by: Xuan-Son Nguyen <[email protected]>
|
@ngxson aight should be good to go. |
Co-authored-by: Xuan-Son Nguyen <[email protected]>
Co-authored-by: Xuan-Son Nguyen <[email protected]>
Co-authored-by: Xuan-Son Nguyen <[email protected]>
Co-authored-by: Xuan-Son Nguyen <[email protected]>
|
@ngxson bump :) |
There was a problem hiding this comment.
Just tested it, looking good.
One small thing that I would prefer to have in this PR or a follow up one: the printed tensor has a long leading space, making it hard to read. Not sure why it's there in the first place, but better to remove it (not sure why it's there in the first place)
[
[ 0.0000, -0.0659, -0.1201, ..., -0.1427, -0.1092, -0.0488],
[ -0.1201, -0.1175, -0.0603, ..., -0.0488, -0.0956, -0.1014],
[ -0.0603, -0.1521, -0.1467, ..., -0.1014, -0.1196, -0.0856],
...,
[ -0.1674, -0.0987, -0.0784, ..., -0.0787, -0.1005, -0.1428],
[ -0.0784, -0.1367, -0.1161, ..., -0.1428, -0.1068, -0.1274],
[ -0.1161, -0.0998, -0.1306, ..., -0.1274, 0.0000, 0.0000],
],
|
@ngxson yeah that's just the original format from eval-callback, willing to discuss how to optimize. |
…elements in llama (ggml-org#17914) * Extract common debugging functions; plug eval-callback and mtmd's MTMD_DEBUG_GRAPH with same functionality * Move to common * Remove unneeded header * Unlink from common * chore: update webui build output * Cleanup; properly pass params to mtmd without depending on common; factorize debug.cpp to use common debug code. * Revert change to webapp * Post-merge adjust * Apply suggestions from code review Co-authored-by: Xuan-Son Nguyen <[email protected]> * Apply code review changes * Remove changes to server-context * Remove mtmd.h include * Remove utility functions from header * Apply suggestions from code review Co-authored-by: Xuan-Son Nguyen <[email protected]> * Rename functions * Update tools/mtmd/clip.cpp Co-authored-by: Xuan-Son Nguyen <[email protected]> * Update tools/mtmd/clip.cpp Co-authored-by: Xuan-Son Nguyen <[email protected]> * Update tools/mtmd/clip.cpp Co-authored-by: Xuan-Son Nguyen <[email protected]> --------- Co-authored-by: Xuan-Son Nguyen <[email protected]>
Cherry-picked commits: - e047f9e: mtmd: fix use_non_causal being reported incorrectly (ggml-org#18793) - d98b548: Restore clip's cb() to its rightful glory (ggml-org#17914) - c945aaa: mtmd: Fix ASR for LFM2.5-Audio-1.5B (ggml-org#18876) These fixes are required for VL (vision-language) model inference to work correctly with llama-mtmd-cli. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <[email protected]>
…elements in llama (ggml-org#17914) * Extract common debugging functions; plug eval-callback and mtmd's MTMD_DEBUG_GRAPH with same functionality * Move to common * Remove unneeded header * Unlink from common * chore: update webui build output * Cleanup; properly pass params to mtmd without depending on common; factorize debug.cpp to use common debug code. * Revert change to webapp * Post-merge adjust * Apply suggestions from code review Co-authored-by: Xuan-Son Nguyen <[email protected]> * Apply code review changes * Remove changes to server-context * Remove mtmd.h include * Remove utility functions from header * Apply suggestions from code review Co-authored-by: Xuan-Son Nguyen <[email protected]> * Rename functions * Update tools/mtmd/clip.cpp Co-authored-by: Xuan-Son Nguyen <[email protected]> * Update tools/mtmd/clip.cpp Co-authored-by: Xuan-Son Nguyen <[email protected]> * Update tools/mtmd/clip.cpp Co-authored-by: Xuan-Son Nguyen <[email protected]> --------- Co-authored-by: Xuan-Son Nguyen <[email protected]>
I used my callback function from my Qwen3Next testing days, it seems like it works more cleanly than the previous one which was causing some problems with the scheduler / buffers.