Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add TTOI functions #411

Merged
merged 17 commits into from Dec 27, 2022
Merged

Add TTOI functions #411

merged 17 commits into from Dec 27, 2022

Conversation

Lili-Zheng-stat
Copy link
Contributor

I just created a new branch in my repository that is updated with the current version of TensorLy. The updated tensor train functions (tt_TTOI.py in tensorly/tensorly/contrib/decomposition, and test_tt_TTOI.py in tensorly/tensorly/contrib/decomposition/tests) are also added and pass the tests with backend = numpy or pytorch.

@codecov
Copy link

codecov bot commented Jun 16, 2022

Codecov Report

Merging #411 (c72ef9c) into main (ade7a87) will increase coverage by 0.17%.
The diff coverage is 94.16%.

@@            Coverage Diff             @@
##             main     #411      +/-   ##
==========================================
+ Coverage   86.84%   87.01%   +0.17%     
==========================================
  Files         118      120       +2     
  Lines        7313     7432     +119     
==========================================
+ Hits         6351     6467     +116     
- Misses        962      965       +3     
Impacted Files Coverage Δ
tensorly/contrib/decomposition/tt_TTOI.py 92.47% <92.47%> (ø)
...nsorly/contrib/decomposition/tests/test_tt_TTOI.py 100.00% <100.00%> (ø)
tensorly/tenalg/svd.py 88.88% <100.00%> (+0.08%) ⬆️
tensorly/tenalg/proximal.py 67.68% <0.00%> (+0.23%) ⬆️
tensorly/backend/__init__.py 89.83% <0.00%> (+2.54%) ⬆️

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

Copy link
Member

@JeanKossaifi JeanKossaifi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @Lili-Zheng-stat, it's much clearer! I left some mostly stylistic comments in the code. Would be great to apply pep8 formatting too.
Looking to have TTOI in TensorLy!

and len(rank) == len(tl.shape(data_tensor))+1
n_iter : int
half the number of iterations
trajectory : bool, optional, default is False
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there a practical case where we'd actually want this? It would be quite memory heavy.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This option can be set as false in practice; I am only leaving this option for sanity check in the test function, making sure that our iteration is giving better approximation and estimation when iteration number increases!

tensorly/contrib/decomposition/tt_TTOI.py Outdated Show resolved Hide resolved
tensorly/contrib/decomposition/tt_TTOI.py Outdated Show resolved Hide resolved
tensorly/contrib/decomposition/tt_TTOI.py Outdated Show resolved Hide resolved
tensorly/contrib/decomposition/tt_TTOI.py Outdated Show resolved Hide resolved
tensorly/contrib/decomposition/tt_TTOI.py Outdated Show resolved Hide resolved
@JeanKossaifi
Copy link
Member

Thanks @Lili-Zheng-stat!

The issue in the tests comes from the fact that we changed the SVD interface in #429, the best would be to use tensorly.tenalg.svd_interface. @aarmey perhaps we should deprecate tl.partial_svd or at least raise an error if users try to use it, to let them know they should switch to the new interface?

@aarmey
Copy link
Contributor

aarmey commented Aug 16, 2022

Thanks @Lili-Zheng-stat!

The issue in the tests comes from the fact that we changed the SVD interface in #429, the best would be to use tensorly.tenalg.svd_interface. @aarmey perhaps we should deprecate tl.partial_svd or at least raise an error if users try to use it, to let them know they should switch to the new interface?

Good idea. I'll add a deprecation before we think about releasing this.

@Lili-Zheng-stat
Copy link
Contributor Author

Thanks @Lili-Zheng-stat!

The issue in the tests comes from the fact that we changed the SVD interface in #429, the best would be to use tensorly.tenalg.svd_interface. @aarmey perhaps we should deprecate tl.partial_svd or at least raise an error if users try to use it, to let them know they should switch to the new interface?

Thanks for checking the errors! I updated the code so that it calls the new svd_interface now.

@caglayantuna
Copy link
Member

You can format your files with Black. Then, it will pass the test. To use Black;

