db9d883aecb6cdfba6c6bbc76b83d85397fef28d,maml_rl/utils/torch_utils.py,,weighted_mean,#Any#Any#Any#,4
Before Change
if isinstance(dim, int):
dim = (dim,)
numerator = tensor * weights
denominator = weights
for dimension in dim:
numerator = torch.sum(numerator, dimension, keepdim=True)
denominator = torch.sum(denominator, dimension, keepdim=True)
return numerator / denominator
def detach_distribution(pi):
if isinstance(pi, Categorical):
distribution = Categorical(logits=pi.logits.detach())
After Change
out = torch.mean(tensor)
if dim is None:
out = torch.sum(tensor * weights)
out.div_(torch.sum(weights))
else:
mean_dim = torch.sum(tensor * weights, dim=dim)
mean_dim.div_(torch.sum(weights, dim=dim))
out = torch.mean(mean_dim)
In pattern: SUPERPATTERN
Frequency: 3
Non-data size: 5
Instances Project Name: tristandeleu/pytorch-maml-rl
Commit Name: db9d883aecb6cdfba6c6bbc76b83d85397fef28d
Time: 2018-10-23
Author: tristan.deleu@gmail.com
File Name: maml_rl/utils/torch_utils.py
Class Name:
Method Name: weighted_mean
Project Name: pytorch/fairseq
Commit Name: 8ce2c35d8e2dfb2b6dd220058710f81df5eb5729
Time: 2019-05-24
Author: yqw@fb.com
File Name: scripts/average_checkpoints.py
Class Name:
Method Name: average_checkpoints