Skip to content

refactor: reuse sam3_read_f32 for small embedding readbacks - #32

Merged
PABannier merged 2 commits into
mainfrom
cleanup/reuse-read-f32
Sep 16, 2026
Merged

PABannier merged 2 commits into
mainfrom
cleanup/reuse-read-f32

Conversation

@PABannier

Copy link
Copy Markdown
Owner

Six places in sam3.cpp open-code the same readback:

if (t->type == GGML_TYPE_F16) { read into tmp; ggml_fp16_to_fp32_row(...); } else { read F32; }

The tensors are pe_gaussian, the 4 point_embeds, not_a_point_embed, no_mask_embed, no_obj_embed_spatial and no_obj_ptr. sam3_read_f32(t, dst, n) already does exactly this, and it also dequantizes quantized tensors, which the inline copies would have misread as F32. Each site becomes one call.

Stacked on #25 because the no_obj_ptr read sits inside sam3_track_frame, which #25 restructures. Merge #25 first; GitHub will retarget this PR to main. The identical readbacks in the test-API region are left alone, since #20 deletes them.

Verification: a parity tool runs encode, PVS point + box, and a 3-frame visual track, then compares the output byte for byte with origin/main. The prompt-encoder caches and the SAM2.1 no_obj_embed_spatial path are covered.

PARITY OK   edgetam_f16 gpu0
PARITY OK   edgetam_f16 gpu1
PARITY OK   sam2.1_hiera_tiny_q8_0 gpu0
PARITY OK   sam2.1_hiera_tiny_q8_0 gpu1

The no_obj_ptr read in sam3_track_frame (text-prompted SAM3) only has a compile check, because no full SAM3 checkpoint is available locally.

git diff --shortstat: 1 file changed, 7 insertions(+), 49 deletions(-).

Part of an over-engineering cleanup series.

🤖 Generated with Claude Code

https://claude.ai/code/session_01M2qLmQ9ag49hT61V6i9qAq

PABannier and others added 2 commits September 11, 2026 13:51
…te_frame

Move the duplicated code into static helpers: active/pending masklet
propagation, memory encode + object pointer store, active commit +
tracker update, mask-to-detection, and the post-processing. Call order
and behavior are unchanged in both functions. track_frame keeps its
pending masks in a scratch map, as before.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01M2qLmQ9ag49hT61V6i9qAq
Six sites open-coded "if F16 { read + ggml_fp16_to_fp32_row } else
{ read F32 }" for pe_gaussian, point_embed, not_a_point_embed,
no_mask_embed, no_obj_embed_spatial and no_obj_ptr. sam3_read_f32 already
does exactly that, and it also handles quantized tensors.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01M2qLmQ9ag49hT61V6i9qAq
Base automatically changed from cleanup/dedupe-track-propagate to main September 16, 2026 18:55
@PABannier
PABannier merged commit 0d3b1d0 into main Sep 16, 2026
@PABannier
PABannier deleted the cleanup/reuse-read-f32 branch September 16, 2026 18:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant