(base_path: str, loras: List[str], scales: List[str])
| 21 | |
| 22 | |
| 23 | def apply_loras(base_path: str, loras: List[str], scales: List[str]) -> dict: |
| 24 | refit_dict = merge_loras(loras, scales) |
| 25 | base = onnx.load(base_path) |
| 26 | onnx_opt_dir = os.path.dirname(base_path) |
| 27 | |
| 28 | def convert_int64(arr): |
| 29 | if len(arr.shape) == 0: |
| 30 | return np.array([np.int32(arr)]) |
| 31 | return arr |
| 32 | |
| 33 | for initializer in base.graph.initializer: |
| 34 | if initializer.name not in refit_dict: |
| 35 | continue |
| 36 | |
| 37 | wt = refit_dict[initializer.name] |
| 38 | initializer_data = numpy_helper.to_array( |
| 39 | initializer, base_dir=onnx_opt_dir |
| 40 | ).astype(np.float16) |
| 41 | delta = torch.tensor(initializer_data).to(wt.device) + wt |
| 42 | |
| 43 | refit_dict[initializer.name] = delta.contiguous() |
| 44 | |
| 45 | return refit_dict |
no test coverage detected