Skip to content

Conversation

@braun-steven
Copy link
Contributor

This adds the logsumexp function using the logsumexp trick which is the numerical stable version of applying log(sum(exp(x))). I chose to default to the backend implementation if available (pytorch, numpy/scipy, tensorflow, jax) and implemented the numerical stable computation of log(sum(exp(x))) when the backend did not provide a logsumexp function (mxnet, cupy).

Additionally, I've added a unit test that checks against the numpy/scipy baseline with some 3d data tensor over all axis.

This adds the logsumexp function using the logsumexp trick which is the
numerical stable version of applying `log(sum(exp(x)))`. I chose to
default to the backend implementation if available (pytorch,
numpy/scipy, tensorflow, jax) and implemented the numerical stable
computation of `log(sum(exp(x)))` when the backend did not provide a
logsumexp function (mxnet, cupy).

Additionally, I've added a unit test that checks against the numpy/scipy
baseline with some 3d data tensor over all axis.
@braun-steven braun-steven changed the title Feature/logsumexp Add logsumexp function Feb 27, 2023
@codecov
Copy link

codecov bot commented Feb 28, 2023

Codecov Report

Merging #491 (ba9c055) into main (4b7abac) will decrease coverage by 3.68%.
The diff coverage is 66.66%.

@@            Coverage Diff             @@
##             main     #491      +/-   ##
==========================================
- Coverage   86.79%   83.12%   -3.68%     
==========================================
  Files         120      120              
  Lines        7392     7395       +3     
==========================================
- Hits         6416     6147     -269     
- Misses        976     1248     +272     
Impacted Files Coverage Δ
tensorly/backend/__init__.py 79.66% <ø> (-10.17%) ⬇️
tensorly/backend/core.py 62.68% <66.66%> (-6.44%) ⬇️
tensorly/contrib/decomposition/_tt_cross.py 4.29% <0.00%> (-84.67%) ⬇️
...ecomposition/tests/test_mps_decomposition_cross.py 21.79% <0.00%> (-78.21%) ⬇️
tensorly/contrib/sparse/tests/test_tenalg.py 29.41% <0.00%> (-70.59%) ⬇️
...ensorly/contrib/sparse/tests/test_decomposition.py 41.17% <0.00%> (-58.83%) ⬇️
tensorly/utils/_prod.py 71.42% <0.00%> (-28.58%) ⬇️
tensorly/contrib/sparse/core.py 75.00% <0.00%> (-25.00%) ⬇️
tensorly/contrib/sparse/backend/__init__.py 75.86% <0.00%> (-10.35%) ⬇️
... and 4 more

📣 We’re building smart automated test selection to slash your CI/CD build times. Learn more

@JeanKossaifi
Copy link
Member

Thanks @braun-steven! Is there anywhere it could be used in the current codebase or is this just for new functionalities?

@braun-steven
Copy link
Contributor Author

braun-steven commented Mar 8, 2023

I haven't found any use cases in the current code base. We need the functionality for our library SPFlow which we are currently rewriting to be used with tensorly as backend. We could have also written it as part of our codebase but thought that pushing the added functionality upstream would be good for tensorly as well.

@JeanKossaifi
Copy link
Member

Indeed, thanks for contributing @braun-steven ! Looks good to me, merging.

@JeanKossaifi JeanKossaifi merged commit a26ffe0 into tensorly:main Mar 8, 2023
@braun-steven braun-steven deleted the feature/logsumexp branch March 8, 2023 06:43
@JeanKossaifi
Copy link
Member

As a side note @braun-steven let us know if you need more features on the tensorly side -- we can also showcase SPFlow somewhere on the website, e.g. in an ecosystem page or something!

@braun-steven
Copy link
Contributor Author

As a side note @braun-steven let us know if you need more features on the tensorly side

Will do! But I think we will probably be able to implement most functionality that we need and is missing ourselves and push it upstream. In case of issues/questions/problems we will definitely get back at you :)

The current status is that the rewrite of SPFlow is quite far and we wanted to initially support a numpy and a torch backend which was almost done, with support for TensorFlow and Jax in future (>1.0.0) versions. Then we found out about tensorly and investigated if it is worth the effort to replace the numpy backend with tensorly to get all the backends "for free" (with the exception of some specific modules such as probability distributions etc). So the current status is that we are replacing numpy with tensorly and see how far we come and into how many issues we run on our side.

we can also showcase SPFlow somewhere on the website, e.g. in an ecosystem page or something!

That sounds awesome! Once the backend rewrite is done and we are ready to release our 1.0.0 version built on top of tensorly, I would gladly come back at you :)

@felixdivo
Copy link

I think this wasn't added to the docs, or did I just miss it?

https://tensorly.org/stable/search.html?q=logsumexp

@JeanKossaifi
Copy link
Member

Indeed, it hasn't been added, good catch @felixdivo! Do you want to make a small PR and add it to the doc (in the API doc)?
I can add it later otherwise.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants