Skip to content

Commit 5f85a5a

Browse files
committed
Resolve comments.
1 parent a8e0e4c commit 5f85a5a

File tree

6 files changed

+10
-13
lines changed

6 files changed

+10
-13
lines changed

src/ml_flashpoint/checkpoint_object_manager/buffer_metadata.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,10 @@
2121
class BufferMetadataType(ctypes.LittleEndianStructure):
2222
"""Metadata block stored at the beginning of the BufferIO buffer."""
2323

24-
_pack_ = 1
24+
_pack_ = 1 # Ensure tight packing for cross-platform consistency
2525
_fields_ = [
2626
("len_written_data", ctypes.c_uint64),
27-
# 8 bytes for MAGIC_BYTES to identify the file format version
27+
# 8 bytes for checkpoint format signature to identify the file format version
2828
("format_signature", ctypes.c_char * 8),
2929
# Pad the rest of the structure to reach METADATA_SIZE
3030
(

src/ml_flashpoint/core/checkpoint_loader.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,8 @@
4242
from ml_flashpoint.core.defaults import (
4343
COMMON_STATE_FNAME,
4444
DIRTY_MARKER_SUFFIX,
45-
FORMAT_SIGNATURE,
4645
GLOBAL_RANK_PATTERN,
46+
CheckpointFormat,
4747
default_metadata_object_name,
4848
)
4949
from ml_flashpoint.core.mlf_logging import get_logger
@@ -301,7 +301,7 @@ def read_data(
301301

302302
with self._checkpoint_object_manager.get_buffer(checkpoint_object_id) as stream:
303303
use_optimized_loader = False
304-
if stream.format_signature == FORMAT_SIGNATURE:
304+
if stream.format_signature == CheckpointFormat.MLF_FORMAT:
305305
use_optimized_loader = True
306306
_LOGGER.debug("Using optimized loader for '%s'", checkpoint_object_id.data)
307307

src/ml_flashpoint/core/checkpoint_saver.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -625,9 +625,9 @@ def _write_to_buffer_from_queue_worker(
625625
) as buffer_io_writer:
626626
# Set the format signature
627627
if use_optimized_write:
628-
buffer_io_writer.set_format_signature(CheckpointFormat.MLF_FORMAT.value)
628+
buffer_io_writer.set_format_signature(CheckpointFormat.MLF_FORMAT)
629629
else:
630-
buffer_io_writer.set_format_signature(CheckpointFormat.TORCH_SAVE.value)
630+
buffer_io_writer.set_format_signature(CheckpointFormat.TORCH_SAVE)
631631

632632
# First write tensors.
633633
for tensor_item, tensor in tensor_tuples:

src/ml_flashpoint/core/defaults.py

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,6 @@ class CheckpointFormat(bytes, Enum):
2727
MLF_FORMAT = b"MLF_TENS"
2828

2929

30-
FORMAT_SIGNATURE = CheckpointFormat.MLF_FORMAT.value
31-
32-
3330
def default_metadata_object_name() -> str:
3431
"""Returns the default object name for metadata files (i.e. filename).
3532

tests/checkpoint_object_manager/test_buffer_io.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
from ml_flashpoint.checkpoint_object_manager.buffer_io import METADATA_SIZE, BufferIO
2525
from ml_flashpoint.checkpoint_object_manager.buffer_metadata import BufferMetadataType
2626
from ml_flashpoint.checkpoint_object_manager.buffer_object.buffer_object_ext import BufferObject
27-
from ml_flashpoint.core.defaults import FORMAT_SIGNATURE
27+
from ml_flashpoint.core.defaults import CheckpointFormat
2828

2929

3030
# --- Mocks and Fixtures ---
@@ -994,7 +994,7 @@ def test_buffer_io_does_not_set_signature_automatically(self, temp_dir_path):
994994
# BufferIO should NOT auto-set signature.
995995
sig = bio.format_signature
996996

997-
assert sig != FORMAT_SIGNATURE, f"BufferIO SHOULD NOT auto-set signature. Got {sig!r}"
997+
assert sig != CheckpointFormat.MLF_FORMAT, f"BufferIO SHOULD NOT auto-set signature. Got {sig!r}"
998998

999999
def test_set_format_signature(self, temp_dir_path):
10001000
"""Test that set_format_signature correctly updates the metadata."""

tests/core/test_checkpoint_saver.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@
3939
from ml_flashpoint.checkpoint_object_manager.object_manager import object_manager_ext
4040
from ml_flashpoint.core.checkpoint_id_types import CheckpointContainerId, CheckpointObjectId
4141
from ml_flashpoint.core.checkpoint_saver import DefaultMLFlashpointCheckpointSaver, WriteItemResolver
42-
from ml_flashpoint.core.defaults import FORMAT_SIGNATURE
42+
from ml_flashpoint.core.defaults import CheckpointFormat
4343
from ml_flashpoint.replication.replication_manager import ReplicationManager
4444

4545

@@ -202,7 +202,7 @@ def test_write_data_with_optimized_save_false(self, chkpt_object_manager, replic
202202
assert buffer_io is not None
203203
with buffer_io:
204204
magic = buffer_io.read(8)
205-
assert magic != FORMAT_SIGNATURE
205+
assert magic != CheckpointFormat.MLF_FORMAT
206206

207207
# Reset position for loading
208208
buffer_io.seek(0)

0 commit comments

Comments
 (0)