Skip to content

Commit 666b5a6

Browse files
committed
Allow specifying name and description for output GGUF
1 parent a43a0d6 commit 666b5a6

File tree

1 file changed

+14
-3
lines changed

1 file changed

+14
-3
lines changed

convert-llama-ggmlv3-to-gguf.py

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import sys, struct, math, argparse
2+
from pathlib import Path
23

34
import numpy as np
45

@@ -163,8 +164,16 @@ def save(self):
163164
def add_params(self, gguf_writer):
164165
hp = self.model.hyperparameters
165166
cfg = self.cfg
167+
desc = cfg.desc if cfg.desc is not None else 'converted from legacy GGJTv3 format'
168+
try:
169+
# Filenames aren't necessarily valid UTF8.
170+
name = cfg.name if cfg.name is not None else cfg.input.name
171+
except UnicodeDecodeError:
172+
name = None
166173
print('* Adding model parameters and KV items')
167-
gguf_writer.add_description('converted from legacy GGJTv3 format')
174+
if name is not None:
175+
gguf_writer.add_name(name)
176+
gguf_writer.add_description(desc)
168177
gguf_writer.add_context_length(cfg.context_length)
169178
gguf_writer.add_embedding_length(hp.n_embd)
170179
gguf_writer.add_block_count(hp.n_layer)
@@ -224,8 +233,10 @@ def add_tensors(self, gguf_writer):
224233

225234
def handle_args():
226235
parser = argparse.ArgumentParser(description = 'Convert GGMLv3 models to GGUF')
227-
parser.add_argument('--input', '-i', help = 'Input GGMLv3 filename')
228-
parser.add_argument('--output', '-o', help ='Output GGUF filename')
236+
parser.add_argument('--input', '-i', type = Path, help = 'Input GGMLv3 filename')
237+
parser.add_argument('--output', '-o', type = Path, help ='Output GGUF filename')
238+
parser.add_argument('--name', help = 'Set model name')
239+
parser.add_argument('--desc', help = 'Set model description')
229240
parser.add_argument('--gqa', type = int, default = 1, help = 'grouped-query attention factor (use 8 for LLaMA2 70B)')
230241
parser.add_argument('--eps', default = '5.0e-06', help = 'RMS norm eps: Use 1e-6 for LLaMA1 and OpenLLaMA, use 1e-5 for LLaMA2')
231242
parser.add_argument('--context-length', '-c', type=int, default = 2048, help = 'Default max context length: LLaMA1 is typically 2048, LLaMA2 is typically 4096')

0 commit comments

Comments
 (0)