()
| 235 | |
| 236 | |
| 237 | def parse_args() -> argparse.Namespace: |
| 238 | parser = argparse.ArgumentParser( |
| 239 | description="Convert a Hugging Face PEFT LoRA adapter to a GGUF file") |
| 240 | parser.add_argument( |
| 241 | "--outfile", type=Path, |
| 242 | help="path to write to; default: based on input. {ftype} will be replaced by the outtype.", |
| 243 | ) |
| 244 | parser.add_argument( |
| 245 | "--outtype", type=str, choices=["f32", "f16", "bf16", "q8_0", "auto"], default="f32", |
| 246 | help="output format - use f32 for float32, f16 for float16, bf16 for bfloat16, q8_0 for Q8_0, auto for the highest-fidelity 16-bit float type depending on the first loaded tensor type", |
| 247 | ) |
| 248 | parser.add_argument( |
| 249 | "--bigendian", action="store_true", |
| 250 | help="model is executed on big endian machine", |
| 251 | ) |
| 252 | parser.add_argument( |
| 253 | "--no-lazy", action="store_true", |
| 254 | help="use more RAM by computing all outputs before writing (use in case lazy evaluation is broken)", |
| 255 | ) |
| 256 | parser.add_argument( |
| 257 | "--verbose", action="store_true", |
| 258 | help="increase output verbosity", |
| 259 | ) |
| 260 | parser.add_argument( |
| 261 | "--dry-run", action="store_true", |
| 262 | help="only print out what will be done, without writing any new files", |
| 263 | ) |
| 264 | parser.add_argument( |
| 265 | "--base", type=Path, |
| 266 | help="directory containing Hugging Face model config files (config.json, tokenizer.json) for the base model that the adapter is based on - only config is needed, actual model weights are not required. If base model is unspecified, it will be loaded from Hugging Face hub based on the adapter config", |
| 267 | ) |
| 268 | parser.add_argument( |
| 269 | "--base-model-id", type=str, |
| 270 | help="the model ID of the base model, if it is not available locally or in the adapter config. If specified, it will ignore --base and load the base model config from the Hugging Face hub (Example: 'meta-llama/Llama-3.2-1B-Instruct')", |
| 271 | ) |
| 272 | parser.add_argument( |
| 273 | "lora_path", type=Path, |
| 274 | help="directory containing Hugging Face PEFT LoRA config (adapter_model.json) and weights (adapter_model.safetensors or adapter_model.bin)", |
| 275 | ) |
| 276 | |
| 277 | return parser.parse_args() |
| 278 | |
| 279 | |
| 280 | def load_hparams_from_hf(hf_model_id: str) -> tuple[dict[str, Any], Path | None]: |
no test coverage detected