pytorch / pytorch

Tensors and Dynamic neural networks in Python with strong GPU acceleration
https://pytorch.org
Other
82.02k stars 21.99k forks source link

Generalizing cross product to hodge star operator #130807

Open redwrasse opened 1 month ago

redwrasse commented 1 month ago

🚀 The feature, motivation and pitch

Posting here to shop around and get feedback on the idea of generalizing the cross product operations in Pytorch to a hodge star operator: https://en.wikipedia.org/wiki/Hodge_star_operator

Hodge star generalizes the cross-product of 3-dimensions to arbitrary dimensions. It maps a k differential form to a d-k differential form. While it looks involved at first glance, it can likely be computed fairly easily with the existing Pytorch machinery (however whether also efficiently, would have to be investigated).

Conceptually it would make sense for Pytorch if there's not much special about 3 dimensional space (exception here seems to be 3d convolutions and related applications). Indeed, most Pytorch tensor operations operate on arbitrary dimensionality.

Counterargument is the suite of differential geometry operations is not part of the standard deep learning application repertoire, though Lie groups do present more and more in research. For example, here's one google search hit: https://github.com/lucidrains/lie-transformer-pytorch/blob/main/lie_transformer_pytorch/se3.py#L72

Alternatives

No response

Additional context

No response

cc @albanD

albanD commented 1 month ago

Hey! Thanks for opening the discussion here. I would be curious how this aligns with the cross product in the Python Array API https://data-apis.org/array-api/latest/extensions/generated/array_api.linalg.cross.html#cross (the shared standard we're trying to adopt for python-based array computing libraries)?

redwrasse commented 1 month ago

It looks like the Python Array API cross-product method is also restricted to 3 dimensional vectors.

I suspect very few existing general purpose numerical computation libraries will have a concept of non-3-dimensional only cross product (hodge star). But, I also suspect the cross product exists in these libraries because the implementers are familiar with it (right-hand rule from electricity and magnetism classes), which may be distinct from applicability to deep learning use cases (indeed it's one of the awkward 'only works in 3-dimensions' operations from the perspective of the Pytorch API).

I'm not advocating here to put hodge star in, but soliciting a discussion. It is indeed a very general operator for a large class of operations, but someone more closely involved in the deep learning research community, and using geometric methods, may want to chime in here.

amjames commented 1 month ago

@redwrasse IMO generalizing cross in this way would be premature at this point. Since we strive for Array API compliance where we can achieve and maintain it, taking a step backward here would not be ideal. Weighing the usefulness/demand for the generalized definition against Array API compliance the late is winning in my mind.

I can think of one situation where it would make sense to generalize cross this way in torch, and that would be if the Array API standard is amended to include the generalized definition. That conversation would begin with the data-apis consortium, and their process for considering **extension/revisions

On the other hand, introducing a new hode_star operation would not be subject to considerations of standard compliance. It would instead be evaluated on the basis of usefulness and the general needs of the community. Starting with an implementation available as a downstream extension would be a good idea for that path.

redwrasse commented 1 month ago

@amjames, thanks for the input. I agree as well, Array API compliance should take priority- so from that perspective, generalizing cross can be ruled out.

As for exploring an independent hodge star operation, would need some more data points from the research community. I suspect there are some, but not many, researchers using such differential geometry methods.