pip install black
black filename.py

@JeanKossaifi
Copy link
Member

Thanks @Lili-Zheng-stat -- sorry for the delay, I'll try to make another review asap. Would be great if someone else could also have a look, maybe @merajhashemi since you're familiar with TT too?

Copy link
Contributor

@cohenjer cohenjer left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @Lili-Zheng-stat, the code looks nice and the method is cool :)
I left a few comments. Maybe it could be nice to see some example of the code in action, possibly added to the Tensorly examples? But that can be done later in a subsequent PR.

tensorly/contrib/decomposition/tt_TTOI.py Show resolved Hide resolved
tensorly/contrib/decomposition/tt_TTOI.py Outdated Show resolved Hide resolved
tensorly/contrib/decomposition/tt_TTOI.py Outdated Show resolved Hide resolved
for iteration in range(n_iter):
# first perform forward update
# left_singular_vectors will be a list including estimated left singular spaces at the current iteration
left_singular_vectors = list()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It would be nice to provide some sort of initialization. In the paper referenced in the comments, the authors suggest to initialize with TT-SVD, which we have available in Tensorly. Maybe you could use that for initialization by default, and add an input option in the signature to allow custom initialization. You can check how we handle initialization in e.g. the _cp.py file.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the suggestion! However, our later updates make use of many intermediate product obtained during the TT-SVD algorithm, and it would need a lot of changes in our code structure if we want to use the default TT-SVD function.... If possible, I would prefer not changing this now...

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I meant using TT-SVD for initialization, not for the updates. But if this is a huge modification then sure the current version is fine.
Would be nice still to allow custom initialization, that does not seem too hard?

tensorly/contrib/decomposition/tt_TTOI.py Show resolved Hide resolved
@Lili-Zheng-stat Lili-Zheng-stat requested review from JeanKossaifi and cohenjer and removed request for JeanKossaifi and cohenjer November 7, 2022 07:06
Copy link
Member

@merajhashemi merajhashemi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I left a few comments. There are sometl.tensors which I think are not necessary. Removing them could improve code readability.

tensorly/contrib/decomposition/tt_TTOI.py Outdated Show resolved Hide resolved
tensorly/contrib/decomposition/tt_TTOI.py Outdated Show resolved Hide resolved
tensorly/contrib/decomposition/tt_TTOI.py Outdated Show resolved Hide resolved
tensorly/contrib/decomposition/tt_TTOI.py Outdated Show resolved Hide resolved
@JeanKossaifi
Copy link
Member

JeanKossaifi commented Nov 20, 2022

It looks good to me, thanks for all the change @Lili-Zheng-stat -- it looks good to me. Can you just skip the test for MXNet (and maybe add a small test on 3rd or 4th order tensor). MXNet currently doesn't support >6th order tensors.
There's also a small issue with Black, should be a quick fix.

Can you also add the new function to the API?

I think we can merge it afterwards!

@JeanKossaifi
Copy link
Member

@Lili-Zheng-stat apologies, the tests are failing due to an unrelated issue, could you merge main, that should fix the issue! Thanks!

@Lili-Zheng-stat
Copy link
Contributor Author

Sorry that I just saw this! It seems that you have merged main already? Let me know if there is anything else I need to do at this point. Thanks!!

@JeanKossaifi
Copy link
Member

Yes, I realized you enabled edit from maintainers so I went ahead and merged / fixed the issue, looks like tests are passing now, merging.

Thanks a lot for the PR @Lili-Zheng-stat, this is a great addition! It would be great to add an example in a separate PR.
And thanks @cohenjer @merajhashemi @aarmey @caglayantuna for the reviews!

@JeanKossaifi JeanKossaifi merged commit 9e448d7 into tensorly:main Dec 27, 2022
@Lili-Zheng-stat
Copy link
Contributor Author

Awesome!! Thanks to everyone @JeanKossaifi @cohenjer @merajhashemi @aarmey @caglayantuna for the review and all the suggestions!

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.

None yet

6 participants