Skip to content

refactor: skip hparams the loader stores but never reads - #34

Closed
PABannier wants to merge 1 commit into
mainfrom
cleanup/skip-unused-hparams
Closed

PABannier wants to merge 1 commit into
mainfrom
cleanup/skip-unused-hparams

Conversation

@PABannier

Copy link
Copy Markdown
Owner

The three hparams loaders (sam3_load_hparams, sam2_load_hparams, edgetam_load_extra_hparams) read 16 header fields into sam3_hparams that nothing reads again. The code hard-codes the behaviour those flags describe.

Loader Fields skipped
SAM3 ddec_ffn_dim, n_presence_tokens, n_geom_queries, n_amb_experts
SAM2 use_high_res_features, use_obj_ptrs_in_encoder, directly_add_no_mem_embed, non_overlap_masks_for_mem_enc, binarize_mask_from_pts, multimask_output_for_tracking, multimask_min_pt_num, multimask_max_pt_num, iou_prediction_use_sigmoid, use_mask_input_as_output
EdgeTAM mem_attn_ca_q_size, mem_attn_ca_k_size

These fields are removed from the struct. Each loader gets a skip(n) lambda (fin.seekg(4 * n, cur)), with the skipped field names in a trailing comment so the on-disk layout stays readable. The .ggml format doesn't change; converters still write every field.

Verification: a parity tool loads models through both SAM2 paths (SAM2.1 Hiera and EdgeTAM extra hparams), then compares encode, PVS point + box, and a 3-frame visual track byte for byte with origin/main:

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 SAM3 loader only has a compile check, because no full SAM3 checkpoint is available locally. Its change is three rd → skip swaps in the same positions.

git diff --shortstat: 1 file changed, 11 insertions(+), 32 deletions(-).

Part of an over-engineering cleanup series.

🤖 Generated with Claude Code

https://claude.ai/code/session_01M2qLmQ9ag49hT61V6i9qAq

16 sam3_hparams fields were read from the .ggml header and never used
again: ddec_ffn_dim, n_presence_tokens, n_geom_queries, n_amb_experts,
the SAM2 memory/tracking flags use_high_res_features,
use_obj_ptrs_in_encoder, directly_add_no_mem_embed,
non_overlap_masks_for_mem_enc, binarize_mask_from_pts,
multimask_output_for_tracking, multimask_{min,max}_pt_num,
iou_prediction_use_sigmoid, use_mask_input_as_output, and EdgeTAM's
mem_attn_ca_{q,k}_size. Seek past them instead, and keep their names
in comments so the file layout stays documented. The file format
itself doesn't change.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01M2qLmQ9ag49hT61V6i9qAq
@PABannier PABannier closed this Sep 16, 2026
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