Get information about a LoRA adapter. Args: adapter_path: Path to adapter directory Returns: Dict with adapter information
(adapter_path: str)
| 85 | |
| 86 | |
| 87 | def get_adapter_info(adapter_path: str) -> Dict: |
| 88 | """ |
| 89 | Get information about a LoRA adapter. |
| 90 | |
| 91 | Args: |
| 92 | adapter_path: Path to adapter directory |
| 93 | |
| 94 | Returns: |
| 95 | Dict with adapter information |
| 96 | """ |
| 97 | adapter_dir = Path(adapter_path) |
| 98 | info_dict = { |
| 99 | "path": str(adapter_dir), |
| 100 | "size_mb": 0, |
| 101 | "base_model": "unknown", |
| 102 | "lora_r": "unknown", |
| 103 | "lora_alpha": "unknown", |
| 104 | } |
| 105 | |
| 106 | # Calculate size |
| 107 | total_size = sum(f.stat().st_size for f in adapter_dir.rglob("*") if f.is_file()) |
| 108 | info_dict["size_mb"] = total_size / (1024 * 1024) |
| 109 | |
| 110 | # Read config |
| 111 | config_path = adapter_dir / "adapter_config.json" |
| 112 | if config_path.exists(): |
| 113 | try: |
| 114 | with open(config_path) as f: |
| 115 | config = json.load(f) |
| 116 | info_dict["base_model"] = config.get("base_model_name_or_path", "unknown") |
| 117 | info_dict["lora_r"] = config.get("r", "unknown") |
| 118 | info_dict["lora_alpha"] = config.get("lora_alpha", "unknown") |
| 119 | except: |
| 120 | pass |
| 121 | |
| 122 | return info_dict |
| 123 | |
| 124 | |
| 125 | # ============================================================================= |