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

TTTensor class #23089

Merged
merged 15 commits into from
Sep 17, 2023
Merged

TTTensor class #23089

merged 15 commits into from
Sep 17, 2023

Conversation

mobley-trent
Copy link
Contributor

Closes #22188

@github-actions
Copy link
Contributor

github-actions bot commented Sep 5, 2023

Thanks for contributing to Ivy! 😊👏
Here are some of the important points from our Contributing Guidelines 📝:
1. Feel free to ignore the run_tests (1), run_tests (2), … jobs, and only look at the display_test_results job. 👀 It contains the following two sections:
- Combined Test Results: This shows the results of all the ivy tests that ran on the PR. ✔️
- New Failures Introduced: This lists the tests that are passing on main, but fail on the PR Fork. Please try to make sure that there are no such tests. 💪
2. The lint / Check formatting / check-formatting tests check for the formatting of your code. 📜 If it fails, please check the exact error message in the logs and fix the same. ⚠️🔧
3. Finally, the test-docstrings / run-docstring-tests check for the changes made in docstrings of the functions. This may be skipped, as well. 📚
Happy coding! 🎉👨‍💻

Copy link
Contributor

@hello-fri-end hello-fri-end left a comment

Choose a reason for hiding this comment

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

Hey @mobley-trent ! Thanks for working on this, it's a great PR. Would you please add some tests from TensorLy for the TTTensor class in ivy_tests/test_ivy/test_misc like we have added for other Factorized Classes?

@ivy-leaves ivy-leaves added Ivy Functional API Ivy API Experimental Run CI for testing API experimental/New feature or request labels Sep 7, 2023
@mobley-trent
Copy link
Contributor Author

I have no idea what caused the changes to the docs/demos. I think there was a force push or maybe something to do with the linting bot @NripeshN @hello-fri-end

@NripeshN
Copy link
Contributor

NripeshN commented Sep 11, 2023

I have no idea what caused the changes to the docs/demos. I think there was a force push or maybe something to do with the linting bot @NripeshN @hello-fri-end

Hi,
The linting bot does not touch docs/demos. It only goes through the files in frontend and tests.
Could you please pin point the changes you're referring to?

docs/demos Outdated Show resolved Hide resolved
Copy link
Contributor

@hello-fri-end hello-fri-end left a comment

Choose a reason for hiding this comment

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

Hey @mobley-trent, thanks for making the changes. Just left a few minor comments - let's also make sure that all the relevant tests are passing on the CI. Happy to review again once you have made the changes. Thanks :)

