fastvideo.v1.models.utils#

Utils for model executor.

Module Contents#

Functions#

auto_attributes

Decorator that automatically adds all initialization arguments as object attributes.

extract_layer_index

Extract the layer index from the module name. Examples:

modulate

modulate by shift and scale

set_random_seed

set_weight_attrs

Set attributes on a weight tensor.

API#

fastvideo.v1.models.utils.auto_attributes(init_func)[source]#

Decorator that automatically adds all initialization arguments as object attributes.

.. rubric:: Example

@auto_attributes def init(self, a=1, b=2): pass

This will automatically set:#

- self.a = 1 and self.b = 2#

- self.config.a = 1 and self.config.b = 2#

fastvideo.v1.models.utils.extract_layer_index(layer_name: str) int[source]#

Extract the layer index from the module name. Examples:

  • “encoder.layers.0” -> 0

  • “encoder.layers.1.self_attn” -> 1

  • “2.self_attn” -> 2

  • “model.encoder.layers.0.sub.1” -> ValueError

fastvideo.v1.models.utils.modulate(x: torch.Tensor, shift: Optional[torch.Tensor] = None, scale: Optional[torch.Tensor] = None) torch.Tensor[source]#

modulate by shift and scale

Parameters:
Returns:

the output tensor after modulate.

Return type:

torch.Tensor

fastvideo.v1.models.utils.set_random_seed(seed: int) None[source]#
fastvideo.v1.models.utils.set_weight_attrs(weight: torch.Tensor, weight_attrs: Optional[Dict[str, Any]])[source]#

Set attributes on a weight tensor.

This method is used to set attributes on a weight tensor. This method will not overwrite existing attributes.

Parameters:
  • weight – The weight tensor.

  • weight_attrs – A dictionary of attributes to set on the weight tensor.