Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions tools/convert_hf_to_fp8.py
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,8 @@ def process_file(input_path, output_path, filename, strategy, block_size, result
and "lm_head" not in key
and "eh_proj" not in key
and "weights_proj" not in key
and "vision_tower" not in key
and "mm_projector" not in key
):
qw, s = quant_fp8(weights[key], strategy, block_size)
q_weights[key] = qw
Expand Down
2 changes: 2 additions & 0 deletions tools/convert_hf_to_int4.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,8 @@ def main():
"re:.*shared_experts.*",
"re:.*mlp\\.(gate|up|gate_up|down)_proj.*",
"re:.*mlp\\.gate\\.*",
"re:vision_tower.*",
"re:mm_projector.*",
]

recipe = GPTQModifier(
Expand Down
2 changes: 2 additions & 0 deletions tools/convert_hf_to_int4_direct.py
Original file line number Diff line number Diff line change
Expand Up @@ -295,6 +295,8 @@ def parse_args():
"re:.*shared_experts.*",
"re:.*mlp\\.(gate|up|gate_up|down)_proj.*",
"re:.*mlp\\.gate\\.*",
"re:vision_tower.*",
"re:mm_projector.*",
],
help="Ignore Rules",
)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
"""
Usage:
------
python convert_k2_thinking_int4_to_bf16.py [-h] --model-dir MODEL_DIR [--output-dir OUTPUT_DIR]
python convert_kimi_int4_to_bf16.py [-h] --model-dir MODEL_DIR [--output-dir OUTPUT_DIR]
[--files FILE [FILE ...]] [--config-path CONFIG_PATH]
[--overwrite]
options:
Expand All @@ -20,7 +20,8 @@

Example:
--------
python convert_k2_thinking_int4_to_bf16.py --model-dir /Kimi-K2-Thinking --output-dir /Kimi-K2-Thinking-bf16
python convert_kimi_int4_to_bf16.py --model-dir /Kimi-K2-Thinking --output-dir /Kimi-K2-Thinking-bf16
python convert_kimi_int4_to_bf16.py --model-dir /Kimi-K2.5 --output-dir /Kimi-K2.5-bf16
"""

import argparse
Expand All @@ -40,10 +41,11 @@ def _load_config(model_dir: str, config_path: str | None) -> tuple[int, int, int
cfg_path = config_path or os.path.join(model_dir, "config.json")
with open(cfg_path) as f:
cfg = json.load(f)
hidden_size = int(cfg.get("hidden_size"))
inter_size = int(cfg.get("moe_intermediate_size"))
loader = cfg.get("text_config", cfg)
hidden_size = int(loader.get("hidden_size"))
inter_size = int(loader.get("moe_intermediate_size"))
group_size = int(
cfg.get("quantization_config", {})
loader.get("quantization_config", {})
.get("config_groups", {})
.get("group_0", {})
.get("weights", {})
Expand Down Expand Up @@ -218,7 +220,13 @@ def main():
dst_path = os.path.join(output_dir, fname)
if fname == "model.safetensors.index.json":
continue
if fname.endswith(".json") or fname.endswith(".py") or fname.startswith("tokenizer"):
if (
fname.endswith(".json")
or fname.endswith(".py")
or fname.startswith("tokenizer")
or fname.endswith(".jinja")
or fname.endswith(".model")
):
shutil.copy2(src_path, dst_path)

# Generate new index
Expand Down