Git Product home page Git Product logo

torch-ppr's Introduction

Hi there ๐Ÿ‘‹

torch-ppr's People

Contributors

cthoyt avatar filco306 avatar mberr avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

torch-ppr's Issues

RuntimeError torch.sparse.addmm different torch tensor shape

Dear torch-ppr

I installed torch-ppr on my Mac with python 3.9 and run the example code

>>> import torch
>>> edge_index = torch.as_tensor(data=[(0, 1), (1, 2), (1, 3), (2, 4)]).t()
>>> from torch_ppr import page_rank
>>> page_rank(edge_index)

I got a runtimeerror as

x = torch.sparse.addmm(input=x0, sparse=adj, dense=x, beta=alpha, alpha=beta)
RuntimeError: mat1 and mat2 shapes cannot be multiplied (2x4 and 2x1)

I printed the shape of x0, adj and x

torch.Size([2, 1])
torch.Size([2, 4])
torch.Size([2, 1])

I believe that the shape of adj should be 2x2 or I might be wrong.
I find the define process of adj.

# convert to sparse matrix, shape: (n, n)
adj = edge_index_to_sparse_matrix(edge_index=edge_index, num_nodes=num_nodes)
adj = adj + adj.t()

The adj is symmect.

I wonder how to fix the runtimeError or any suggestions?
Thanks in advanced
meatball1982
12-May-2022 09:54:50

Incorporating edge weights

Hello,

Thank you for this great repository; it is a great, handy package that performs very well! I was wondering however; is it possible to incorporate edge weights into the personalized pagerank method?

Best
Filip

Formulate page-rank as a torch.nn Layer

Thank you for this repo!

The reason to request a 'layer' fomulation is to convert the function page_rank to an onnx graph with torch.onnx (only accepts models).

Once I have the onnx model, I can compile it different hardware (other than cuda).

Maybe need just the forward pass, no need for a backward pass although I think the compute will be differentiable.

Thanks.

`torch.sparse.mm` breaking API changes

Suddenly, everything stopped working ๐Ÿ˜ฑ presumably because of the changes to torch.sparse.
Particularly, I am on PyTorch 1.10, master branch of PyKEEN and torch-ppr 0.0.5.

Problem 1: the allclose() check does not pass now:

if not torch.allclose(x_sum, torch.ones_like(x_sum)):
raise ValueError(f"The entries do not sum to 1. {x_sum[x_sum != 0]}")

MWE:

import torch
from torch_ppr import page_rank

from pykeen.datasets import FB15k237

dataset = FB15k237(create_inverse_triples=False)
edges = dataset.training.mapped_triples[:, [0, 2]].t()
pr = page_rank(edge_index=torch.cat([edges, edges.flip(0)], dim=-1), num_nodes=dataset.num_entities)

>> ValueError: Invalid column sum: tensor([1.0000, 1.0000, 1.0000,  ..., 1.0000, 1.0000, 1.0000]). expected 1.0

Looking into the debugger:

  • adj_sum does sum up to the number of nodes
  • the default tolerance fails the check, but if I reduce rtol=1e-4 or atol=1e-4 - the check passes

Problem 2: the signature of torch.sparse.addmm has changed from the one used in power_iteration so the API call fails with the unknown kwarg error.

x = torch.sparse.addmm(input=x0, sparse=adj, dense=x, beta=alpha, alpha=beta)

In fact, I can't find where those kwargs input, sparse, dense come from because the current signature has less readable mat, mat1, mat2. I traced to the very Torch 1.3.0 and still can't find where those originated from. Where does this signature come from? ๐Ÿ˜…

My test env

torch                 1.10.0
torch-ppr             0.0.5

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.