mirror of
https://github.com/ggml-org/llama.cpp.git
synced 2026-11-26 23:29:34 +00:00
Some checks failed
Behavior Check / ubuntu (push) Waiting to run
Behavior Check / windows (push) Waiting to run
CI (3rd-party) / ubuntu-26-llguidance (push) Waiting to run
CI (android) / default (push) Waiting to run
CI (android) / ndk (push) Waiting to run
CI (android) / arm64 (push) Waiting to run
CI (apple) / macos-latest-arm64 (push) Waiting to run
CI (cpu) / ubuntu (arm64, ubuntu-26.04-arm) (push) Waiting to run
CI (cpu) / ubuntu (x64, ubuntu-26.04) (push) Waiting to run
CI (cpu) / windows / arm64 (push) Waiting to run
CI (cpu) / windows / x64-cpu-static (push) Waiting to run
CI (cpu) / windows / x64-openblas (push) Waiting to run
CI (cpu) / build-cmake-pkg (push) Waiting to run
CI (CUDA, ubuntu) / cuda (push) Waiting to run
CI (CUDA, ubuntu) / hip (push) Waiting to run
CI (CUDA, ubuntu) / musa (push) Waiting to run
CI (ibm) / ubuntu-26-s390x (VXE OFF) (push) Waiting to run
CI (ibm) / ubuntu-26-s390x (VXE ON) (push) Waiting to run
CI (ibm) / ubuntu-26-zdnn-s390x (push) Waiting to run
CI (ibm) / ubuntu-26-ppc64le (push) Waiting to run
CI (opencl) / windows-2025-opencl-adreno (push) Waiting to run
CI (openvino) / openvino-windows-2022 (push) Waiting to run
CI (riscv) / ubuntu-cpu-riscv64-native (push) Waiting to run
CI (sanitize) / ctest (ubuntu-26.04, ADDRESS) (push) Waiting to run
CI (sanitize) / ctest (ubuntu-26.04, THREAD) (push) Waiting to run
CI (sanitize) / ctest (ubuntu-26.04, UNDEFINED) (push) Waiting to run
CI (sycl) / ubuntu-26-sycl (fp16, ON) (push) Waiting to run
CI (sycl) / ubuntu-26-sycl (fp32, OFF) (push) Waiting to run
CI (sycl) / windows-latest-sycl (push) Waiting to run
CI (virtgpu) / ubuntu-26-virtgpu (push) Waiting to run
CI (vulkan) / ubuntu (push) Waiting to run
CI (vulkan) / ubuntu-llvmpipe (push) Waiting to run
CI (vulkan) / windows / arm64 (push) Waiting to run
CI (vulkan) / windows / x64 (push) Waiting to run
CI (wasi) / ubuntu-webgpu (push) Waiting to run
CI (wasm) / ubuntu-webgpu (push) Waiting to run
CI (self-hosted CPU backend) / cpu-x64-high-perf (push) Waiting to run
CI (self-hosted CPU backend) / cpu-arm64-high-perf-graviton4 (push) Waiting to run
CI (self-hosted CUDA backend) / gpu-cuda (push) Waiting to run
CI (self-hosted CUDA backend) / gpu-rocm (gfx1151) (push) Waiting to run
CI (self-hosted CUDA backend) / gpu-rocm (gfx1201) (push) Waiting to run
CI (self-hosted KleidiAI backend) / cpu-arm64-graviton4-kleidiai (push) Waiting to run
CI (self-hosted Metal backend) / gpu-metal (push) Waiting to run
CI (self-hosted OpenVINO backend) / gpu-openvino-low-perf (push) Waiting to run
CI (self-hosted Vulkan backend) / gpu-vulkan-nvidia-cm (push) Waiting to run
CI (self-hosted Vulkan backend) / gpu-vulkan-nvidia-cm2 (push) Waiting to run
CI (self-hosted Vulkan backend) / gpu-vulkan-apple (push) Waiting to run
CI (self-hosted Vulkan backend) / gpu-vulkan-intel-linux (push) Waiting to run
CI (self-hosted Vulkan backend) / gpu-vulkan-intel-windows (push) Waiting to run
CI (self-hosted WebGPU backend) / gpu-webgpu-nvidia (push) Waiting to run
CI (self-hosted WebGPU backend) / gpu-webgpu-apple (push) Waiting to run
Code Style Checker / model-naming (push) Waiting to run
EditorConfig Checker / editorconfig (push) Waiting to run
HIP quality check / ubuntu-22-hip-quality-check (push) Waiting to run
Models Backend Check / metal (push) Waiting to run
Models Backend Check / cuda (push) Waiting to run
Models Backend Check / rocm (push) Waiting to run
Models Backend Check / vulkan-nvidia (push) Waiting to run
Models Backend Check / vulkan-amd (push) Waiting to run
Models Backend Check / webgpu-nvidia (push) Waiting to run
Python check requirements.txt / check-requirements (push) Waiting to run
flake8 Lint / Lint (push) Waiting to run
Python Type-Check / python type-check (push) Waiting to run
Release / macos-cpu (arm64, arm64, -DGGML_METAL_EMBED_LIBRARY=ON -DCMAKE_OSX_DEPLOYMENT_TARGET=13.3, macos-26) (push) Blocked by required conditions
Release / check-release (push) Waiting to run
Release / macos-cpu (x64, x64, -DGGML_METAL=OFF -DCMAKE_OSX_DEPLOYMENT_TARGET=13.3, macos-15-intel) (push) Blocked by required conditions
Release / ubuntu-cpu (26.04-s390x, ubuntu-26.04-s390x) (push) Blocked by required conditions
Release / ubuntu-cpu (arm64, ubuntu-24.04-arm) (push) Blocked by required conditions
Release / ubuntu-cpu (s390x, ubuntu-24.04-s390x) (push) Blocked by required conditions
Release / ubuntu-cpu (x64, ubuntu-22.04) (push) Blocked by required conditions
Release / ubuntu-vulkan (arm64, ubuntu-24.04-arm) (push) Blocked by required conditions
Release / ubuntu-vulkan (x64, ubuntu-22.04) (push) Blocked by required conditions
Release / ubuntu-cuda (13.5, arm64) (push) Blocked by required conditions
Release / ubuntu-cuda (12.8, x64) (push) Blocked by required conditions
Release / ubuntu-cuda (13.5, x64) (push) Blocked by required conditions
Release / android-arm64 (push) Blocked by required conditions
Release / android-arm64-snapdragon (push) Blocked by required conditions
Release / linux-arm64-snapdragon (push) Blocked by required conditions
Release / ubuntu-24-openvino (push) Blocked by required conditions
Release / windows-openvino (push) Blocked by required conditions
Release / windows-cpu / arm64 (push) Blocked by required conditions
Release / windows-cpu / x64 (push) Blocked by required conditions
Release / windows-rocm (10.0.0, x64, gfx1010;gfx1011;gfx1012;gfx1030;gfx1031;gfx1032;gfx1033;gfx1034;gfx1035;gfx1036;gfx1100;gfx1101;gfx1102;gfx1103;gfx1150;gfx1151;gfx1152;gfx1153;gfx1200;gfx1201) (push) Blocked by required conditions
Release / windows (arm64, opencl-adreno, -G "Ninja Multi-Config" -D CMAKE_TOOLCHAIN_FILE=cmake/arm64-windows-llvm.cmake -DCMAKE_PREFIX_PATH="$env:RUNNER_TEMP/opencl-arm64-release" -DGGML_OPENCL=ON -DGGML_OPENCL_USE_ADRENO_KERNELS=ON -DGGML_OPENCL_ADRENO_BIN_KERN… (push) Blocked by required conditions
Release / windows (arm64, vulkan, -G "Ninja Multi-Config" -DGGML_VULKAN=ON -D CMAKE_TOOLCHAIN_FILE=cmake/arm64-windows-llvm.cmake, ggml-vulkan) (push) Blocked by required conditions
Release / windows (x64, vulkan, -DGGML_VULKAN=ON, ggml-vulkan) (push) Blocked by required conditions
Release / windows-cuda (13.5, arm64) (push) Blocked by required conditions
Release / windows-cuda (12.4, x64) (push) Blocked by required conditions
Release / windows-cuda (13.5, x64) (push) Blocked by required conditions
Release / windows-sycl (push) Blocked by required conditions
Release / ubuntu-24-sycl (fp16, ON) (push) Blocked by required conditions
Release / ubuntu-24-sycl (fp32, OFF) (push) Blocked by required conditions
Release / ubuntu-24-rocm (10.0.0, x64, gfx908;gfx90a;gfx942;gfx950;gfx1010;gfx1011;gfx1012;gfx1030;gfx1031;gfx1032;gfx1033;gfx1034;gfx1035;gfx1036;gfx1100;gfx1101;gfx1102;gfx1103;gfx1150;gfx1151;gfx1152;gfx1200;gfx1201) (push) Blocked by required conditions
Release / ubuntu-26-zdnn (push) Blocked by required conditions
Release / ios-xcode (push) Blocked by required conditions
Release / ui-build (push) Blocked by required conditions
Server (sanitize) / server (RelWithDebInfo, ADDRESS) (push) Waiting to run
Server (sanitize) / server (RelWithDebInfo, UNDEFINED) (push) Waiting to run
Server (self-hosted) / server-kleidiai (push) Waiting to run
Server (self-hosted) / server-metal (push) Waiting to run
Server (self-hosted) / server-cuda (push) Waiting to run
Server / ubuntu (push) Waiting to run
Server / windows (push) Waiting to run
UI (self-hosted) / Build static output (push) Waiting to run
UI (self-hosted) / Checks (push) Blocked by required conditions
UI (self-hosted) / E2E Tests (push) Blocked by required conditions
UI Storybook / Deploy to Hugging Face Spaces (push) Waiting to run
UI / Build static output (push) Waiting to run
UI / Chat-only build (push) Waiting to run
UI / Checks (push) Blocked by required conditions
UI / Library checks (push) Waiting to run
UI / Voice checks (push) Waiting to run
UI / Harness checks (push) Waiting to run
UI / E2E Tests (push) Blocked by required conditions
Server (speculative decoding) / server-speculative (push) Has been cancelled
* conversion * init cpp side * handle temp > 0 * dspark : fix Inkling2 draft state width, reseeding and draw order * spec: align Inkling2 DSpark with n_max draft tokens same as the other DSparks * unify rnn condition with markov_head_type * formatting issues and restructure some DSpark functions --------- Co-authored-by: Xuan Son Nguyen <son@huggingface.co> Co-authored-by: ruixiang63 <wangruixiang07@outlook.com>
342 lines
15 KiB
Python
Executable file
342 lines
15 KiB
Python
Executable file
#!/usr/bin/env python3
|
|
# -*- coding: utf-8 -*-
|
|
|
|
from __future__ import annotations
|
|
|
|
import argparse
|
|
import logging
|
|
import os
|
|
import sys
|
|
from pathlib import Path
|
|
|
|
import torch
|
|
|
|
if 'NO_LOCAL_GGUF' not in os.environ:
|
|
sys.path.insert(1, str(Path(__file__).parent / 'gguf-py'))
|
|
import gguf
|
|
|
|
from conversion import (
|
|
ModelBase,
|
|
ModelType,
|
|
get_model_architecture,
|
|
get_model_class,
|
|
logger,
|
|
print_registered_models,
|
|
_mistral_common_installed,
|
|
_mistral_import_error_msg,
|
|
)
|
|
|
|
|
|
def split_str_to_n_bytes(split_str: str) -> int:
|
|
if split_str.endswith("K"):
|
|
n = int(split_str[:-1]) * 1000
|
|
elif split_str.endswith("M"):
|
|
n = int(split_str[:-1]) * 1000 * 1000
|
|
elif split_str.endswith("G"):
|
|
n = int(split_str[:-1]) * 1000 * 1000 * 1000
|
|
elif split_str.isnumeric():
|
|
n = int(split_str)
|
|
else:
|
|
raise ValueError(f"Invalid split size: {split_str}, must be a number, optionally followed by K, M, or G")
|
|
|
|
if n < 0:
|
|
raise ValueError(f"Invalid split size: {split_str}, must be positive")
|
|
|
|
return n
|
|
|
|
|
|
def parse_args() -> argparse.Namespace:
|
|
parser = argparse.ArgumentParser(
|
|
description="Convert a huggingface model to a GGML compatible file")
|
|
parser.add_argument(
|
|
"--vocab-only", action="store_true",
|
|
help="extract only the vocab",
|
|
)
|
|
parser.add_argument(
|
|
"--outfile", type=Path,
|
|
help="path to write to; default: based on input. {ftype} will be replaced by the outtype.",
|
|
)
|
|
parser.add_argument(
|
|
"--outtype", type=str, choices=["f32", "f16", "bf16", "q8_0", "tq1_0", "tq2_0", "auto"], default="auto",
|
|
help="output format - use f32 for float32, f16 for float16, bf16 for bfloat16, q8_0 for Q8_0, tq1_0 or tq2_0 for ternary, and auto to preserve supported FP8 weights and otherwise select the highest-fidelity 16-bit float type",
|
|
)
|
|
parser.add_argument(
|
|
"--bigendian", action="store_true",
|
|
help="model is executed on big endian machine",
|
|
)
|
|
parser.add_argument(
|
|
"model", type=str,
|
|
help="directory containing model file or huggingface repository ID (if --remote)",
|
|
nargs="?",
|
|
)
|
|
parser.add_argument(
|
|
"--use-temp-file", action="store_true",
|
|
help="use the tempfile library while processing (helpful when running out of memory, process killed)",
|
|
)
|
|
parser.add_argument(
|
|
"--no-lazy", action="store_true",
|
|
help="use more RAM by computing all outputs before writing (use in case lazy evaluation is broken)",
|
|
)
|
|
parser.add_argument(
|
|
"--model-name", type=str, default=None,
|
|
help="name of the model",
|
|
)
|
|
parser.add_argument(
|
|
"--verbose", action="store_true",
|
|
help="increase output verbosity",
|
|
)
|
|
parser.add_argument(
|
|
"--split-max-tensors", type=int, default=0,
|
|
help="max tensors in each split",
|
|
)
|
|
parser.add_argument(
|
|
"--split-max-size", type=str, default="0",
|
|
help="max size per split N(M|G)",
|
|
)
|
|
parser.add_argument(
|
|
"--dry-run", action="store_true",
|
|
help="only print out a split plan and exit, without writing any new files",
|
|
)
|
|
parser.add_argument(
|
|
"--no-tensor-first-split", action="store_true",
|
|
help="do not add tensors to the first split (disabled by default)"
|
|
)
|
|
parser.add_argument(
|
|
"--metadata", type=Path,
|
|
help="Specify the path for an authorship metadata override file"
|
|
)
|
|
parser.add_argument(
|
|
"--print-supported-models", action="store_true",
|
|
help="Print the supported models"
|
|
)
|
|
parser.add_argument(
|
|
"--remote", action="store_true",
|
|
help="(Experimental) Read safetensors file remotely without downloading to disk. Config and tokenizer files will still be downloaded. To use this feature, you need to specify Hugging Face model repo name instead of a local directory. For example: 'HuggingFaceTB/SmolLM2-1.7B-Instruct'. Note: To access gated repo, set HF_TOKEN environment variable to your Hugging Face token.",
|
|
)
|
|
parser.add_argument(
|
|
"--mmproj", action="store_true",
|
|
help="Export multimodal projector (mmproj) for vision models. This will only work on some vision models. An 'mmproj-' prefix will be added to the output file name.",
|
|
)
|
|
parser.add_argument(
|
|
"--mtp", action="store_true",
|
|
help="Export only the multi-token prediction (MTP) head as a separate GGUF, suitable for use as a speculative draft. An 'mtp-' prefix will be added to the output file name.",
|
|
)
|
|
parser.add_argument(
|
|
"--no-nextn", "--no-mtp", dest="no_mtp", action="store_true",
|
|
help="Exclude NextN speculative draft tensors from the converted GGUF. Pair with --mtp or --dspark on a second run to publish target and draft as two files.",
|
|
)
|
|
ple_group = parser.add_mutually_exclusive_group()
|
|
ple_group.add_argument(
|
|
"--ple-only", action="store_true",
|
|
help="Export only the per-layer embedding table as a separate GGUF for use with --shard (alias: --ple).",
|
|
)
|
|
ple_group.add_argument(
|
|
"--no-ple", action="store_true",
|
|
help="Exclude the per-layer embedding table while retaining its metadata. Load the table separately with --shard (alias: --ple).",
|
|
)
|
|
parser.add_argument(
|
|
"--dspark", action="store_true",
|
|
help="Export only the DeepSeek-V4, Mistral Large 4 or Inkling 2 DSpark draft tensors as a separate GGUF.",
|
|
)
|
|
parser.add_argument(
|
|
"--mistral-format", action="store_true",
|
|
help="Whether the model is stored following the Mistral format.",
|
|
)
|
|
parser.add_argument(
|
|
"--disable-mistral-community-chat-template", action="store_true",
|
|
help=(
|
|
"Whether to disable usage of Mistral community chat templates. If set, use the Mistral official `mistral-common` library for tokenization and detokenization of Mistral models. "
|
|
"Using `mistral-common` ensure correctness and zero-day support of tokenization for models converted from the Mistral format but requires to manually setup the tokenization server."
|
|
)
|
|
)
|
|
|
|
parser.add_argument(
|
|
"--sentence-transformers-dense-modules", action="store_true",
|
|
help=("Whether to include sentence-transformers dense modules. "
|
|
"It can be used for sentence-transformers models, like google/embeddinggemma-300m. "
|
|
"Default these modules are not included.")
|
|
)
|
|
|
|
parser.add_argument(
|
|
"--fuse-gate-up-exps", action="store_true",
|
|
help="Fuse gate_exps and up_exps tensors into a single gate_up_exps tensor for MoE models.",
|
|
)
|
|
parser.add_argument(
|
|
"--fp8-as-q8", action="store_true",
|
|
help="Store tensors dequantized from FP8 as Q8_0 instead of BF16/F16.",
|
|
)
|
|
|
|
parser.add_argument(
|
|
"--fuse-qkv", action="store_true",
|
|
help="Fuse separate Q, K, V weight tensors into a single QKV tensor.",
|
|
)
|
|
parser.add_argument(
|
|
"--target-model-dir", type=str, default=None,
|
|
help=(
|
|
"path to the target model directory; required when converting a standalone draft model "
|
|
"(e.g. EAGLE3 / DFlash) that needs target-model metadata such as tokenizer, hidden size, and "
|
|
"layer count to populate its GGUF."
|
|
),
|
|
)
|
|
|
|
args = parser.parse_args()
|
|
if not args.print_supported_models and args.model is None:
|
|
parser.error("the following arguments are required: model")
|
|
if (args.ple_only or args.no_ple) and (args.vocab_only or args.mmproj or args.mtp or args.dspark):
|
|
parser.error("--ple-only / --no-ple cannot be combined with --vocab-only, --mmproj, --mtp, or --dspark")
|
|
if args.ple_only and args.no_tensor_first_split:
|
|
parser.error("--ple-only cannot be combined with --no-tensor-first-split")
|
|
return args
|
|
|
|
|
|
def main() -> None:
|
|
args = parse_args()
|
|
|
|
if args.print_supported_models:
|
|
logger.error("Supported models:")
|
|
print_registered_models()
|
|
sys.exit(0)
|
|
|
|
if args.verbose:
|
|
logging.basicConfig(level=logging.DEBUG)
|
|
else:
|
|
logging.basicConfig(level=logging.INFO)
|
|
|
|
if args.remote:
|
|
hf_repo_id = args.model
|
|
from huggingface_hub import snapshot_download
|
|
allowed_patterns = ["LICENSE", "*.json", "*.md", "*.txt", "tokenizer.model"]
|
|
if args.sentence_transformers_dense_modules:
|
|
# include sentence-transformers dense modules safetensors files
|
|
allowed_patterns.append("*.safetensors")
|
|
local_dir = snapshot_download(
|
|
repo_id=hf_repo_id,
|
|
allow_patterns=allowed_patterns)
|
|
dir_model = Path(local_dir)
|
|
logger.info(f"Downloaded config and tokenizer to {local_dir}")
|
|
else:
|
|
hf_repo_id = None
|
|
dir_model = Path(args.model)
|
|
|
|
if not dir_model.is_dir():
|
|
logger.error(f'Error: {dir_model} is not a directory')
|
|
sys.exit(1)
|
|
|
|
ftype_map: dict[str, gguf.LlamaFileType] = {
|
|
"f32": gguf.LlamaFileType.ALL_F32,
|
|
"f16": gguf.LlamaFileType.MOSTLY_F16,
|
|
"bf16": gguf.LlamaFileType.MOSTLY_BF16,
|
|
"q8_0": gguf.LlamaFileType.MOSTLY_Q8_0,
|
|
"tq1_0": gguf.LlamaFileType.MOSTLY_TQ1_0,
|
|
"tq2_0": gguf.LlamaFileType.MOSTLY_TQ2_0,
|
|
"auto": gguf.LlamaFileType.GUESSED,
|
|
}
|
|
|
|
is_split = args.split_max_tensors > 0 or args.split_max_size != "0"
|
|
if args.use_temp_file and is_split:
|
|
logger.error("Error: Cannot use temp file when splitting")
|
|
sys.exit(1)
|
|
|
|
if args.outfile is not None:
|
|
fname_out = args.outfile
|
|
elif hf_repo_id:
|
|
# if remote, use the model ID as the output file name
|
|
fname_out = Path("./" + hf_repo_id.replace("/", "-") + "-{ftype}.gguf")
|
|
else:
|
|
fname_out = dir_model
|
|
|
|
logger.info(f"Loading model: {dir_model.name}")
|
|
|
|
is_mistral_format = args.mistral_format
|
|
if is_mistral_format and not _mistral_common_installed:
|
|
raise ImportError(_mistral_import_error_msg)
|
|
disable_mistral_community_chat_template = args.disable_mistral_community_chat_template
|
|
|
|
with torch.inference_mode():
|
|
output_type = ftype_map[args.outtype]
|
|
model_type = ModelType.MMPROJ if args.mmproj else ModelType.TEXT
|
|
hparams = ModelBase.load_hparams(dir_model, is_mistral_format)
|
|
if not is_mistral_format:
|
|
model_architecture = get_model_architecture(hparams, model_type)
|
|
logger.info(f"Model architecture: {model_architecture}")
|
|
try:
|
|
model_class = get_model_class(model_architecture, mmproj=(model_type == ModelType.MMPROJ))
|
|
except NotImplementedError:
|
|
logger.error(f"Model {model_architecture} is not supported")
|
|
sys.exit(1)
|
|
elif args.mmproj:
|
|
assert hparams.get("vision_encoder") is not None, "This model does not support multimodal"
|
|
from conversion.pixtral import PixtralModel
|
|
model_class = PixtralModel
|
|
elif hparams.get("moe") is not None and hparams.get("dsa") is not None:
|
|
from conversion.mistral4 import MistralLarge4Model
|
|
model_class = MistralLarge4Model
|
|
elif hparams.get("moe") is not None:
|
|
from conversion.mistral import MistralMoeModel
|
|
model_class = MistralMoeModel
|
|
else:
|
|
from conversion.mistral import MistralModel
|
|
model_class = MistralModel
|
|
|
|
if sum((args.mtp, args.no_mtp, args.dspark)) > 1:
|
|
logger.error("--mtp, --no-nextn, and --dspark are mutually exclusive")
|
|
sys.exit(1)
|
|
|
|
if args.dspark:
|
|
if is_mistral_format or model_architecture == "MistralLarge4ForConditionalGeneration":
|
|
if model_class.__name__ != "MistralLarge4Model":
|
|
logger.error("--dspark is only supported for Mistral Large 4 among Mistral-format models")
|
|
sys.exit(1)
|
|
from conversion.mistral4 import MistralLarge4DSparkModel
|
|
model_class = MistralLarge4DSparkModel
|
|
elif model_architecture in ("Inkling2ForConditionalGeneration", "Inkling2ForCausalLM", "Inkling2LoopForConditionalGeneration", "Inkling2LoopForCausalLM"):
|
|
from conversion.inkling2 import Inkling2DSparkModel
|
|
model_class = Inkling2DSparkModel
|
|
elif model_architecture not in ("DeepseekV4ForCausalLM", "DeepseekV41ForCausalLM"):
|
|
logger.error("--dspark is only supported for DeepseekV4ForCausalLM, DeepseekV41ForCausalLM, Mistral Large 4 and Inkling 2")
|
|
sys.exit(1)
|
|
elif model_architecture == "DeepseekV41ForCausalLM":
|
|
from conversion.deepseek41 import DeepseekV41DSparkModel
|
|
model_class = DeepseekV41DSparkModel
|
|
else:
|
|
from conversion.deepseek import DeepseekV4DSparkModel
|
|
model_class = DeepseekV4DSparkModel
|
|
|
|
if args.mtp or args.no_mtp:
|
|
if not model_class.supports_mtp_export:
|
|
logger.error("--mtp / --no-nextn are not supported for %s", model_architecture)
|
|
sys.exit(1)
|
|
if args.no_mtp:
|
|
model_class.no_mtp = True
|
|
if args.mtp:
|
|
model_class.mtp_only = True
|
|
|
|
model_instance = model_class(dir_model, output_type, fname_out,
|
|
is_big_endian=args.bigendian, use_temp_file=args.use_temp_file,
|
|
eager=args.no_lazy,
|
|
metadata_override=args.metadata, model_name=args.model_name,
|
|
split_max_tensors=args.split_max_tensors,
|
|
split_max_size=split_str_to_n_bytes(args.split_max_size), dry_run=args.dry_run,
|
|
small_first_shard=args.no_tensor_first_split,
|
|
remote_hf_model_id=hf_repo_id, disable_mistral_community_chat_template=disable_mistral_community_chat_template,
|
|
sentence_transformers_dense_modules=args.sentence_transformers_dense_modules,
|
|
target_model_dir=Path(args.target_model_dir) if args.target_model_dir else None,
|
|
fuse_gate_up_exps=args.fuse_gate_up_exps,
|
|
fp8_as_q8=args.fp8_as_q8,
|
|
fuse_qkv=args.fuse_qkv,
|
|
ple_only=args.ple_only, no_ple=args.no_ple,
|
|
)
|
|
|
|
if args.vocab_only:
|
|
logger.info("Exporting model vocab...")
|
|
model_instance.write_vocab()
|
|
logger.info(f"Model vocab successfully exported to {model_instance.fname_out}")
|
|
else:
|
|
logger.info("Exporting model...")
|
|
model_instance.write()
|
|
out_path = f"{model_instance.fname_out.parent}{os.sep}" if is_split else model_instance.fname_out
|
|
logger.info(f"Model successfully exported to {out_path}")
|
|
|
|
|
|
if __name__ == '__main__':
|
|
main()
|