[Feature suggestion] UnPack proportionally
lkhphuc opened this issue · comments
Phúc H. Lê Khắc commented
- Try to collect use-cases
If you don't have access to the input API to use pack but still want to unpack it with einops, you would need to know the size of the output. This is not ideal if you known the proportion that you want to unpack into.
x = MyBigPretrainedLibraryImportModel(size='base') # base, large, huge
# Instead of
b, s, c = x.shape # c is different depending on model size
c_param = c // 2
x_mean, x_logvar = unpack(x, [[c_param], [c_param]], 'b s *')
# Accept this
x_mean, x_logvar = unpack(x, [[0.5], [0.5]], 'b s *')
- Integrity - does it interplay well with existing operations and notation in einops?
pack and unpack currently only accepts int, so accepting float shouldn't break anything.
Incase of float it will be a bit more job, like ensuring all sum to 1, each proportion will scale up to a proper integer etc.
assert c == 512
x1, x_2, x_3 = unpack(x, [[1/3], [1/3], [1/4], 'b s *') # Raise error as 1/3 + 1/3 + 1/4 != 1
x1, x_2, x_3 = unpack(x, [[1/3], [1/3], [1/3], 'b s *') # Raise error as 512 is not divisible by 3
- Readability
The complexity of checking validity of proportion might not worth adding it to the library and should be handled by a few lines of user code.