You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
feat(rpc): comp-time op metadata and graph validation
Refactor `ggml_op` and `GGML_OP_METADATA` using X-Macros.
This ensures compile-time synchronization between the enum
and metadata. `ggml_op_metadata_check()` verifies this
at compile time during `ggml_init`.
This enables robust graph validation in the RPC server.
Previously, malformed graphs (e.g., ADD with NULL src[1])
could cause crashes. `validate_graph_operands` now uses
the X-Macro-generated metadata (`ggml_op_get_n_src`) to check
for required non-null source operands before execution.
Invalid graphs are rejected early.
Adds `test_op_metadata_counts` to verify the metadata system.
Signed-off-by: Ville Vesilehto <[email protected]>
GGML_PRINT_DEBUG("[%s] Validating graph with %d nodes\n", __func__, graph->n_nodes);
760
+
for (uint32_t i = 0; i < (uint32_t)graph->n_nodes; ++i) {
761
+
const ggml_tensor* node = graph->nodes[i];
762
+
// Initial null check added for safety.
763
+
if (node == nullptr) {
764
+
GGML_LOG_ERROR("[%s] Graph node %d is null.\n", __func__, i);
765
+
returnfalse;
766
+
}
767
+
768
+
constint n_src = ggml_op_get_n_src(node->op);
769
+
770
+
if (n_src == -1) {
771
+
// Ops like GGML_OP_CUSTOM have variable inputs, cannot validate here.
772
+
GGML_PRINT_DEBUG("[%s] Skipping operand validation for node %d (op %s, name '%s') with variable inputs.\n", __func__, i, ggml_op_name(node->op), node->name);
773
+
continue;
774
+
} elseif (n_src == -2) {
775
+
GGML_LOG_ERROR("[%s] Graph node %d (name '%s') has invalid op type %d.\n", __func__, i, node->name, (int)node->op);
776
+
returnfalse;
777
+
} elseif (n_src > GGML_MAX_SRC) {
778
+
GGML_LOG_ERROR("[%s] Graph node %d (op %s, name '%s') requires %d sources, exceeding GGML_MAX_SRC (%d).\n", __func__, i, ggml_op_name(node->op), node->name, n_src, GGML_MAX_SRC);
779
+
returnfalse;
780
+
}
781
+
782
+
// Check required source operands
783
+
for (int s_idx = 0; s_idx < n_src; ++s_idx) {
784
+
if (node->src[s_idx] == nullptr) {
785
+
GGML_LOG_ERROR("[%s] Graph node %d (op %s, name '%s') missing required input src[%d].\n", __func__, i, ggml_op_name(node->op), node->name, s_idx);
0 commit comments