MCPcopy Create free account
hub / github.com/YesianRohn/TextSSR / split_attentions

Function split_attentions

diffusers/scripts/convert_shap_e_to_diffusers.py:898–921  ·  view source on GitHub ↗
(*, weight, bias, split, chunk_size)

Source from the content-addressed store, hash-verified

896
897# TODO maybe document and/or can do more efficiently (build indices in for loop and extract once for each split?)
898def 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

Callers 1

Calls

no outgoing calls

Tested by

no test coverage detected