From 398bedb287ba91b1034549d4a31547c9e5ed1616 Mon Sep 17 00:00:00 2001 From: akawrykow Date: Tue, 22 Aug 2023 17:25:04 -0700 Subject: [PATCH] [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 ef5d4cc9d..ac0f3bb9e 100644 --- a/convert.py +++ b/convert.py @@ -16,6 +16,7 @@ import pickle import re import signal import struct +import subprocess import sys import zipfile import numpy as np @@ -735,7 +736,8 @@ class OutputFile: 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 07a4c2d02..89cbbf93d 100644 --- a/gguf.py +++ b/gguf.py @@ -28,6 +28,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" +KEY_GENERAL_COMMIT_HASH = "general.commit_hash" # LLM KEY_LLM_CONTEXT_LENGTH = "{arch}.context_length" @@ -603,6 +604,9 @@ class GGUFWriter: 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)