fn
parameters_to_vector
→Tensorparameters_to_vector(parameters: Iterable[Parameter])Flatten an iterable of parameters into a single 1-D Tensor.
Every parameter is detached, reshaped to 1-D, and concatenated in iteration order. Useful when an algorithm needs to view the whole parameter set as one vector — most commonly second-order optimisers (L-BFGS, conjugate-gradient, trust-region methods), hyper-gradient solvers, and natural-gradient pre-conditioners.
Parameters
parametersiterable of ParameterParameters to flatten. Each must be a
lucid._tensor.tensor.Tensor
(or subclass). All entries must share device and dtype; a mismatch
raises ValueError.Returns
Tensor1-D tensor of length on the same
device / dtype as the first parameter. requires_grad is
False — the result is a detached snapshot, not a graph node.
Notes
Given parameters with sizes , the returned vector is
The inverse operation is vector_to_parameters, which copies a
1-D tensor of the same length back into the original parameter shapes.
Examples
>>> import lucid
>>> from lucid.nn.utils import parameters_to_vector
>>> vec = parameters_to_vector(model.parameters())
>>> vec.shape
(n_params,)