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

Commit ad211ed

Browse filesBrowse files
authored
convert.py : --vocab-only generates false but valid params (#7027)
An example of how this might be used in the style of baby-llama will be attached with this PR.
1 parent 229ffff commit ad211ed
Copy full SHA for ad211ed

File tree

Expand file treeCollapse file tree

1 file changed

+32
-19
lines changed
Filter options
Expand file treeCollapse file tree

1 file changed

+32
-19
lines changed

‎convert.py

Copy file name to clipboardExpand all lines: convert.py
+32-19Lines changed: 32 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1508,25 +1508,27 @@ def main(args_in: list[str] | None = None) -> None:
15081508
if args.big_endian:
15091509
endianess = gguf.GGUFEndian.BIG
15101510

1511-
params = Params.load(model_plus)
1512-
if params.n_ctx == -1:
1513-
if args.ctx is None:
1514-
msg = """\
1515-
The model doesn't have a context size, and you didn't specify one with --ctx
1516-
Please specify one with --ctx:
1517-
- LLaMA v1: --ctx 2048
1518-
- LLaMA v2: --ctx 4096"""
1519-
parser.error(textwrap.dedent(msg))
1520-
params.n_ctx = args.ctx
1521-
1522-
if args.outtype:
1523-
params.ftype = {
1524-
"f32": GGMLFileType.AllF32,
1525-
"f16": GGMLFileType.MostlyF16,
1526-
"q8_0": GGMLFileType.MostlyQ8_0,
1527-
}[args.outtype]
1528-
1529-
logger.info(f"params = {params}")
1511+
params = None
1512+
if args.pad_vocab or not args.vocab_only:
1513+
params = Params.load(model_plus)
1514+
if params.n_ctx == -1:
1515+
if args.ctx is None:
1516+
msg = """\
1517+
The model doesn't have a context size, and you didn't specify one with --ctx
1518+
Please specify one with --ctx:
1519+
- LLaMA v1: --ctx 2048
1520+
- LLaMA v2: --ctx 4096"""
1521+
parser.error(textwrap.dedent(msg))
1522+
params.n_ctx = args.ctx
1523+
1524+
if args.outtype:
1525+
params.ftype = {
1526+
"f32": GGMLFileType.AllF32,
1527+
"f16": GGMLFileType.MostlyF16,
1528+
"q8_0": GGMLFileType.MostlyQ8_0,
1529+
}[args.outtype]
1530+
1531+
logger.info(f"params = {params}")
15301532

15311533
model_parent_path = model_plus.paths[0].parent
15321534
vocab_path = Path(args.vocab_dir or args.model or model_parent_path)
@@ -1539,6 +1541,17 @@ def main(args_in: list[str] | None = None) -> None:
15391541
if not args.outfile:
15401542
raise ValueError("need --outfile if using --vocab-only")
15411543
outfile = args.outfile
1544+
if params is None:
1545+
params = Params(
1546+
n_vocab = vocab.vocab_size,
1547+
n_embd = 1,
1548+
n_layer = 1,
1549+
n_ctx = 1,
1550+
n_ff = 1,
1551+
n_head = 1,
1552+
n_head_kv = 1,
1553+
f_norm_eps = 1e-5,
1554+
)
15421555
OutputFile.write_vocab_only(outfile, params, vocab, special_vocab,
15431556
endianess=endianess, pad_vocab=args.pad_vocab)
15441557
logger.info(f"Wrote {outfile}")

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.