feat: safetensors hyperparameter extraction with GGUF parity#70
Open
afogel wants to merge 2 commits intoGenAI-Security-Project:v0.2from
Open
feat: safetensors hyperparameter extraction with GGUF parity#70afogel wants to merge 2 commits intoGenAI-Security-Project:v0.2from
afogel wants to merge 2 commits intoGenAI-Security-Project:v0.2from
Conversation
Extract hyperparameters from safetensors repos by combining config.json (using llama.cpp's find_hparam key fallback chains), tokenizer_config.json, and safetensors tensor headers. Safetensors takes precedence over GGUF as the original source format. - Add config_parsing.py as canonical home for HPARAM_KEYS and parse_config() - Add safetensors_metadata.py with SafetensorsModelInfo, map_to_metadata(), fetch_safetensors_metadata() (config.json + tokenizer + tensor headers) - Add SafetensorsFileExtractor to model_file_extractors.py - Wire hyperparameter extraction into EnhancedExtractor via _try_config_extraction - Add safetensors>=0.4.0 as runtime dependency - 83 tests covering config parsing, metadata mapping, tensor extraction, HF Hub integration, extractor wiring, precedence, and fixture end-to-end
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.
Summary
config.json(llama.cpp'sfind_hparamkey fallback chains),tokenizer_config.json, and safetensors tensor headers viahuggingface_hub.get_safetensors_metadata()config_parsing.pymodule shared by bothsafetensors_metadata.pyandextractor.pydefault_extractors()since safetensors is the original source format that GGUF is derived fromChanges
src/models/config_parsing.pyHPARAM_KEYS+parse_config()— llama.cpp key fallback chains, VLM text_config mergesrc/models/safetensors_metadata.pySafetensorsModelInfo,map_to_metadata(),fetch_safetensors_metadata()— config + tokenizer + tensor headerssrc/models/model_file_extractors.pySafetensorsFileExtractor+ reorderdefault_extractors()(safetensors first)src/models/extractor.py_build_hyperparameters_from_config()into_try_config_extractionfor thehyperparameterfieldtests/test_safetensors_metadata.pytests/test_model_file_extraction.pytests/test_hyperparameter_wiring.pytests/fixtures/__init__.pybuild_safetensors_fixture()— real safetensors binary for end-to-end testspyproject.tomlsafetensors>=0.4.0runtime dep, dev deps to[dependency-groups]Design decisions
parse_config()works for safetensors, GGUF, pytorch — any HF repo with aconfig.json. Extracted to a shared module to avoid duplication.huggingface_hub.get_safetensors_metadata()(100KB range request) — never downloads full model weights.config.jsonandtokenizer_config.jsonare small JSON files fetched viahf_hub_download().model_type,typeOfModel,vocab_size,context_length,tokenizer_class,hyperparameterdict (includingrope_dimension_count), plussafetensors_total_parameters.hyperparameterdict format thatextractor.pyandservice.pyalready handle generically.Test plan
uv run pytest tests/test_safetensors_metadata.py -v— 40 testsuv run pytest tests/test_model_file_extraction.py -v— 17 tests (including new safetensors + precedence tests)uv run pytest tests/test_hyperparameter_wiring.py -v— 8 testsuv run pytest tests/test_gguf_metadata.py -v— 18 tests (no regressions)