fn

vector_to_parameters

None
vector_to_parameters(vec: Tensor, parameters: Iterable[Parameter])
source

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

vecTensor
1-D source tensor. Length must equal knumel(pk)\sum_k \text{numel}(p_k) for the supplied parameter iterator; mismatches raise ValueError.
parametersiterable of Parameter
Destination parameters. Each parameter's storage is overwritten with the matching slice of vec, reshaped to the parameter's own shape.

Returns

None

The copy is performed in place; no value is returned.

Notes

Conceptually the operation splits vec at the parameter boundaries and reshapes each chunk:

pk    reshape(v[sk1 ⁣: ⁣sk],shape(pk)),sk=jknj.p_k \;\leftarrow\; \operatorname{reshape}\bigl( v[s_{k-1}\!:\!s_k],\, \text{shape}(p_k)\bigr), \qquad s_k = \sum_{j \leq k} n_j.

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())