fastvideo.v1.models.loader.weight_utils
#
Utilities for downloading and initializing model weights.
Module Contents#
Classes#
Functions#
Default weight loader. |
|
Download hf safetensors index file from Hugging Face Hub. |
|
Download model weights from Hugging Face Hub. |
|
automatically activates hf_transfer |
|
Exclude files that are not needed for inference. |
|
Remap the name of FP8 k/v_scale parameters. |
|
Iterate over the weights in the model bin/pt files. |
|
Iterate over the weights in the model safetensor files. |
Data#
API#
- class fastvideo.v1.models.loader.weight_utils.DisabledTqdm(*args, **kwargs)[source]#
Bases:
tqdm.auto.tqdm
Initialization
- fastvideo.v1.models.loader.weight_utils.default_weight_loader(param: torch.Tensor, loaded_weight: torch.Tensor) None [source]#
Default weight loader.
- fastvideo.v1.models.loader.weight_utils.download_safetensors_index_file_from_hf(model_name_or_path: str, index_file: str, cache_dir: Optional[str], revision: Optional[str] = None) None [source]#
Download hf safetensors index file from Hugging Face Hub.
- fastvideo.v1.models.loader.weight_utils.download_weights_from_hf(model_name_or_path: str, cache_dir: Optional[str], allow_patterns: List[str], revision: Optional[str] = None, ignore_patterns: Optional[Union[str, List[str]]] = None) str [source]#
Download model weights from Hugging Face Hub.
- Parameters:
model_name_or_path (str) β The model name or path.
cache_dir (Optional[str]) β The cache directory to store the model weights. If None, will use HF defaults.
allow_patterns (List[str]) β The allowed patterns for the weight files. Files matched by any of the patterns will be downloaded.
revision (Optional[str]) β The revision of the model.
ignore_patterns (Optional[Union[str, List[str]]]) β The patterns to filter out the weight files. Files matched by any of the patterns will be ignored.
- Returns:
The path to the downloaded model weights.
- Return type:
- fastvideo.v1.models.loader.weight_utils.enable_hf_transfer() None [source]#
automatically activates hf_transfer
- fastvideo.v1.models.loader.weight_utils.filter_duplicate_safetensors_files(hf_weights_files: List[str], hf_folder: str, index_file: str) List[str] [source]#
- fastvideo.v1.models.loader.weight_utils.filter_files_not_needed_for_inference(hf_weights_files: List[str]) List[str] [source]#
Exclude files that are not needed for inference.
See https://github.com/huggingface/transformers/blob/v4.34.0/src/transformers/trainer.py#L227-L233
- fastvideo.v1.models.loader.weight_utils.get_lock(model_name_or_path: Union[str, pathlib.Path], cache_dir: Optional[str] = None)[source]#
- fastvideo.v1.models.loader.weight_utils.maybe_remap_kv_scale_name(name: str, params_dict: dict) Optional[str] [source]#
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:
- Returns:
The remapped parameter name if successful, or the original name if no remapping is needed. None: If the remapped name is not found in params_dict.
- Return type:
- fastvideo.v1.models.loader.weight_utils.pt_weights_iterator(hf_weights_files: List[str]) Generator[Tuple[str, torch.Tensor], None, None] [source]#
Iterate over the weights in the model bin/pt files.