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

convert-*.py: GGUF Naming Convention Refactor and Metadata Override Refactor #7499

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 66 commits into from
Jul 18, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
66 commits
Select commit Hold shift + click to select a range
d3a936f
convert-*.py: licence -> license
mofosyne May 28, 2024
dbb1b47
convert-*.py: add --get-outfile command and refactor
mofosyne May 23, 2024
a42c2b7
convert-*.py: add basename and finetune metadata
mofosyne May 30, 2024
916872f
convert-*.py: model card metadata
mofosyne May 31, 2024
4d5f18a
convert-*.py: metadata class moved to utility
mofosyne Jun 1, 2024
5c263cb
convert-*.py: encoding_scheme --> output_type
mofosyne Jun 1, 2024
b36e391
convert-*.py: parse model card in metadata util. Add license_link and…
mofosyne Jun 2, 2024
8f73408
convert-*.py: add base_version and add tags
mofosyne Jun 2, 2024
0f1d50f
convert-*.py: add parameter size class
mofosyne Jun 2, 2024
684c604
convert-*.py: add datasets and language to KV store
mofosyne Jun 2, 2024
b1927ee
convert-*.py: move per model weight estimation away from util back to…
mofosyne Jun 2, 2024
f7c2079
convert-*.py: enable --model-name direct metadata override
mofosyne Jun 2, 2024
5a86dfa
convert-*.py: add general.organization to kv store
mofosyne Jun 2, 2024
dd15712
convert-*.py: add quantized_by and enhance heuristics
mofosyne Jun 3, 2024
b0553f4
convert-*.py: adjust help message
mofosyne Jun 3, 2024
4d5cd06
convert-*.py: use heuristics to parse _name_or_path
mofosyne Jun 3, 2024
32e80e0
convert-*.py: base_model is actually in spec for model cards
mofosyne Jun 3, 2024
54918ad
convert-*.py: refactor parameter weight class
mofosyne Jun 3, 2024
39472a0
convert-*.py: need to include self in per_model_weight_count_estimati…
mofosyne Jun 3, 2024
3625a42
convert-*.py: add heuristic to directory name fallback
mofosyne Jun 3, 2024
91e65d9
convert-*.py: add unittest to metadata class
mofosyne Jun 4, 2024
d060fcd
convert-*.py: adjusted authorship KV store
mofosyne Jun 6, 2024
eaa47f5
convert-*.py: separated unit test, hf_repo to repo_url
mofosyne Jun 8, 2024
e973443
convert-*.py: Remove self.model_name that was left in since last rebase
mofosyne Jun 9, 2024
5011eef
convert_hf_to_gguf.py: optional, dataclass removed from type as it wa…
mofosyne Jul 7, 2024
2f23927
convert_hf_to_gguf.py: rebase error correction
mofosyne Jul 7, 2024
4dc8ddd
convert_hf_to_gguf.py: Remove code that is already in fill_templated_…
mofosyne Jul 7, 2024
007708e
gguf_writer.py: generate tensor uuid if missing
mofosyne Jul 8, 2024
7ecb8f0
test: remove test_gguf.py and remove test_generate_any_missing_uuid()
mofosyne Jul 9, 2024
fdc5a3f
convert-*.py: autogenerate general.uuid if missing
mofosyne Jul 9, 2024
2a976e1
convert-*.py: write_tensors() --> prepare_tensors_for_writing()
mofosyne Jul 10, 2024
59a01df
convert-*.py: refactor per model weight count estimation
mofosyne Jul 10, 2024
dd14b8f
convert-*.py: pyright type fixes
mofosyne Jul 10, 2024
74383ba
Apply suggestions from code review
mofosyne Jul 11, 2024
4c91d07
convert-*.py: cast not required if Metadata.load_metadata_override re…
mofosyne Jul 11, 2024
6eb08ac
convert-*.py: Removing the redundant metadata is not None from all co…
mofosyne Jul 11, 2024
f8b5931
convert-*.py: parameter_class_attribute --> size_label
mofosyne Jul 11, 2024
64707b6
convert-*.py: remove redundant gguf_writer.add_name() calls
mofosyne Jul 11, 2024
04c4fff
convert-*.py: prepare_tensors_for_writing() --> prepare_tensors()
mofosyne Jul 11, 2024
f2b425c
convert-*.py: import cast from typing and other refactor
mofosyne Jul 11, 2024
ad217d7
convert-*.py: remove autogenerated uuid
mofosyne Jul 13, 2024
60278e4
Update convert_hf_to_gguf.py
mofosyne Jul 13, 2024
aa4e589
Update convert_hf_to_gguf.py
mofosyne Jul 13, 2024
2c06030
Update constants.py : spacing correction
mofosyne Jul 13, 2024
8156835
constants.py : Revert removal of backward compatibility KEY_GENERAL_S…
mofosyne Jul 13, 2024
ccff6c7
convert-*.py: remove reference to uuid generation
mofosyne Jul 13, 2024
455c0e5
Apply suggestions from code review
mofosyne Jul 14, 2024
5ab1a84
convert-*.py: dict_item --> Iterable
mofosyne Jul 14, 2024
5cdb03b
convert-*.py: update nix package to add python frontmatter
mofosyne Jul 14, 2024
9954b64
convert-*.py: add logger and refactor load_model_card()
mofosyne Jul 14, 2024
abc351c
convert-*.py: quantized_by in model card is not relevant for converte…
mofosyne Jul 14, 2024
144a7ec
convert-*.py: pathlib.Path exist() --> is_file() or is_dir()
mofosyne Jul 14, 2024
8629b7b
covert-*.py: per_model_weight_count_estimation() tensor arg type is I…
mofosyne Jul 14, 2024
4e37611
covert-*.py: flake8 newline missing
mofosyne Jul 14, 2024
f98f109
convert-*.py: more rigorous regexp for get_model_id_components()
mofosyne Jul 14, 2024
3b1766a
convert-*.py: flake8 remove blank line
mofosyne Jul 14, 2024
78a42fb
gguf-py : use pyyaml instead of python-frontmatter
compilade Jul 14, 2024
417d7a7
convert_hf : use GGUFWriter to count model parameters
compilade Jul 15, 2024
9a925b5
metadata.py: account for decimal point in size label within model id …
mofosyne Jul 15, 2024
c7b3616
Update convert_hf_to_gguf.py
mofosyne Jul 15, 2024
5da16bb
Merge branch 'master' into refactor-convert-py
mofosyne Jul 16, 2024
eb0bf6b
convert-*.py: Add naming_convention_vocab_only()
mofosyne Jul 16, 2024
7e9271c
convert_lora_to_gguf.py: remove model_name parameter. Doesn't exist i…
mofosyne Jul 16, 2024
2c18a9a
gguf-py : extract metadata from model name more resiliently
compilade Jul 18, 2024
4c9932c
gguf-py : fix flake8 lint
compilade Jul 18, 2024
73899f7
gguf-py : handle more name metadata extraction edge cases
compilade Jul 18, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
convert-*.py: add basename and finetune metadata
  • Loading branch information
