Download code/convert_lora_for_vllm.py from fdemelo/jegue: direct link, hf CLI and curl.
- Browser
- Download file 1 kB
-
https://huggingface.co/fdemelo/jegue/resolve/main/code/convert_lora_for_vllm.py
- Command line
-
hf download hf://fdemelo/jegue/code/convert_lora_for_vllm.py
-
curl -L -o convert_lora_for_vllm.py https://huggingface.co/fdemelo/jegue/resolve/main/code/convert_lora_for_vllm.py
1 kB
| #!/usr/bin/env python3 | |
| """Rename the keys of a text-only PEFT adapter (base_model.model.model.layers.*) to the Qwen3.5 conditional-generation layout vLLM expects | |
| (base_model.model.model.language_model.layers.*). vLLM otherwise DROPS the adapter silently (checked 2026-10-24: outputs equal the base model). | |
| python tools/convert_lora_for_vllm.py SRC_LORA_DIR DST_DIR""" | |
| import json, os, shutil, sys | |
| from safetensors.torch import load_file, save_file | |
| src, dst = sys.argv[1:3] | |
| os.makedirs(dst, exist_ok=True) | |
| sd = load_file(os.path.join(src, "adapter_model.safetensors")) | |
| new = {k.replace("base_model.model.model.layers.", "base_model.model.model.language_model.layers.", 1): v for k, v in sd.items()} | |
| assert len(new) == len(sd) and any("language_model" in k for k in new) | |
| save_file(new, os.path.join(dst, "adapter_model.safetensors"), metadata={"format": "pt"}) | |
| shutil.copy(os.path.join(src, "adapter_config.json"), os.path.join(dst, "adapter_config.json")) | |
| print(len(new), "tensors written to", dst) | |