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 general.organization to kv store
  • Loading branch information
mofosyne committed Jul 15, 2024
commit 5a86dfaa1c7a934da3a7a29a22aa0b6eab15615d
2 changes: 2 additions & 0 deletions 2 convert_hf_to_gguf.py
Original file line number Diff line number Diff line change
Expand Up @@ -244,6 +244,8 @@ def set_gguf_meta_model(self):
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.organization is not None:
self.gguf_writer.add_organization(self.metadata.organization)
if self.metadata.version is not None:
self.gguf_writer.add_version(self.metadata.version)
if self.metadata.base_version is not None:
Expand Down
6 changes: 6 additions & 0 deletions 6 examples/convert_legacy_llama.py
Original file line number Diff line number Diff line change
Expand Up @@ -789,6 +789,8 @@ def add_meta_model(self, params: Params, metadata: gguf.Metadata | None) -> None
self.gguf.add_finetune(metadata.finetune)
if metadata.author is not None:
self.gguf.add_author(metadata.author)
if metadata.organization is not None:
self.add_organization(metadata.organization)
if metadata.version is not None:
self.gguf.add_version(metadata.version)
if metadata.base_version is not None:
Expand All @@ -805,6 +807,10 @@ def add_meta_model(self, params: Params, metadata: gguf.Metadata | None) -> None
self.gguf.add_source_hf_repo(metadata.source_hf_repo)
if metadata.tags is not None:
self.gguf_writer.add_tags(metadata.tags)
if metadata.languages is not None:
self.gguf_writer.add_languages(metadata.languages)
if metadata.datasets is not None:
self.gguf_writer.add_datasets(metadata.datasets)

def add_meta_arch(self, params: Params) -> None:
# Metadata About The Neural Architecture Itself
Expand Down
3 changes: 2 additions & 1 deletion 3 gguf-py/gguf/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ class General:
BASENAME = "general.basename"
FINETUNE = "general.finetune"
AUTHOR = "general.author"
ORGANIZATION = "general.organization"
VERSION = "general.version"
BASE_VERSION = "general.base_version"
URL = "general.url"
Expand All @@ -39,7 +40,7 @@ class General:
FILE_TYPE = "general.file_type"
PARAMETER_SIZE_CLASS = "general.parameter_size_class"
TAGS = "general.tags"
LANGUAGE = "general.language"
LANGUAGES = "general.languages"
DATASETS = "general.datasets"

class LLM:
Expand Down
5 changes: 4 additions & 1 deletion 5 gguf-py/gguf/gguf_writer.py
Original file line number Diff line number Diff line change
Expand Up @@ -439,6 +439,9 @@ def add_finetune(self, finetune: str) -> None:
def add_author(self, author: str) -> None:
self.add_string(Keys.General.AUTHOR, author)

def add_organization(self, organization: str) -> None:
self.add_string(Keys.General.ORGANIZATION, organization)

def add_version(self, version: str) -> None:
self.add_string(Keys.General.VERSION, version)

Expand Down Expand Up @@ -479,7 +482,7 @@ def add_tags(self, tags: Sequence[str]) -> None:
self.add_array(Keys.Tokenizer.TAGS, tags)

def add_languages(self, languages: Sequence[str]) -> None:
self.add_array(Keys.Tokenizer.LANGUAGE, languages)
self.add_array(Keys.Tokenizer.LANGUAGES, languages)

def add_datasets(self, datasets: Sequence[str]) -> None:
self.add_array(Keys.Tokenizer.DATASETS, datasets)
Expand Down
12 changes: 7 additions & 5 deletions 12 gguf-py/gguf/metadata.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ class Metadata:
basename: Optional[str] = None
finetune: Optional[str] = None
author: Optional[str] = None
organization: Optional[str] = None
version: Optional[str] = None
base_version: Optional[str] = None
url: Optional[str] = None
Expand All @@ -26,7 +27,7 @@ class Metadata:
source_hf_repo: Optional[str] = None
mofosyne marked this conversation as resolved.
Show resolved Hide resolved
parameter_size_class: Optional[str] = None
tags: Optional[list[str]] = None
language: Optional[list[str]] = None
languages: Optional[list[str]] = None
datasets: Optional[list[str]] = None

@staticmethod
Expand All @@ -38,7 +39,7 @@ def load(metadata_override_path: Optional[Path], model_path: Optional[Path], mod
# Create a new Metadata instance
metadata = Metadata()

# load model folder model card if available
# load huggingface model card if available
# Reference Model Card Metadata: https://github.com/huggingface/hub-docs/blob/main/modelcard.md?plain=1
model_card = Metadata.load_model_card(model_path)
if metadata.name is None:
Expand All @@ -61,9 +62,9 @@ def load(metadata_override_path: Optional[Path], model_path: Optional[Path], mod
if metadata.tags is None:
metadata.tags = model_card.get("tags", [])
if metadata.languages is None:
metadata.languages = model_card.get("languages", [])
metadata.languages = model_card.get("language", model_card.get("languages", []))
if metadata.datasets is None:
metadata.datasets = model_card.get("datasets", [])
metadata.datasets = model_card.get("datasets", model_card.get("dataset", []))

# load huggingface parameters if available
hf_params = Metadata.load_huggingface_parameters(model_path)
Expand All @@ -85,6 +86,7 @@ def load(metadata_override_path: Optional[Path], model_path: Optional[Path], mod
metadata.basename = metadata_override.get(Keys.General.BASENAME , metadata.basename ) # noqa: E202
metadata.finetune = metadata_override.get(Keys.General.FINETUNE , metadata.finetune ) # noqa: E202
metadata.author = metadata_override.get(Keys.General.AUTHOR , metadata.author ) # noqa: E202
metadata.organization = metadata_override.get(Keys.General.ORGANIZATION , metadata.organization ) # noqa: E202
metadata.version = metadata_override.get(Keys.General.VERSION , metadata.version ) # noqa: E202
metadata.base_version = metadata_override.get(Keys.General.BASE_VERSION , metadata.base_version ) # noqa: E202
metadata.url = metadata_override.get(Keys.General.URL , metadata.url ) # noqa: E202
Expand All @@ -97,7 +99,7 @@ def load(metadata_override_path: Optional[Path], model_path: Optional[Path], mod
metadata.parameter_size_class = metadata_override.get(Keys.General.PARAMETER_SIZE_CLASS, metadata.parameter_size_class) # noqa: E202
metadata.tags = metadata_override.get(Keys.General.TAGS , metadata.tags ) # noqa: E202
metadata.languages = metadata_override.get(Keys.General.LANGUAGES , metadata.languages ) # noqa: E202
metadata.datasets = metadata_override.get(Keys.General.datasets , metadata.datasets ) # noqa: E202
metadata.datasets = metadata_override.get(Keys.General.DATASETS , metadata.datasets ) # noqa: E202

# Direct Metadata Override (via direct cli argument)
if model_name is not None:
Expand Down
Morty Proxy This is a proxified and sanitized view of the page, visit original site.