fastvideo.v1.models.loader.weight_utils#

Utilities for downloading and initializing model weights.

Module Contents#

Classes#

Functions#

default_weight_loader

Default weight loader.

download_safetensors_index_file_from_hf

Download hf safetensors index file from Hugging Face Hub.

download_weights_from_hf

Download model weights from Hugging Face Hub.

enable_hf_transfer

automatically activates hf_transfer

filter_duplicate_safetensors_files

filter_files_not_needed_for_inference

Exclude files that are not needed for inference.

get_lock

maybe_remap_kv_scale_name

Remap the name of FP8 k/v_scale parameters.

pt_weights_iterator

Iterate over the weights in the model bin/pt files.

safetensors_weights_iterator

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.

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.

  • revision (Optional[str]) – The revision of the model.

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:

str

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.logger[source]#

β€˜init_logger(…)’

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:
  • name (str) – The original loaded checkpoint parameter name.

  • params_dict (dict) – Dictionary containing the model’s named 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:

str

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.

fastvideo.v1.models.loader.weight_utils.safetensors_weights_iterator(hf_weights_files: List[str]) Generator[Tuple[str, torch.Tensor], None, None][source]#

Iterate over the weights in the model safetensor files.

fastvideo.v1.models.loader.weight_utils.temp_dir[source]#

β€˜gettempdir(…)’