weight_utils
¶
Utilities for downloading and initializing model weights.
Functions:¶
fastvideo.models.loader.weight_utils.default_weight_loader
¶
Default weight loader.
Source code in fastvideo/models/loader/weight_utils.py
fastvideo.models.loader.weight_utils.enable_hf_transfer
¶
automatically activates hf_transfer
Source code in fastvideo/models/loader/weight_utils.py
fastvideo.models.loader.weight_utils.filter_files_not_needed_for_inference
¶
Exclude files that are not needed for inference.
See https://github.com/huggingface/transformers/blob/v4.34.0/src/transformers/trainer.py#L227-L233
Source code in fastvideo/models/loader/weight_utils.py
fastvideo.models.loader.weight_utils.maybe_remap_kv_scale_name
¶
Remap the name of FP8 k/v_scale parameters.
This function handles the remapping of FP8 k/v_scale parameter names. It detects if the given name ends with a suffix and attempts to remap it to the expected name format in the model. If the remapped name is not found in the params_dict, a warning is printed and None is returned.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
str
|
The original loaded checkpoint parameter name. |
required |
params_dict
|
dict
|
Dictionary containing the model's named parameters. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
str |
str | None
|
The remapped parameter name if successful, or the original name if no remapping is needed. |
None |
str | None
|
If the remapped name is not found in params_dict. |
Source code in fastvideo/models/loader/weight_utils.py
fastvideo.models.loader.weight_utils.pt_weights_iterator
¶
pt_weights_iterator(hf_weights_files: list[str], to_cpu: bool = False, broadcast: bool = True) -> Generator[tuple[str, Tensor], None, None]
Iterate over the weights in the model bin/pt files.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
hf_weights_files
|
list[str]
|
List of bin/pt files to load. |
required |
to_cpu
|
bool
|
Whether to load the weights to CPU. |
False
|
broadcast
|
bool
|
Accepted for API symmetry. PT weights are loaded through torch.load and do not use the safetensors broadcast path. |
True
|
Source code in fastvideo/models/loader/weight_utils.py
fastvideo.models.loader.weight_utils.resolve_safetensors_files
¶
Discover safetensors files in a model directory.
Source code in fastvideo/models/loader/weight_utils.py
fastvideo.models.loader.weight_utils.safetensors_weights_iterator
¶
safetensors_weights_iterator(hf_weights_files: list[str], to_cpu: bool = False, broadcast: bool = True, async_broadcast: bool = False) -> Generator[tuple[str, Tensor], None, None]
Iterate over the weights in the model safetensor files. Args: hf_weights_files: List of safetensor files to load. to_cpu: Whether to load the weights to CPU. If False, will load to the GPU device bound to the current process. broadcast: Whether local rank 0 should read GPU weights and broadcast them to the other local ranks. async_broadcast: Whether to overlap loading from disk and broadcasting to other ranks. If True, must iterate over all the weights before use. Only used when broadcast is True and to_cpu is False.