Repository navigation
refactor: share tensor writer across ggml converters - #19
Merged
Merged
Conversation
convert_sam3/sam2/edgetam_to_ggml.py each carried a copy of write_tensor and the FTYPE constants. Move them to ggml_writer.py, parameterised by the keep-f32 name substrings (sam3 adds "freqs_cis", edgetam adds "latents"). Output bytes are unchanged. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01M2qLmQ9ag49hT61V6i9qAq
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What / why
convert_sam3_to_ggml.py,convert_sam2_to_ggml.pyandconvert_edgetam_to_ggml.pyeach had their own copy ofwrite_tensor(the 32-byte-aligned tensor record writer) and of theFTYPE_F32/F16constants. The copies differed only in which name substrings are kept as f32.This PR moves that code into a new
ggml_writer.pyat the repo root.write_tensor(fout, name, data, ftype, keep_f32=KEEP_F32)takes the substrings as a parameter:KEEP_F32KEEP_F32 + ("freqs_cis",)KEEP_F32 + ("latents",)"pos_embed"is no longer listed separately because"embed"already matches it.rename_keyandwrite_headerreally do differ between the converters, so they stay where they are. The now-unusednumpyimport is removed from the sam2 and edgetam converters.Verification
A throwaway script (not committed) pulled the old
write_tensorand FTYPE constants out of each file atorigin/mainwithast. It compared them against the new shared function, called with the extra arguments read from each converter's realwrite_tensor(...)call. Every write went to aBytesIOand the bytes were compared. Test matrix:pos_embed,freqs_cis,latents,perceiver.latents_2d, normal.weight/.biasnamesResult: 20,160 cases (6,720 per converter) plus 3 streams, all byte-identical.
I also checked that every file parses with
astand passespy_compile.--helpruns for all three converters when invoked by absolute path from a different cwd, with only numpy installed (torch is imported lazily insidemain). That matches howscripts/download_model.shcalls them; the README usesuv run python convert_*.pyfrom the repo root.Diff
Caveats
ggml_writer.pybeing in the same directory. That holds for every documented invocation (README,scripts/download_model.sh), but copying a single converter somewhere else on its own will no longer work.🤖 Generated with Claude Code
https://claude.ai/code/session_01M2qLmQ9ag49hT61V6i9qAq