(*, weight, bias, split, chunk_size)
| 836 | |
| 837 | # TODO maybe document and/or can do more efficiently (build indices in for loop and extract once for each split?) |
| 838 | def split_attentions(*, weight, bias, split, chunk_size): |
| 839 | weights = [None] * split |
| 840 | biases = [None] * split |
| 841 | |
| 842 | weights_biases_idx = 0 |
| 843 | |
| 844 | for starting_row_index in range(0, weight.shape[0], chunk_size): |
| 845 | row_indices = torch.arange(starting_row_index, starting_row_index + chunk_size) |
| 846 | |
| 847 | weight_rows = weight[row_indices, :] |
| 848 | bias_rows = bias[row_indices] |
| 849 | |
| 850 | if weights[weights_biases_idx] is None: |
| 851 | assert weights[weights_biases_idx] is None |
| 852 | weights[weights_biases_idx] = weight_rows |
| 853 | biases[weights_biases_idx] = bias_rows |
| 854 | else: |
| 855 | assert weights[weights_biases_idx] is not None |
| 856 | weights[weights_biases_idx] = torch.concat([weights[weights_biases_idx], weight_rows]) |
| 857 | biases[weights_biases_idx] = torch.concat([biases[weights_biases_idx], bias_rows]) |
| 858 | |
| 859 | weights_biases_idx = (weights_biases_idx + 1) % split |
| 860 | |
| 861 | return weights, biases |
| 862 | |
| 863 | |
| 864 | # done unet utils |
no outgoing calls
no test coverage detected