mofosyne committed Jul 15, 2024
commit a42c2b7efc720d4d36a258d7430b33c82ec3bfd0
10 changes: 9 additions & 1 deletion 10 convert_hf_to_gguf.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@
@dataclass
class Metadata:
name: Optional[str] = None
basename: Optional[str] = None
finetune: Optional[str] = None
author: Optional[str] = None
version: Optional[str] = None
url: Optional[str] = None
Expand All @@ -55,6 +57,8 @@ def load(metadata_path: Path) -> Metadata:
# Assigning values to Metadata attributes if they exist in the JSON file
# This is based on LLM_KV_NAMES mapping in llama.cpp
metadata.name = data.get("general.name")
metadata.basename = data.get("general.basename")
metadata.finetune = data.get("general.finetune")
metadata.author = data.get("general.author")
metadata.version = data.get("general.version")
metadata.url = data.get("general.url")
Expand Down Expand Up @@ -201,7 +205,7 @@ def per_model_weight_count_estimation(tensors, expert_count):
weight_estimate = per_model_weight_count_estimation(model_tensors, expert_count)

# Generate default filename based on model specification and available metadata
self.fname_default = gguf.naming_convention(self.model_name, self.metadata.version, expert_count, weight_estimate, encodingScheme)
self.fname_default = gguf.naming_convention(self.model_name, self.metadata.basename, self.metadata.finetune, self.metadata.version, expert_count, weight_estimate, encodingScheme)

# Filename Output
if fname_out is not None:
Expand Down Expand Up @@ -311,6 +315,10 @@ def set_gguf_meta_model(self):
self.gguf_writer.add_name(self.model_name)

if self.metadata is not None:
if self.metadata.basename is not None:
self.gguf_writer.add_basename(self.metadata.basename)
if self.metadata.finetune is not None:
self.gguf_writer.add_finetune(self.metadata.finetune)
if self.metadata.author is not None:
self.gguf_writer.add_author(self.metadata.author)
if self.metadata.version is not None:
Expand Down
12 changes: 11 additions & 1 deletion 12 examples/convert_legacy_llama.py
Original file line number Diff line number Diff line change
Expand Up @@ -349,6 +349,8 @@ def load(model_plus: ModelPlus) -> Params:
@dataclass
class Metadata:
name: Optional[str] = None
basename: Optional[str] = None
finetune: Optional[str] = None
author: Optional[str] = None
version: Optional[str] = None
url: Optional[str] = None
Expand All @@ -371,6 +373,8 @@ def load(metadata_path: Path) -> Metadata:
# Assigning values to Metadata attributes if they exist in the JSON file
# This is based on LLM_KV_NAMES mapping in llama.cpp
metadata.name = data.get("general.name")
metadata.basename = data.get("general.basename")
metadata.finetune = data.get("general.finetune")
metadata.author = data.get("general.author")
metadata.version = data.get("general.version")
metadata.url = data.get("general.url")
Expand Down Expand Up @@ -820,6 +824,10 @@ def add_meta_model(self, params: Params, metadata: Metadata | None) -> None:
self.gguf.add_name(name)

