Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 9626f4f

Browse filesBrowse files
committed
convert-*.py: lint check and add back in type templates
1 parent 9a6062d commit 9626f4f
Copy full SHA for 9626f4f

File tree

Expand file treeCollapse file tree

2 files changed

+17
-10
lines changed
Filter options
Expand file treeCollapse file tree

2 files changed

+17
-10
lines changed

‎convert-hf-to-gguf.py

Copy file name to clipboardExpand all lines: convert-hf-to-gguf.py
+17-8Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
from enum import IntEnum
1313
from pathlib import Path
1414
from hashlib import sha256
15-
from typing import TYPE_CHECKING, Any, Callable, ContextManager, Iterable, Iterator, Sequence, TypeVar, cast
15+
from typing import TYPE_CHECKING, Any, Callable, ContextManager, Iterable, Iterator, Sequence, TypeVar, cast, Optional
1616
from dataclasses import dataclass
1717

1818
import math
@@ -148,18 +148,27 @@ def get_model_name(metadata, hyperparameters, dir_model, model_arch):
148148
return gguf.MODEL_ARCH_NAMES[model_arch]
149149
self.model_name = get_model_name(self.metadata, self.hparams, self.dir_model, self.model_arch)
150150

151-
# Generate default filename based on model specification and available metadata
152-
def extract_encoding_scheme(ftype):
153-
# Extracts and converts the encoding scheme from the given file type name.
154-
# e.g. 'gguf.LlamaFileType.ALL_F32' --> 'F32'
155-
return ftype.name.partition("_")[2].upper()
151+
# Extracts and converts the encoding scheme from the given file type name. e.g. 'gguf.LlamaFileType.ALL_F32' --> 'F32'
152+
encodingScheme = self.ftype.name.partition("_")[2]
153+
154+
# Get Expert Count From Hyperparameters
156155
expert_count = self.hparams["num_local_experts"] if "num_local_experts" in self.hparams else None
157-
self.fname_default = f"{gguf.naming_convention(self.model_name, self.metadata.version, expert_count, self.parameter_count(), extract_encoding_scheme(self.ftype))}"
156+
157+
# Generate default filename based on model specification and available metadata
158+
self.fname_default = gguf.naming_convention(self.model_name, self.metadata.version, expert_count, self.parameter_count(), encodingScheme)
158159

159160
# Filename Output
160161
if fname_out is not None:
161162
# custom defined filename and path was provided
162-
self.fname_out = fname_out
163+
def fill_templated_filename(filename: str, encodingScheme: str):
164+
# Given a file name fill in any type templates e.g. 'some-model-name.{ftype}.gguf'
165+
ftype_uppercase: str = encodingScheme.upper()
166+
ftype_lowercase: str = encodingScheme.lower()
167+
return filename.format(ftype_lowercase,
168+
outtype=ftype_lowercase, ftype=ftype_lowercase,
169+
OUTTYPE=ftype_uppercase, FTYPE=ftype_uppercase)
170+
171+
self.fname_out = fname_out.parent / fill_templated_filename(fname_out.name, encodingScheme)
163172
else:
164173
# output in the same directory as the model by default
165174
self.fname_out = dir_model.parent / self.fname_default

‎convert.py

Copy file name to clipboardExpand all lines: convert.py
-2Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1320,8 +1320,6 @@ def pick_output_type(model: LazyModel, output_type_str: str | None) -> GGMLFileT
13201320

13211321
def model_parameter_count(model: LazyModel) -> int:
13221322
# TODO: Ensure parameter count is accurate throughout various model type
1323-
# May currently overestimate parameter count in Mamba model because
1324-
# output weights is tied with token embeddings.
13251323
total_model_parameters = 0
13261324
for name, lazy_tensor in model.items():
13271325
# Got A Tensor

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.