d6e8ea4250b2a48262bae0276047371ea2dcccf1,onmt/utils/loss.py,,shards,#Any#Any#Any#,246

Before Change


            yield dict(zip(keys, shard_tensors))

        // Assumed backprop"d
        variables = ((state[k], v.grad.data) for k, v in non_none.items()
                     if isinstance(v, Variable) and v.grad is not None)
        inputs, grads = zip(*variables)
        torch.autograd.backward(inputs, grads)

After Change


        // want a sequence of dictionaries of tensors.
        // First, unzip the dictionary into a sequence of keys and a
        // sequence of tensor-like sequences.
        keys, values = zip(*((k, [v_chunk for v_chunk in v_split])
                             for k, (_, v_split) in non_none.items()))

        // Now, yield a dictionary for each shard. The keys are always
        // the same. values is a sequence of length //keys where each
        // element is a sequence of length //shards. We want to iterate
        // over the shards, not over the keys: therefore, the values need
        // to be re-zipped by shard and then each shard can be paired
        // with the keys.
        for shard_tensors in zip(*values):
            yield dict(zip(keys, shard_tensors))

        // Assumed backprop"d
        variables = []
        for k, (v, v_split) in non_none.items():
            if isinstance(v, torch.Tensor) and state[k].requires_grad:
                variables.extend(zip(torch.split(state[k], shard_size),
                                     [v_chunk.grad for v_chunk in v_split]))
        inputs, grads = zip(*variables)
        torch.autograd.backward(inputs, grads)
Italian Trulli
In pattern: SUPERPATTERN

Frequency: 3

Non-data size: 9

Instances


Project Name: OpenNMT/OpenNMT-py
Commit Name: d6e8ea4250b2a48262bae0276047371ea2dcccf1
Time: 2018-06-15
Author: vince62s@yahoo.com
File Name: onmt/utils/loss.py
Class Name:
Method Name: shards


Project Name: biolab/orange3
Commit Name: 8d4d199c35f5163ed21ae705a16ce3c8548d60c6
Time: 2012-11-28
Author: janez.demsar@fri.uni-lj.si
File Name: Orange/data/io.py
Class Name: BasketReader
Method Name: prescan_file


Project Name: OpenNMT/OpenNMT-py
Commit Name: ab89e458bdec863f2dc2f7232ffd38d49758b31a
Time: 2018-06-08
Author: srush@seas.harvard.edu
File Name: onmt/Loss.py
Class Name:
Method Name: shards