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

PyTorch only cauchy kernel for easier test #9

Closed
bratao opened this issue Mar 2, 2022 · 5 comments
Closed

PyTorch only cauchy kernel for easier test #9

bratao opened this issue Mar 2, 2022 · 5 comments

Comments

@bratao
Copy link

bratao commented Mar 2, 2022

Hello,

I loved Structured State Spaces, and obteined a fantastic performance compared to LSTM/SRU/Transformers.

I want to introduce S4 to some researchers and students, and the self-contained S4 layer is super great! However it requires the "cautchy kernel".

There are two versions of cautchy kernel, a cuda and a Pykeops version.

However extensions/cauchy requires cuda and Pykeops do not support Windows, and the target people have a very diverse number of environments.

Would be possible to HazyResearch team to implement a self-contained S4 layer including a simpler pytorch cautchy kernel ?

@albertfgu
Copy link
Contributor

These extensions are required because the algorithm requires functionality that is not supported in vanilla PyTorch. There is a pure PyTorch implementation of the kernel that is slower and uses more memory. To use it, in the line https://github.com/HazyResearch/state-spaces/blob/2af126108991d214fd82ffc1899f6d4e31a1eda3/src/models/sequence/ss/kernel.py#L322 replace cauchy.cauchy_conj with cauchy.cauchy_conj_slow.
Or if you're using the standalone module, replace the cauchy function with the one found here https://github.com/HazyResearch/state-spaces/blob/2af126108991d214fd82ffc1899f6d4e31a1eda3/src/models/functional/cauchy.py#L124

@bratao
Copy link
Author

bratao commented Mar 6, 2022

That worked @albertfgu , thank you!
I will open a PR to use this as fallback on the standalone module

@albertfgu
Copy link
Contributor

No problem. I can also make the requisite changes to fall back on this - should be pretty simple.

Do keep in mind again that this version is less efficient, so it might be useful for preliminary testing but we would recommend trying to set up the full environment if possible.

Also, there is an excellent port of S4 to JAX here if that might be easier to set up: https://srush.github.io/annotated-s4/

@albertfgu
Copy link
Contributor

I just added a fallback to the slow version. Can you test this?

@bratao
Copy link
Author

bratao commented Mar 6, 2022

Works perfectly @albertfgu , thank you!

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

No branches or pull requests

2 participants