pytorch / pytorch/tutorials

[BUG] - parametrizations tutorial no longer works in torch 2.0 (deprecated torch.solve API)

Open
#2,288 3 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

bug
Dominant language
Python
Stars
9.3k
Forks
4.4k
Avg merge
1d 21h
Merged PRs (30d)
4

Description

Add Link

https://pytorch.org/tutorials/intermediate/parametrizations.html

Describe the bug

This fails

class CayleyMap(nn.Module):
    def __init__(self, n):
        super().__init__()
        self.register_buffer("Id", torch.eye(n))

    def forward(self, X):
        # (I + X)(I - X)^{-1}
        return torch.solve(self.Id + X, self.Id - X).solution #### Broken
        #return torch.linalg.solve(self.Id + X, self.Id - X)

layer = nn.Linear(3, 3)
parametrize.register_parametrization(layer, "weight", Skew())
parametrize.register_parametrization(layer, "weight", CayleyMap(3))
X = layer.weight
print(torch.dist(X.T @ X, torch.eye(3)))  # X is orthogonal

The offending line should be replaced by

return torch.linalg.solve(self.Id + X, self.Id - X)
Describe your environment

colab, CPU mode, torch 2.0.0+cu118

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Open the parametrizations tutorial at the linked URL and find the CayleyMap example. Run the snippet with the reported PyTorch environment, update the deprecated torch.solve call as indicated, and rerun it to confirm the orthogonality check succeeds.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
documentation, machine-learning
Issue type
Bug
Difficulty
1/5
Estimated time
Under an hour
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
55/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.