if metadata is not None:
if metadata.basename is not None:
self.gguf.add_basename(metadata.basename)
if metadata.finetune is not None:
self.gguf.add_finetune(metadata.finetune)
if metadata.author is not None:
self.gguf.add_author(metadata.author)
if metadata.version is not None:
Expand Down Expand Up @@ -1226,6 +1234,8 @@ def load_vocab(self, vocab_types: list[str] | None, model_parent_path: Path) ->

def default_convention_outfile(file_type: GGMLFileType, model_name:str, expert_count:int, model_params_count: int, metadata: Metadata) -> str:
name = metadata.name if metadata is not None and metadata.name is not None else model_name
basename = metadata.basename if metadata is not None and metadata.basename is not None else None
finetune = metadata.finetune if metadata is not None and metadata.finetune is not None else None
version = metadata.version if metadata is not None and metadata.version is not None else None

encodingScheme = {
Expand All @@ -1234,7 +1244,7 @@ def default_convention_outfile(file_type: GGMLFileType, model_name:str, expert_c
GGMLFileType.MostlyQ8_0: "Q8_0",
}[file_type]

return gguf.naming_convention(name, version, expert_count, model_params_count, encodingScheme)
return gguf.naming_convention(name, basename, finetune, version, expert_count, model_params_count, encodingScheme)


def default_outfile(model_paths: list[Path], file_type: GGMLFileType, model_name:str, expert_count:int, model_params_count: int, metadata: Metadata) -> Path:
Expand Down
2 changes: 2 additions & 0 deletions 2 gguf-py/gguf/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ class General:
QUANTIZATION_VERSION = "general.quantization_version"
ALIGNMENT = "general.alignment"
NAME = "general.name"
BASENAME = "general.basename"
FINETUNE = "general.finetune"
AUTHOR = "general.author"
VERSION = "general.version"
URL = "general.url"
Expand Down
6 changes: 6 additions & 0 deletions 6 gguf-py/gguf/gguf_writer.py
Original file line number Diff line number Diff line change
Expand Up @@ -430,6 +430,12 @@ def add_type(self, type_name: str) -> None:
def add_architecture(self) -> None:
self.add_string(Keys.General.ARCHITECTURE, self.arch)

def add_basename(self, basename: str) -> None:
self.add_string(Keys.General.BASENAME, basename)

def add_finetune(self, finetune: str) -> None:
self.add_string(Keys.General.FINETUNE, finetune)

def add_author(self, author: str) -> None:
self.add_string(Keys.General.AUTHOR, author)

Expand Down
29 changes: 22 additions & 7 deletions 29 gguf-py/gguf/utility.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,26 @@ def model_weight_count_rounded_notation(model_params_count: int) -> str:
return f"{round(scaled_model_params)}{scale_suffix}"


def naming_convention(model_name: str, version_string:str, expert_count_int:int, model_params_count: int, encodingScheme: str) -> str:
def naming_convention(model_name: str, base_name: str, finetune_string:str, version_string:str, expert_count_int:int, model_params_count: int, encoding_scheme: str) -> str:
# Reference: https://github.com/ggerganov/ggml/blob/master/docs/gguf.md#gguf-naming-convention
name = model_name.strip().replace(' ', '-') if model_name is not None else "ggml-model"
version = f"-{version_string}" if version_string is not None else ""
expert_count_chunk = f"{expert_count_int}x" if expert_count_int is not None and expert_count_int > 0 else ""
parameters = model_weight_count_rounded_notation(model_params_count)
encodingScheme = encodingScheme.upper()
return f"{name}{version}-{expert_count_chunk}{parameters}-{encodingScheme}"

if base_name is not None:
name = base_name.strip().title().replace(' ', '_')
elif model_name is not None:
name = model_name.strip().title().replace(' ', '_')
else:
name = "ggml-model"

per_model_rounded_weight_estimate = model_weight_count_rounded_notation(model_params_count)
if expert_count_int is not None and expert_count_int > 0:
parameters = f"-{expert_count_int}x{per_model_rounded_weight_estimate}"
else:
parameters = f"-{per_model_rounded_weight_estimate}"

finetune = f"-{finetune_string.strip().title().replace(' ', '_')}" if finetune_string is not None else ""

version = f"-{version_string.strip().replace(' ', '_')}" if version_string is not None else ""

encoding = f"-{encoding_scheme.strip().replace(' ', '_').upper()}"

return f"{name}{parameters}{finetune}{version}{encoding}"
Morty Proxy This is a proxified and sanitized view of the page, visit original site.