Repository navigation
refactor: use sam3_graph_compute in sam2_encode_image_hiera - #31
Conversation
| @@ -5938,11 +5938,7 @@ static bool sam2_encode_image_hiera(sam3_state& state, | |||
| } | |||
There was a problem hiding this comment.
Fix the merge conflicts
There was a problem hiding this comment.
Rebased onto main; conflict resolved and force-pushed. GitHub now reports the PR as mergeable.
The conflict was with #27 (RAII contexts/allocators), which had already deleted the manual ggml_gallocr_free(galloc); ggml_free(ctx0); lines this diff sat on top of. Resolution keeps #27's version, so the failure path is just return false;:
// Compute
if (!sam3_graph_compute(model.backend, graph, state.n_threads)) {
return false;
}The diff is now 1 insertion, 5 deletions in sam2_encode_image_hiera — the thread-count setup, the status check and the duplicate error print, all of which sam3_graph_compute already does (it also logs the status string).
Verified: encode, PVS point + box, and a 3-frame visual track match main byte for byte on EdgeTAM f16 and SAM2.1-tiny q8_0, CPU and Metal (PARITY OK ×4); the SAM2.1 runs go through this function. A Release build with -DSAM3_BUILD_TESTS=ON has no errors or new warnings.
One note for later, left out to keep this diff as reviewed: sam3_encode_vit_from_preprocessed_selective (~sam3.cpp:7128) still open-codes the same pattern. It's in the test/debug region that #27 skipped, so it kept its manual frees and needs a slightly different edit.
sam2_encode_image_hiera hand-rolled the CPU thread-count setup and ggml_backend_graph_compute status check that sam3_graph_compute already does. The helper also logs the status string, so the caller's duplicate error print goes too. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01M2qLmQ9ag49hT61V6i9qAq
de3bbb5 to
e49a2c1
Compare
sam2_encode_image_hieraopen-coded exactly whatsam3_graph_computedoes: set the CPU thread count when the backend is CPU, runggml_backend_graph_compute, and check the status. Every other stage insam3.cppalready goes through the helper. The helper also logsgraph compute failed: <status>, so the caller's own error print at this call site is dropped.Rebased onto
main. The earlier conflict was with #27 (RAII contexts/allocators), which had already removed the manualggml_gallocr_free/ggml_freelines this diff sat on; the failure path is now justreturn false;.Verification: a parity tool runs encode, PVS point + box, and a 3-frame visual track, then compares the output byte for byte with
main. The SAM2.1 runs go through this function.A Release build with
-DSAM3_BUILD_TESTS=ONhas no errors or new warnings.git diff --shortstat main: 1 file changed, 1 insertion(+), 5 deletions(-).Not fixed here, to keep the diff as reviewed:
sam3_encode_vit_from_preprocessed_selective(~sam3.cpp:7128) still open-codes the same pattern, inside the test/debug region that #27 skipped.Part of an over-engineering cleanup series.
🤖 Generated with Claude Code
https://claude.ai/code/session_01M2qLmQ9ag49hT61V6i9qAq