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

✨🤖 Update RotatE to ERModel #877

Merged
merged 25 commits into from
Apr 19, 2022
Merged

✨🤖 Update RotatE to ERModel #877

merged 25 commits into from
Apr 19, 2022

Conversation

mberr
Copy link
Member

@mberr mberr commented Apr 16, 2022

This PR updates RotatE to new-style ERModel.

It also update Embedding to better encapsulate complex embeddings, and updates the interaction functions of ComplEx and RotatE to operate on PyTorch native complex tensors.

Benchmark

TL;DR: slightly slower evaluation (new 27.04s vs 26.74s); more than twice as fast in training (new 39.77s vs. 91.72s)

Quadro RTX 8000

Key Value
OS posix
Platform Linux
Release 5.4.0-81-generic
Time Sat Apr 16 18:12:51 2022
Python 3.8.10
PyKEEN 1.8.1-dev
PyKEEN Hash *
PyKEEN Branch *
PyTorch 1.10.0+cu113
CUDA Available? true
CUDA Version 11.3
cuDNN Version 8200
 pykeen experiments run sun2019_rotate_fb15k237.json 

with the configuration being equal to src/pykeen/experiments/rotate/sun2019_rotate_fb15k237.json @ f47ee602, except that the number of training epochs has been reduced to 2.

commit train eval
f47ee60 (master) 91.72s 26.74s*
b6024ce 78.68s 61.85s**
45f93c0 49.77s 61.78s**
f424bf0 40.16s 27.27s**
b5798db (update-rotate-to-ermodel) 39.77s 27.04s*
  • *: with batch_size=256
  • **: with batch_size=128

@mberr mberr mentioned this pull request Apr 16, 2022
8 tasks
@mberr mberr added the ✨ ERModel Upgrading old-style models to new-style label Apr 16, 2022
@mberr mberr changed the title Update RotatE to ERModel ✨🤖 Update RotatE to ERModel Apr 16, 2022
@@ -611,7 +611,7 @@ def rotate_interaction(
The scores.
"""
# r expresses a rotation in complex plane.
h, r, t = [view_complex(x) for x in (h, r, t)]
Copy link
Member

Choose a reason for hiding this comment

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

are we ready to replace this function with the torch builtin?

Copy link
Member Author

Choose a reason for hiding this comment

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

except in testing and dead code, we do not seem to reference this function anywhere else

@@ -347,7 +347,7 @@ def __init__(
# work-around until full complex support (torch==1.10 still does not work)
# TODO: verify that this is our understanding of complex!
if dtype.is_complex:
shape = tuple(shape[:-1]) + (2 * shape[-1],)
shape = tuple(shape[:-1]) + (shape[-1], 2)
Copy link
Member Author

Choose a reason for hiding this comment

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

this is the shape torch.view_as_complex expects, i.e., (..., 2)

@@ -661,11 +661,6 @@ def negative_norm(
assert not isinstance(p, str)
return -(x.abs() ** p).sum(dim=-1)

if torch.is_complex(x):
assert not isinstance(p, str)
# workaround for complex numbers: manually compute norm
Copy link
Member Author

Choose a reason for hiding this comment

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

not necessary anymore in current torch

@mberr mberr marked this pull request as ready for review April 16, 2022 20:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
✨ ERModel Upgrading old-style models to new-style
Projects
No open projects
Development

Successfully merging this pull request may close these issues.

None yet

2 participants