Giter Site home page Giter Site logo

State sharing between graphs about dgl HOT 9 CLOSED

dmlc avatar dmlc commented on August 15, 2024
State sharing between graphs

from dgl.

Comments (9)

zzhang-cn avatar zzhang-cn commented on August 15, 2024

I am not familiar enough with this problem, but like the way networkx follows Python's style so that users, if they are confused, have some "prior" suspect. For the "independent shallow" that networkx provides, does it raises issue with our current models, or does it work okay and we just need to warn the user about the potential problems?

And, the worst is to ask users to do deep copy and maintain the states themselves. Correct?

from dgl.

GaiYu0 avatar GaiYu0 commented on August 15, 2024

After an "independent shallow" copy, a graph and its duplicate will share representations. However, if we update the representations of either the graph or its duplicate with current API, they will not share representations any more.

# Assume that g.nodes[n]['x'] == 0 for every node n
h = g.copy()
h.register_message_func(lambda src, trg, _: None)
h.register_update_func(lambda node_reprs, edge_reprs: 1)
h.update_all()

Now, g.nodes[n]['x'] == 0 and h.nodes[n]['x'] == 1 for every node n. To sync between g and h, we have to write

for n, d in g.nodes.items():
  d['x'] = h.nodes[n]['x']

In this case sync is not tricky. However, sync between graphs may become a burden for user, e.g. line 153 - 156 and line 164 - 167 in line_graph/gnn.py. Syncing by iterating through all nodes is not very efficient either. So the question is can we help users to sync between graphs automatically?

I hope this makes more sense.

from dgl.

zzhang-cn avatar zzhang-cn commented on August 15, 2024

I played with networkx's copy a little and understand what it is now:
image
For the time being, I'd suggest simply add a sync_state(g_src, g_tgt, name="all") to make it easy for the user, and deal with performance issue later.

from dgl.

GaiYu0 avatar GaiYu0 commented on August 15, 2024

I would suggest the following (implemented by overriding networkx methods):

# Assume that isinstance(g, DGLGraph), g.nodes[0]['h'] == 12, g.edges[0, 1]['h'] == 12
g_c = g.copy(share=['h'])
g_c.nodes[0]['h'] = 13 # Now g.nodes[0]['h'] == 13

g_c = DGLGraph()
g_c.add_nodes_from(g.nodes, share=['x'])
g_c.nodes[0]['h'] = 13 # Now g.nodes[0]['h'] == 13

g_c = DGLGraph()
g_c.add_edges_from(g.edges, share=['x'])
g_c.edges[0, 1]['h'] = 13 # Now g.edges[0, 1]['h'] == 13

This interface is less flexible compared to sync_state because states are always synced after copy, add_nodes_from and add_edges_from. However, it provides us with more information about which attributes will be synced and thus may benefit optimization.

from dgl.

zzhang-cn avatar zzhang-cn commented on August 15, 2024

from dgl.

jermainewang avatar jermainewang commented on August 15, 2024

from dgl.

GaiYu0 avatar GaiYu0 commented on August 15, 2024

Does the example need to be runnable?

from dgl.

jermainewang avatar jermainewang commented on August 15, 2024

from dgl.

jermainewang avatar jermainewang commented on August 15, 2024

Current solution for state sharing is using FrameRef (PR #39 ). More examples are coming on this syntax.

from dgl.

Related Issues (20)

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.