Parse command line arguments
()
| 41 | raise ValueError(f"{name} must be a non-empty path") |
| 42 | setattr(self, name, os.path.expandvars(os.path.expanduser(getattr(self, name)))) |
| 43 | if not isinstance(self.layers, list) or not self.layers or any(not isinstance(layer, str) or not layer or layer.endswith(".weight") for layer in self.layers): |
| 44 | raise ValueError("layers must be a non-empty list of module names/glob patterns without .weight") |
| 45 | if type(self.rank) is not int or self.rank < 1: |
| 46 | raise ValueError("rank must be a positive integer") |
| 47 | self.alpha = float(self.rank if self.alpha is None else self.alpha) |
| 48 | if not math.isfinite(self.alpha) or self.alpha <= 0: |
| 49 | raise ValueError("alpha must be positive and finite") |
| 50 | torch_dtype(self.dtype) |
| 51 | if self.key_prefix not in ("auto", "transformer", "diffusion_model"): |
| 52 | raise ValueError("key_prefix must be auto, transformer or diffusion_model") |
| 53 | if not self.output.endswith(".safetensors"): |
| 54 | raise ValueError("output must end in .safetensors") |
| 55 | |
| 56 | |
| 57 | def load_config(path, overrides=None): |
| 58 | path = Path(path) |
| 59 | if path.suffix.lower() == ".json": |
| 60 | values = json.loads(path.read_text()) |
| 61 | else: |
| 62 | import yaml |
| 63 | |
| 64 | values = yaml.safe_load(path.read_text()) |
| 65 | if not isinstance(values, dict): |
| 66 | raise TypeError("Config must contain a mapping") |
| 67 | unknown = set(values) - {field.name for field in fields(ExtractConfig)} |
| 68 | if unknown: |