rank = draw(helpers.ints(min_value=1, max_value=len(shape)))
dtype = draw(
helpers.get_dtypes("float", full=False).filter(
lambda x: x not in ["bfloat16", "float16"]
Copy link
Contributor

Choose a reason for hiding this comment

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

Are these data-types causing the tests to fail?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I think there is an internal error related to these dtypes. I remember Ved mentioning this in a sync sometime back.

Copy link
Contributor

Choose a reason for hiding this comment

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

I'm not aware of the internal error related to these dtypes but we shouldn't be adding this condition in the tests. It will automatically be fixed once the internal error is fixed. We shouldn't worry about this if this is the only reason why the testa are failing :)

Comment on lines 473 to 497
if full:
reconstructed_tensor = helpers.flatten_and_to_np(ret=ret_np, backend=backend_fw)
reconstructed_tensor_gt = helpers.flatten_and_to_np(
ret=ret_from_gt_np, backend=test_flags.ground_truth_backend
)
for x, x_gt in zip(reconstructed_tensor, reconstructed_tensor_gt):
assert np.prod(shape) == np.prod(x.shape)
assert np.prod(shape) == np.prod(x_gt.shape)

else:
weights = helpers.flatten_and_to_np(ret=ret_np[0], backend=backend_fw)
factors = helpers.flatten_and_to_np(ret=ret_np[1], backend=backend_fw)
weights_gt = helpers.flatten_and_to_np(
ret=ret_from_gt_np[0], backend=test_flags.ground_truth_backend
)
factors_gt = helpers.flatten_and_to_np(
ret=ret_from_gt_np[1], backend=test_flags.ground_truth_backend
)

for w, w_gt in zip(weights, weights_gt):
assert w.shape[-1] == rank
assert w_gt.shape[-1] == rank

for f, f_gt in zip(factors, factors_gt):
assert np.prod(f.shape) == np.prod(f_gt.shape)
Copy link
Contributor

Choose a reason for hiding this comment

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

This doesn't seem to be right. TTTensor only contains factors matrices and and doesn't contain weights :)

Comment on lines 102 to 105
# TODO: This test fails even for the native implementation
# rank = ivy.TTTensor.validate_tt_rank(tensor_shape, coef, rounding="floor")
# n_param = ivy.TTTensor._tt_n_param(tensor_shape, rank)
# np.testing.assert_(n_param >= n_param_tensor * coef)
Copy link
Contributor

Choose a reason for hiding this comment

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

I'm not sure if I follow this, If our implementation matches exactly with TensorLy, this should ideally pass as well. What's the error you're getting on running this?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'm getting an assertion error. This test fails for TensorLy as well, e.g:

import ivy
import numpy as np
import tensorly as tl

coef = 0.2

tensor_shape = tuple(np.random.randint(5, 10, size=4))
n_param_tensor = np.prod(tensor_shape)

# ivy
rank = ivy.TTTensor.validate_tt_rank(tensor_shape, coef, rounding="floor")
n_param = ivy.TTTensor._tt_n_param(tensor_shape, rank)
np.testing.assert_(n_param >= n_param_tensor * coef)

# tensorly
rank = tl.tt_tensor.validate_tt_rank(tensor_shape, coef, rounding="floor")
n_param = tl.tt_tensor._tt_n_param(tensor_shape, rank)
np.testing.assert_(n_param >= n_param_tensor * coef)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Only ceil mode is passing

rank = draw(helpers.ints(min_value=1, max_value=len(shape)))
dtype = draw(
helpers.get_dtypes("float", full=False).filter(
lambda x: x not in ["bfloat16", "float16"]
Copy link
Contributor

Choose a reason for hiding this comment

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

I'm not aware of the internal error related to these dtypes but we shouldn't be adding this condition in the tests. It will automatically be fixed once the internal error is fixed. We shouldn't worry about this if this is the only reason why the testa are failing :)

tensor_shape = tuple(ivy.random.randint(5, 10, shape=(4,)))
n_param_tensor = ivy.prod(tensor_shape)

# TODO: This test fails even for the native implementation
Copy link
Contributor

Choose a reason for hiding this comment

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

Let's add the tensorly issue link here so that it's easy to keep a track :)

Copy link
Contributor

@github-actions github-actions bot left a comment

Choose a reason for hiding this comment

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

PR Compliance Checks

Thank you for your Pull Request! We have run several checks on this pull request in order to make sure it's suitable for merging into this project. The results are listed in the following section.

Conventional Commit PR Title

In order to be considered for merging, the pull request title must match the specification in conventional commits. You can edit the title in order for this check to pass.
Most often, our PR titles are something like one of these:

  • docs: correct typo in README
  • feat: implement dark mode"
  • fix: correct remove button behavior

Linting Errors

  • Found type "null", must be one of "feat","fix","docs","style","refactor","perf","test","build","ci","chore","revert"
  • No subject found

@mobley-trent mobley-trent merged commit 1865ed3 into ivy-llc:main Sep 17, 2023
26 of 30 checks passed
iababio pushed a commit to iababio/ivy that referenced this pull request Sep 27, 2023
druvdub pushed a commit to druvdub/ivy that referenced this pull request Oct 14, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Ivy API Experimental Run CI for testing API experimental/New feature or request Ivy Functional API
Projects
None yet
Development

Successfully merging this pull request may close these issues.

TTTensor
5 participants