llama.cpp/gguf-py/tests
FrozenScorch 22f18a4838 gguf-py: add type validation to GGUFWriter.add_key_value (#9095)
Currently add_key_value() accepts any Python value and silently passes it
to struct.pack, which produces garbage when types are wrong (e.g. a list
passed where a string is expected).  The failure only surfaces later as
an opaque struct.error during serialization, making bugs hard to diagnose.

This adds a _validate_value_type() classmethod that checks values against
the declared GGUFValueType before storing them, raising a clear TypeError
that includes the key name, expected type, actual type, and value.

Key design decisions:
- Reject bool for integer/float types (Python bool is int subclass)
- Accept int for float types (struct.pack handles this; conversion
  scripts commonly pass integer literals like eps=0)
- Accept numpy scalar types (np.integer, np.floating, np.bool_)
- Allow bytes for ARRAY (used by add_array for UINT8 data like
  precompiled_charsmap)
- Reject None for all types

Co-Authored-By: Claude <noreply@anthropic.com>
2026-03-31 23:00:44 -04:00
..
__init__.py convert-*.py: GGUF Naming Convention Refactor and Metadata Override Refactor (#7499) 2024-07-18 20:40:15 +10:00
test_gguf_writer.py gguf-py: add type validation to GGUFWriter.add_key_value (#9095) 2026-03-31 23:00:44 -04:00
test_metadata.py chore : correct typos [no ci] (#20041) 2026-03-05 08:50:21 +01:00
test_quants.py ggml : add NVFP4 quantization type support (#19769) 2026-03-11 21:02:54 +01:00