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

tensor compression seems to not work #50

Open
LukGross opened this issue May 2, 2024 · 1 comment
Open

tensor compression seems to not work #50

LukGross opened this issue May 2, 2024 · 1 comment

Comments

@LukGross
Copy link

LukGross commented May 2, 2024

The straight forward TT-decomposition of a full tensor does not work properly for me.

Minimal example:

import tntorch as tn
import torch
import numpy as np

X, Y, Z = np.meshgrid(range(128), range(128), range(128))
full = torch.Tensor(
    np.sqrt(np.sqrt(X) * (Y + Z) + Y * Z**2) * (X + np.sin(Y) * np.cos(Z))
)  # Some analytical 3D function
print(full.shape)

t = tn.Tensor(full, ranks_tt=3, requires_grad=True)  # You can also pass a list of ranks


def metrics():
    print(t)
    print(
        "Compression ratio: {}/{} = {:g}".format(
            full.numel(), t.numel(), full.numel() / t.numel()
        )
    )
    print("Relative error:", tn.relative_error(full, t))
    print("RMSE:", tn.rmse(full, t))
    print("R^2:", tn.r_squared(full, t))


metrics()

Output:

torch.Size([128, 128, 128])
3D TT tensor:

 128 128 128
  |   |   |
 (0) (1) (2)
 / \ / \ / \
1   3   3   1

Compression ratio: 2097152/2097152.0 = 1
Relative error: tensor(0.0005, grad_fn=<DivBackward0>)
RMSE: tensor(22.0728, grad_fn=<DivBackward0>)
R^2: tensor(1.0000, grad_fn=<RsubBackward1>)

The expected output would be the one given in the tutorial.
Especially, compression ratio should be $&gt;0$.

I experience this behavior both with python 3.9.6 and 3.12.2 on an M1 MacBook under macOS Sonoma 14.4.1

@LukGross
Copy link
Author

LukGross commented May 3, 2024

same problem under ubuntu 22, python 3.9.19

@LukGross LukGross changed the title tensor compression seems to not work (on apple silicon?) tensor compression seems to not work May 3, 2024
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

1 participant