Join GitHub today
GitHub is home to over 40 million developers working together to host and review code, manage projects, and build software together.
Sign upLogCumsumExp #26411
LogCumsumExp #26411
Comments
This comment has been minimized.
This comment has been minimized.
|
I would like to work on this. |
This comment has been minimized.
This comment has been minimized.
|
@opheliagame see #20240 (comment) for |
This comment has been minimized.
This comment has been minimized.
|
HI @agadetsky , I created a PR #26832 for this issues. But I am not sure If I am doing it right in the implementation part, I stop just before the line mask = torch.tril(torch.ones(last_dim_size, last_dim_size)).unsqueeze(0) in python implementation. It would be great if you can review THTensor_(logcumsumexp) in THTensormoreMath.cpp. I want to make sure I am going in right direction. Many thanks! |
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
|
Hi, Yes I could try work on it. |
This comment has been minimized.
This comment has been minimized.
|
@agadetsky what do you use to loop over multi-dimensional tensor in C++, I am trying to compute the convert value of the tensor to 1s and 0s |
This comment has been minimized.
This comment has been minimized.
|
@michiboo unfortunately I am not familiar with pytorch C++ implementation. |
This comment has been minimized.
This comment has been minimized.
|
@michiboo Hi, are you still working on this issue? |
This comment has been minimized.
This comment has been minimized.
|
I will try to submit a PR for this by the weekend, if not needed urgently. PS: @agadetsky I can't seem to assign myself the issue |
This comment has been minimized.
This comment has been minimized.
|
@pandeykartikey thank you, waiting for your PR |
This comment has been minimized.
This comment has been minimized.
|
@pandeykartikey you can use implemented cummax for stable implementation of logcumsumexp |
This comment has been minimized.
This comment has been minimized.
|
@agadetsky Wouldn't that create issues while building a feature because It can undergo drastic changes in implementation as it is being reviewed right now? |
This comment has been minimized.
This comment has been minimized.
|
@pandeykartikey better to ask someone else, atm I don't know, but I think that without cummax it is harder to implement logcumsumexp properly |
This comment has been minimized.
This comment has been minimized.
|
@pandeykartikey hi! do you have any progress? |
This comment has been minimized.
This comment has been minimized.
|
@pandeykartikey cummax is merged now (#30881), is it possible to implement logcumsumexp for you using cummax? |
This comment has been minimized.
This comment has been minimized.
|
Hi @agadetsky, I am almost done with the implementation. Only the backprop and tests are left. But I am having trouble figuring out the backprop algorithm. Can you help me with that? |
Add numerically stable cumulative logsumexp function. Also we have associated PR on
cummaxthat is needed for numerically stable implementation (#20240).Motivation
This is useful when computing sum of probabilities and have different applications.
Pitch
Torch has
cumsumandcumprodso I suggestlogcumsumexpto be added.Alternatives
Current workaround for me and for people that need it can be written as follows (it is quite fast, only overhead for converting between numpy/torch):
UPDATE: code above is not always numerically stable. Still most numerically stable, but slow way to compute
logcumsumexpis use for-loop: