fastvideo.v1.models.loader.weight_utils#

Utilities for downloading and initializing model weights.

Module Contents#

Classes#

Functions#

default_weight_loader

Default weight loader.

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.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(…)’