Coder Social home page Coder Social logo

Comments (3)

ShichangZh avatar ShichangZh commented on June 12, 2024

We did nothing fancy but using a timer to measure the model inference time. We mimic an online setting as in Figure 2 to infer one node at a time. We repeat the procedure 10 times to reduce the variance from randomly chosen nodes. The timing function we used is the following.
https://pytorch.org/docs/stable/benchmark_utils.html

from graphless-neural-networks.

ShichangZh avatar ShichangZh commented on June 12, 2024

Below are the functions I wrote for time measurement. Note that the results could be different from our paper as they depend on your hardware.

def sage_inference(model, feats, dataloader):
    for step, (input_nodes, output_nodes, blocks) in enumerate(dataloader):
        model(blocks, feats[input_nodes])

def sage_measure(conf, model_name, L, prune_budget=0.5, fan_out=None):
    conf = copy.copy(conf)
    
    conf['model_name'] = model_name
    if model_name == 'SAGE':
        get_model = lambda conf: Model(conf).encoder
    elif model_name == 'SAGEQuantize':
        get_model = lambda conf: torch.quantization.quantize_dynamic(Model(conf).encoder)
    elif model_name == 'SAGEPrune':
        conf['hidden_dim'] = int(conf['hidden_dim'] * prune_budget)
        get_model = lambda conf: Model(conf).encoder
    gnn_dur = []
    for l in range(1, L+1):
        conf['num_layers'] = l
        set_seed(0)
        model = get_model(conf)
        sampler = dgl.dataloading.MultiLayerNeighborSampler([fan_out] * model.num_layers)
        model.eval()
        with torch.no_grad():
            dur = []
            for exp in range(num_exp):
                set_seed(exp)
                idx = torch.randperm(g.num_nodes())[0]
                dataloader = dgl.dataloading.NodeDataLoader(g, idx, sampler, batch_size=batch_size, shuffle=False, drop_last=False)
                t0 = benchmark.Timer(
                    stmt='sage_inference(model, feats, dataloader)',
                    setup='from __main__ import sage_inference',
                    globals={'model': model, 'feats': feats, 'dataloader': dataloader})
                measurement = t0.blocked_autorange(min_run_time=0.2)
                dur += [measurement.median * 1000]
            gnn_dur += [np.mean(dur)]
    return gnn_dur

from graphless-neural-networks.

Angazenn avatar Angazenn commented on June 12, 2024

Thx for your quick reply!

from graphless-neural-networks.

Related Issues (8)

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.