fastvideo.v1.models.utils
#
Utils for model executor.
Module Contents#
Functions#
Decorator that automatically adds all initialization arguments as object attributes. |
|
Extract the layer index from the module name. Examples: |
|
modulate by shift and scale |
|
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:
x (torch.Tensor) – input tensor.
shift (torch.Tensor, optional) – shift tensor. Defaults to None.
scale (torch.Tensor, optional) – scale tensor. Defaults to None.
- Returns:
the output tensor after modulate.
- Return type:
- 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.