From 684686eadbe101394ee294f2db5d679d6812f23e Mon Sep 17 00:00:00 2001 From: akawrykow Date: Tue, 22 Aug 2023 17:25:04 -0700 Subject: [PATCH 1/4] [gguf] Add date --- convert.py | 2 ++ gguf.py | 4 ++++ 2 files changed, 6 insertions(+) diff --git a/convert.py b/convert.py index e720889fd515a..ef5d4cc9d90f3 100644 --- a/convert.py +++ b/convert.py @@ -22,6 +22,7 @@ from abc import ABCMeta, abstractmethod from dataclasses import dataclass +from datetime import datetime from pathlib import Path from typing import (IO, TYPE_CHECKING, Any, Callable, Dict, Iterable, List, Literal, Optional, Sequence, Tuple, TypeVar, Union) from sentencepiece import SentencePieceProcessor # type: ignore @@ -734,6 +735,7 @@ def __init__(self, fname_out: Path) -> None: def add_meta_arch(self, params: Params) -> None: self.gguf.add_name ("LLaMA") + self.gguf.add_date(datetime.today().isoformat()) self.gguf.add_context_length (params.n_ctx) self.gguf.add_embedding_length (params.n_embd) self.gguf.add_block_count (params.n_layer) diff --git a/gguf.py b/gguf.py index 4657467182328..07a4c2d025ebd 100644 --- a/gguf.py +++ b/gguf.py @@ -27,6 +27,7 @@ KEY_GENERAL_SOURCE_URL = "general.source.url" KEY_GENERAL_SOURCE_HF_REPO = "general.source.hugginface.repository" KEY_GENERAL_FILE_TYPE = "general.file_type" +KEY_GENERAL_DATE = "general.date" # LLM KEY_LLM_CONTEXT_LENGTH = "{arch}.context_length" @@ -599,6 +600,9 @@ def add_source_hf_repo(self, repo: str): def add_file_type(self, ftype: int): self.add_uint32(KEY_GENERAL_FILE_TYPE, ftype) + def add_date(self, date: str): + self.add_string(KEY_GENERAL_DATE, date) + def add_name(self, name: str): self.add_string(KEY_GENERAL_NAME, name) From 398bedb287ba91b1034549d4a31547c9e5ed1616 Mon Sep 17 00:00:00 2001 From: akawrykow Date: Tue, 22 Aug 2023 17:25:04 -0700 Subject: [PATCH 2/4] [gguf] Add git commit hash --- convert.py | 7 ++++++- gguf.py | 4 ++++ 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/convert.py b/convert.py index ef5d4cc9d90f3..ac0f3bb9e627e 100644 --- a/convert.py +++ b/convert.py @@ -16,6 +16,7 @@ import re import signal import struct +import subprocess import sys import zipfile import numpy as np @@ -735,7 +736,8 @@ def __init__(self, fname_out: Path) -> None: def add_meta_arch(self, params: Params) -> None: self.gguf.add_name ("LLaMA") - self.gguf.add_date(datetime.today().isoformat()) + self.gguf.add_date (datetime.today().isoformat()) + self.gguf.add_commit_hash (get_git_revision_short_hash()) self.gguf.add_context_length (params.n_ctx) self.gguf.add_embedding_length (params.n_embd) self.gguf.add_block_count (params.n_layer) @@ -1002,6 +1004,9 @@ def do_dump_model(model_plus: ModelPlus) -> None: print(f"{name}: shape={lazy_tensor.shape} type={lazy_tensor.data_type}; {lazy_tensor.description}") +def get_git_revision_short_hash() -> str: + return subprocess.check_output(['git', 'rev-parse', '--short', 'HEAD']).decode('ascii').strip() + def main(args_in: Optional[List[str]] = None) -> None: parser = argparse.ArgumentParser(description="Convert a LLaMa model to a GGML compatible file") parser.add_argument("--dump", action="store_true", help="don't convert, just show what's in the model") diff --git a/gguf.py b/gguf.py index 07a4c2d025ebd..89cbbf93d43bb 100644 --- a/gguf.py +++ b/gguf.py @@ -28,6 +28,7 @@ KEY_GENERAL_SOURCE_HF_REPO = "general.source.hugginface.repository" KEY_GENERAL_FILE_TYPE = "general.file_type" KEY_GENERAL_DATE = "general.date" +KEY_GENERAL_COMMIT_HASH = "general.commit_hash" # LLM KEY_LLM_CONTEXT_LENGTH = "{arch}.context_length" @@ -603,6 +604,9 @@ def add_file_type(self, ftype: int): def add_date(self, date: str): self.add_string(KEY_GENERAL_DATE, date) + def add_commit_hash(self, commit_hash: str): + self.add_string(KEY_GENERAL_COMMIT_HASH, commit_hash) + def add_name(self, name: str): self.add_string(KEY_GENERAL_NAME, name) From 39a2c89a305453bd3623db70e8693da21ee83f85 Mon Sep 17 00:00:00 2001 From: akawrykow Date: Tue, 22 Aug 2023 17:25:04 -0700 Subject: [PATCH 3/4] [gguf] Print the date --- llama.cpp | 3 +++ 1 file changed, 3 insertions(+) diff --git a/llama.cpp b/llama.cpp index 6c5da130926fc..d2a4676ec7caa 100644 --- a/llama.cpp +++ b/llama.cpp @@ -1279,6 +1279,7 @@ static void llama_model_load_internal( std::string general_name = "n/a"; std::string general_arch = "n/a"; + std::string general_date = "n/a"; // read hparams { @@ -1336,6 +1337,7 @@ static void llama_model_load_internal( // get general kv GGUF_GET(general_name, gguf_get_val_str, GGUF_TYPE_STRING, false, "general.name"); GGUF_GET(general_arch, gguf_get_val_str, GGUF_TYPE_STRING, false, "general.architecture"); + GGUF_GET(general_date, gguf_get_val_str, GGUF_TYPE_STRING, false, "general.date"); // special tokens GGUF_GET(vocab.special_bos_id, gguf_get_val_u32, GGUF_TYPE_UINT32, false, "tokenizer.ggml.bos_token_id"); @@ -1445,6 +1447,7 @@ static void llama_model_load_internal( // general kv LLAMA_LOG_INFO("%s: general.name = %s\n", __func__, general_name.c_str()); + LLAMA_LOG_INFO("%s: general.date = %s\n", __func__, general_date.c_str()); // special tokens if (vocab.special_bos_id != -1) { LLAMA_LOG_INFO( "%s: BOS token = %d '%s'\n", __func__, vocab.special_bos_id, vocab.id_to_token[vocab.special_bos_id].text.c_str() ); } From 6803aac321e278ae2e86fe91fcf9c784d4778ac1 Mon Sep 17 00:00:00 2001 From: akawrykow Date: Tue, 22 Aug 2023 17:25:04 -0700 Subject: [PATCH 4/4] [gguf] Print the commit hash --- llama.cpp | 3 +++ 1 file changed, 3 insertions(+) diff --git a/llama.cpp b/llama.cpp index d2a4676ec7caa..a18795f859672 100644 --- a/llama.cpp +++ b/llama.cpp @@ -1280,6 +1280,7 @@ static void llama_model_load_internal( std::string general_name = "n/a"; std::string general_arch = "n/a"; std::string general_date = "n/a"; + std::string general_commit_hash = "n/a"; // read hparams { @@ -1338,6 +1339,7 @@ static void llama_model_load_internal( GGUF_GET(general_name, gguf_get_val_str, GGUF_TYPE_STRING, false, "general.name"); GGUF_GET(general_arch, gguf_get_val_str, GGUF_TYPE_STRING, false, "general.architecture"); GGUF_GET(general_date, gguf_get_val_str, GGUF_TYPE_STRING, false, "general.date"); + GGUF_GET(general_commit_hash, gguf_get_val_str, GGUF_TYPE_STRING, false, "general.commit_hash"); // special tokens GGUF_GET(vocab.special_bos_id, gguf_get_val_u32, GGUF_TYPE_UINT32, false, "tokenizer.ggml.bos_token_id"); @@ -1448,6 +1450,7 @@ static void llama_model_load_internal( // general kv LLAMA_LOG_INFO("%s: general.name = %s\n", __func__, general_name.c_str()); LLAMA_LOG_INFO("%s: general.date = %s\n", __func__, general_date.c_str()); + LLAMA_LOG_INFO("%s: general.commit_hash = %s\n", __func__, general_commit_hash.c_str()); // special tokens if (vocab.special_bos_id != -1) { LLAMA_LOG_INFO( "%s: BOS token = %d '%s'\n", __func__, vocab.special_bos_id, vocab.id_to_token[vocab.special_bos_id].text.c_str() ); }