(name: str)
| 684 | names = {name: None for model in models for name in model} |
| 685 | |
| 686 | def convert(name: str) -> LazyTensor: |
| 687 | lazy_tensors: list[LazyTensor] = [model[name] for model in models] |
| 688 | if len(lazy_tensors) == 1: |
| 689 | # only one file; don't go through this procedure since there might |
| 690 | # be quantized tensors |
| 691 | return lazy_tensors[0] |
| 692 | if len(lazy_tensors[0].shape) == 1: |
| 693 | # the tensor is just duplicated in every file |
| 694 | return lazy_tensors[0] |
| 695 | if name.startswith('tok_embeddings.') or \ |
| 696 | name.endswith('.attention.wo.weight') or \ |
| 697 | name.endswith('.feed_forward.w2.weight'): |
| 698 | # split by columns |
| 699 | axis = 1 |
| 700 | else: |
| 701 | # split by rows |
| 702 | axis = 0 |
| 703 | concatenated_shape = list(lazy_tensors[0].shape) |
| 704 | concatenated_shape[axis] = sum(tensor.shape[axis] for tensor in lazy_tensors) |
| 705 | |
| 706 | def load() -> UnquantizedTensor: |
| 707 | ndarrays = [load_unquantized(tensor) for tensor in lazy_tensors] |
| 708 | concatenated: NDArray = np.concatenate(ndarrays, axis=axis) |
| 709 | return UnquantizedTensor(concatenated) |
| 710 | description = 'concatenated[[' + '] | ['.join(lt.description for lt in lazy_tensors) + ']]' |
| 711 | return LazyTensor(load, concatenated_shape, lazy_tensors[0].data_type, description) |
| 712 | return {name: convert(name) for name in names} |
| 713 | |
| 714 |
no test coverage detected