Is there a handy way to dump the running_stats for a pytorch model?
I'm writing a C version of the pytorch model to run it on my special hardware.
Everything looks ok so far, except the running_mean and running_var in every batchnorm layer.

We have a python code to dump all named_parameters, but nothing to do for the running_stats, although we need to use it in the forwarding computation.

So is there a way to dump it with sort of built-in features?
I searched pytorch doc, no help on my task.
Otherwise I might need to write a regexp code to recognize and dump them.

Thanks a lot.
/Patrick

for name, param in model.named_parameters():
    # here can dump weight and bias, but not running_stats
    names.append(name)
    shapes.append(list(param.data.numpy().shape))
    values.append(param.data.numpy().flatten().tolist())


running_mean and others are registered_buffers in PyTorch. You can save (as you say dump) them with torch.nn.Module's state_dict:

torch.save(model.state_dict(), PATH) 


You can iterate over named buffers and save each of them however you like similarly to parameters:

for name, buffer in model.named_buffers():
    # do your thing with them

