When loading a pretrained model's weights into a model placed on an accelerator (e.g. GPU), the choice of loading strategy strongly affects peak CPU memory usage. Three common strategies are:
'baseline': build the full model on CPU, then load the entire state_dict on CPU, copy parameters in-place, and finally move the model to GPU. During the copy, both the model parameters and the state_dict live on CPU simultaneously.'sequential': build the model directly on GPU (no CPU allocation for parameters), load the full state_dict on CPU, then copy each parameter to GPU one at a time, freeing it from CPU immediately after the copy.'meta_sequential': build the model on a 'meta' device (no real allocation), allocate empty buffers on GPU, then for each parameter load that single tensor from disk into CPU, copy it to GPU, and free it before moving to the next parameter.Implement peak_cpu_memory(param_sizes, strategy) that simulates the loading procedure and returns the peak CPU memory (in the same units as the inputs) reached during the entire process. param_sizes is a list of positive numbers giving the size of each parameter tensor, processed in the given order. The valid strategies are 'baseline', 'sequential', and 'meta_sequential'. For invalid strategy strings, raise a ValueError.
Return a single number (int or float).