Skip to content

Commit ddfaad9

Browse files
committed
convert.py: get default outfile
1 parent 7c6d166 commit ddfaad9

File tree

1 file changed

+18
-2
lines changed

1 file changed

+18
-2
lines changed

convert.py

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1523,7 +1523,7 @@ def load_vocab(self, vocab_types: list[str] | None, model_parent_path: Path) ->
15231523
return vocab, special_vocab
15241524

15251525

1526-
def default_outfile(model_paths: list[Path], file_type: GGMLFileType, params: Params, model_params_count: int, metadata: Metadata) -> Path:
1526+
def default_convention_outfile(file_type: GGMLFileType, params: Params, model_params_count: int, metadata: Metadata) -> str:
15271527
quantization = {
15281528
GGMLFileType.AllF32: "F32",
15291529
GGMLFileType.MostlyF16: "F16",
@@ -1546,7 +1546,12 @@ def default_outfile(model_paths: list[Path], file_type: GGMLFileType, params: Pa
15461546
elif params.path_model is not None:
15471547
name = params.path_model.name
15481548

1549-
ret = model_paths[0].parent / f"{name}{version}-{expert_count}{parameters}-{quantization}.gguf"
1549+
return f"{name}{version}-{expert_count}{parameters}-{quantization}"
1550+
1551+
1552+
def default_outfile(model_paths: list[Path], file_type: GGMLFileType, params: Params, model_params_count: int, metadata: Metadata) -> Path:
1553+
default_filename = default_convention_outfile(file_type, params, model_params_count, metadata)
1554+
ret = model_paths[0].parent / f"{default_filename}.gguf"
15501555
if ret in model_paths:
15511556
logger.error(
15521557
f"Error: Default output path ({ret}) would overwrite the input. "
@@ -1585,6 +1590,7 @@ def main(args_in: list[str] | None = None) -> None:
15851590
parser.add_argument("--skip-unknown", action="store_true", help="skip unknown tensor names instead of failing")
15861591
parser.add_argument("--verbose", action="store_true", help="increase output verbosity")
15871592
parser.add_argument("--metadata", type=Path, help="Specify the path for a metadata file")
1593+
parser.add_argument("--get-outfile", action="store_true", help="get calculated default outfile name")
15881594

15891595
args = parser.parse_args(args_in)
15901596

@@ -1598,6 +1604,16 @@ def main(args_in: list[str] | None = None) -> None:
15981604

15991605
metadata = Metadata.load(args.metadata)
16001606

1607+
if args.get_outfile:
1608+
logging.basicConfig(level=logging.CRITICAL)
1609+
model_plus = load_some_model(args.model)
1610+
params = Params.load(model_plus)
1611+
model = convert_model_names(model_plus.model, params, args.skip_unknown)
1612+
model_params_count = model_parameter_count(model_plus.model)
1613+
ftype = pick_output_type(model, args.outtype)
1614+
print(f"{default_convention_outfile(ftype, params, model_params_count, metadata)}") # noqa: NP100
1615+
return
1616+
16011617
if args.no_vocab and args.vocab_only:
16021618
raise ValueError("--vocab-only does not make sense with --no-vocab")
16031619

0 commit comments

Comments
 (0)