fn
vector_to_parameters
→Nonevector_to_parameters(vec: Tensor, parameters: Iterable[Parameter])Copy a flat 1-D tensor back into the supplied parameters in place.
Inverse of parameters_to_vector. vec is sliced according
to the size of each parameter (in iteration order) and the slices are
written into the parameters' storage. Typically called by line-search
routines and second-order optimisers that operate on the concatenated
vector and need to push the result back into the model.
Parameters
vecTensor1-D source tensor. Length must equal
for the supplied parameter iterator; mismatches raise
ValueError.parametersiterable of ParameterDestination parameters. Each parameter's storage is overwritten
with the matching slice of
vec, reshaped to the parameter's
own shape.Returns
NoneThe copy is performed in place; no value is returned.
Notes
Conceptually the operation splits vec at the parameter
boundaries and reshapes each chunk:
Autograd graph state is left intact — the assignment touches storage directly, not the parameter's identity, so existing references in optimiser state remain valid.
Examples
>>> from lucid.nn.utils import parameters_to_vector, vector_to_parameters
>>> v = parameters_to_vector(model.parameters())
>>> v = v + lr * search_direction
>>> vector_to_parameters(v, model.parameters())