Skip to content

test-backend-ops: enables perf/eval testing of composite ops #14833

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

Open
wants to merge 7 commits into
base: master
Choose a base branch
from

Conversation

etasnadi
Copy link
Contributor

This patch adds support for testing computation graphs "composite ops" in test-backend-ops.

This is useful

  • when measuring the performance gains of fused ops compared to indirect implementations,
  • in op development to check the correctness if the implementation of the op under development does not exist yet on CPU but it's equivalent computation graph can be built by combining existing ops forming a composite op.

Currently out of the tree code is used to test the correctness (#14316 or #14316) or non-standardized out-of-tree vibe coded standalone gists added to test the performance in #14388 (comment).

In particular, this PR enables

  • comparing the output of computation graphs when executed on backend1 vs backend2,
  • comparing the output of a computation graph to the output of a regular op or even comparing two composite ops if it makes sense,
  • performance testing of computation graphs.

An example is when we compare the output of CONV_2D (direct conv implementation) with the ggml_conv_2d (indirect conv implementation as the latter contains im2col followed by a mul_mat in the resulting graph).

To test output of an op against a graph, the user needs to add a test case for the graph and the actual op, then they need to subclass a test_case_compare : public test_case that accepts the two test cases in the constructor. The tensor name assignment should be defined in test_case_compare to let the eval() function know how to copy the inputs between the two graphs before execution. The output nodes will then be compared after execution.

When testing the perf of a graph, the get_input_names of test_case should be overwritten to return the name of the input tensors that will be used by eval_perf to know which nodes should be duplicated. The default implementation returns an empty list and eval_perf assumes that the graph tests a regular op containing only the input nodes connected to a single output node doing the actual calculation, so only the output will be duplicated in this case.

@github-actions github-actions bot added testing Everything test related ggml changes relating to the ggml tensor library for machine learning labels Jul 23, 2025
@etasnadi etasnadi changed the title Enables perf/eval testing of composite ops in test-backend-ops. test-backend-ops: enables perf/eval testing of composite ops Jul 23, 2025
@CISC CISC requested a review from Copilot July 24, 2025 10:07
Copy link

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR adds support for testing computation graphs "composite ops" in test-backend-ops, enabling performance and correctness evaluation of fused operations compared to indirect implementations. This is useful for op development when the direct implementation doesn't exist on CPU but can be tested via equivalent computation graphs.

  • Introduces test_case_compare class for comparing outputs between different operation implementations
  • Adds support for composite operation performance testing with proper node duplication logic
  • Implements example comparison between direct CONV_2D and im2col-based CONV_2D implementations

Reviewed Changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 5 comments.

File Description
tests/test-backend-ops.cpp Main implementation adding composite op testing infrastructure and CONV_2D comparison examples
ggml/src/ggml-backend.cpp Adds new function for comparing outputs between two different computation graphs
ggml/include/ggml-backend.h Declares the new graph comparison function in the public API
Comments suppressed due to low confidence (1)

@ggml-org ggml-org deleted a comment from Copilot AI Jul 24, 2025
@ggml-org ggml-org deleted a comment from Copilot AI Jul 24, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
ggml changes relating to the ggml tensor library for machine learning testing Everything test related
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants