Skip to content

Commit

Permalink
gguf-dump.py: Rename variables and adjust comments
Browse files Browse the repository at this point in the history
start_data_offset --> data_offset

_build_tensors_info_fields --> _build_tensor_info
  • Loading branch information
mofosyne committed Jun 24, 2024
1 parent babf263 commit beb8023
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 10 deletions.
18 changes: 9 additions & 9 deletions gguf-py/gguf/gguf_reader.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ class GGUFReader:
# I - same as host, S - swapped
byte_order: Literal['I'] | Literal['S'] = 'I'
alignment: int = GGUF_DEFAULT_ALIGNMENT
start_data_offset: int
data_offset: int

# Note: Internal helper, API may change.
gguf_scalar_to_np: dict[GGUFValueType, type[np.generic]] = {
Expand Down Expand Up @@ -117,7 +117,7 @@ def __init__(self, path: os.PathLike[str] | str, mode: Literal['r'] | Literal['r
offs = self._build_fields(offs, kv_count)

# Build Tensor Info Fields
offs, tensors_fields = self._build_tensors_info_fields(offs, tensor_count)
offs, tensors_fields = self._build_tensor_info(offs, tensor_count)
new_align = self.fields.get('general.alignment')
if new_align is not None:
if new_align.types != [GGUFValueType.UINT32]:
Expand All @@ -126,7 +126,7 @@ def __init__(self, path: os.PathLike[str] | str, mode: Literal['r'] | Literal['r
padding = offs % self.alignment
if padding != 0:
offs += self.alignment - padding
self.start_data_offset = offs
self.data_offset = offs
self._build_tensors(offs, tensors_fields)

_DT = TypeVar('_DT', bound = npt.DTypeLike)
Expand Down Expand Up @@ -206,23 +206,23 @@ def _get_field_parts(
def _get_tensor_info_field(self, orig_offs: int) -> ReaderField:
offs = orig_offs

# Tensor Info Name
# Get Tensor Name
name_len, name_data = self._get_str(offs)
offs += int(name_len.nbytes + name_data.nbytes)

# Tensor Info Dimensions Count
# Get Tensor Dimensions Count
n_dims = self._get(offs, np.uint32)
offs += int(n_dims.nbytes)

# Tensor Info Dimension Array
# Get Tensor Dimension Array
dims = self._get(offs, np.uint64, n_dims[0])
offs += int(dims.nbytes)

# Tensor Info Tensor Type
# Get Tensor Encoding Scheme Type
raw_dtype = self._get(offs, np.uint32)
offs += int(raw_dtype.nbytes)

# Tensor Info Offset
# Get Tensor Offset
offset_tensor = self._get(offs, np.uint64)
offs += int(offset_tensor.nbytes)

Expand Down Expand Up @@ -254,7 +254,7 @@ def _build_fields(self, offs: int, count: int) -> int:
offs += field_size
return offs

def _build_tensors_info_fields(self, offs: int, count: int) -> tuple[int, list[ReaderField]]:
def _build_tensor_info(self, offs: int, count: int) -> tuple[int, list[ReaderField]]:
tensor_fields = []
for _ in range(count):
field = self._get_tensor_info_field(offs)
Expand Down
2 changes: 1 addition & 1 deletion gguf-py/scripts/gguf-dump.py
Original file line number Diff line number Diff line change
Expand Up @@ -404,7 +404,7 @@ def main() -> None:
elif args.markdown:
dump_markdown_metadata(reader, args)
elif args.data_offset:
print(reader.start_data_offset) # noqa: NP100
print(reader.data_offset) # noqa: NP100
elif args.data_alignment:
print(reader.alignment) # noqa: NP100
else:
Expand Down

0 comments on commit beb8023

Please sign in to comment.