(*, weight, bias, split, chunk_size)
| 896 | |
| 897 | # TODO maybe document and/or can do more efficiently (build indices in for loop and extract once for each split?) |
| 898 | def split_attentions(*, weight, bias, split, chunk_size): |
| 899 | weights = [None] * split |
| 900 | biases = [None] * split |
| 901 | |
| 902 | weights_biases_idx = 0 |
| 903 | |
| 904 | for starting_row_index in range(0, weight.shape[0], chunk_size): |
| 905 | row_indices = torch.arange(starting_row_index, starting_row_index + chunk_size) |
| 906 | |
| 907 | weight_rows = weight[row_indices, :] |
| 908 | bias_rows = bias[row_indices] |
| 909 | |
| 910 | if weights[weights_biases_idx] is None: |
| 911 | assert weights[weights_biases_idx] is None |
| 912 | weights[weights_biases_idx] = weight_rows |
| 913 | biases[weights_biases_idx] = bias_rows |
| 914 | else: |
| 915 | assert weights[weights_biases_idx] is not None |
| 916 | weights[weights_biases_idx] = torch.concat([weights[weights_biases_idx], weight_rows]) |
| 917 | biases[weights_biases_idx] = torch.concat([biases[weights_biases_idx], bias_rows]) |
| 918 | |
| 919 | weights_biases_idx = (weights_biases_idx + 1) % split |
| 920 | |
| 921 | return weights, biases |
| 922 | |
| 923 | |
| 924 | # done unet utils |
no outgoing calls
no test coverage detected