From 634ef86c43bf9201f7a9f78a64d9dd837dfa0870 Mon Sep 17 00:00:00 2001 From: nepenth <16943149+nepenth@users.noreply.github.com> Date: Thu, 3 Dec 2026 21:42:11 -0500 Subject: [PATCH] ignition: accept F16 and I16 dtypes in safetensors checkpoint inspection Signed-off-by: nepenth <16943149+nepenth@users.noreply.github.com> --- ignition/preparation/checkpoint.py | 4 +-- tests/preparation/test_checkpoint_dtypes.py | 27 +++++++++++++++++++++ 2 files changed, 29 insertions(+), 2 deletions(-) create mode 100644 tests/preparation/test_checkpoint_dtypes.py diff --git a/ignition/preparation/checkpoint.py b/ignition/preparation/checkpoint.py index a1a87037a..8e36aa7c7 100644 --- a/ignition/preparation/checkpoint.py +++ b/ignition/preparation/checkpoint.py @@ -94,8 +94,8 @@ def _parse_json(raw: bytes, source: str) -> dict: return value -_DTYPE_BYTES = {"BF16": 2, "F32": 4, "F8_E4M3": 1, "F8_E8M0": 1, - "I8": 1, "U8": 1, "U16": 2, "I32": 4, "U32": 4, "I64": 8} +_DTYPE_BYTES = {"BF16": 2, "F16": 2, "F32": 4, "F8_E4M3": 1, "F8_E8M0": 1, + "I8": 1, "U8": 1, "I16": 2, "U16": 2, "I32": 4, "U32": 4, "I64": 8} def _read_header(path: Path, shard: str) -> tuple[ShardMetadata, dict[str, TensorMetadata]]: diff --git a/tests/preparation/test_checkpoint_dtypes.py b/tests/preparation/test_checkpoint_dtypes.py new file mode 100644 index 000000000..998b5e561 --- /dev/null +++ b/tests/preparation/test_checkpoint_dtypes.py @@ -0,0 +1,27 @@ +# SPDX-FileCopyrightText: Copyright (c) 2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved. +# SPDX-FileCopyrightText: Copyright (c) 2026 Flare community contributors +# SPDX-License-Identifier: Apache-2.0 + +import json +import struct + +from ignition.preparation.checkpoint import _read_header + + +def test_read_header_accepts_f16_and_i16(tmp_path): + """EXL3 and FP16 safetensors checkpoints store F16 scales/Hadamards and I16 trellis weights.""" + header = { + "layer.suh": {"dtype": "F16", "shape": [8], "data_offsets": [0, 16]}, + "layer.trellis": {"dtype": "I16", "shape": [4, 4], "data_offsets": [16, 48]}, + } + raw_header = json.dumps(header).encode("utf-8") + shard = tmp_path / "model.safetensors" + shard.write_bytes(struct.pack("