Parse command line arguments
()
| 41 | |
| 42 | if dtype_str not in dtype_mapping: |
| 43 | raise ValueError(f"Unsupported data type: {dtype_str}") |
| 44 | |
| 45 | return dtype_mapping[dtype_str] |
| 46 | |
| 47 | |
| 48 | def parse_args(): |
| 49 | """Parse command line arguments""" |
| 50 | parser = argparse.ArgumentParser(description="Merge a source model with LoRA weights to create a new model", formatter_class=argparse.ArgumentDefaultsHelpFormatter) |
| 51 | |
| 52 | # Source model parameters |
| 53 | parser.add_argument("--source-model", type=str, required=True, help="Path to source model") |
| 54 | parser.add_argument("--source-type", type=str, choices=["safetensors", "pytorch"], default="safetensors", help="Source model format type") |
| 55 | |
| 56 | # LoRA parameters |
| 57 | parser.add_argument("--lora-model", type=str, required=True, help="Path to LoRA weights") |
| 58 | parser.add_argument("--lora-type", type=str, choices=["safetensors", "pytorch"], default="safetensors", help="LoRA weights format type") |
| 59 | |
| 60 | # Output parameters |
| 61 | parser.add_argument("--output", type=str, required=True, help="Path to output merged model") |
| 62 | parser.add_argument("--output-format", type=str, choices=["safetensors", "pytorch"], default="safetensors", help="Output model format") |
| 63 | |
| 64 | # Merge parameters |
| 65 | parser.add_argument("--alpha", type=float, default=1.0, help="LoRA merge strength (alpha value)") |
| 66 | parser.add_argument("--output-dtype", type=str, choices=["float32", "fp32", "float16", "fp16", "bfloat16", "bf16"], default="bf16", help="Output weight data type") |