fn
copy_parameters_and_buffers
→Nonecopy_parameters_and_buffers(source: Module, dest: Module)Copy all parameter / buffer values from source into dest.
Both modules must expose the same set of parameter and buffer names;
a KeyError is raised if a name found on source is missing on
dest. Tensor data is copied in-place via Tensor.detach() and
storage assignment so that dest's autograd graph (if any) is not
disturbed by the copy.
Parameters
Notes
Shape and dtype of corresponding entries must match. Devices may
differ — the source values are routed through .to(device) to
land on dest's device first.
Examples
>>> import lucid
>>> import lucid.nn as nn
>>> from lucid.nn.utils import copy_parameters_and_buffers
>>> src = nn.BatchNorm1d(4) # parameters and running-stat buffers
>>> dst = nn.BatchNorm1d(4)
>>> _ = src(lucid.randn(8, 4)) # a training step moves src's running stats
>>> copy_parameters_and_buffers(src, dst) # dst now mirrors src's weights + buffers
>>> bool((dst.running_mean == src.running_mean).all())
True