utils
¶
Utils for model executor.
Functions¶
fastvideo.models.utils.auto_attributes
¶
Decorator that automatically adds all initialization arguments as object attributes.
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¶
Source code in fastvideo/models/utils.py
fastvideo.models.utils.extract_layer_index
¶
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
Source code in fastvideo/models/utils.py
fastvideo.models.utils.modulate
¶
modulate by shift and scale
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
x
|
Tensor
|
input tensor. |
required |
shift
|
Tensor
|
shift tensor. Defaults to None. |
None
|
scale
|
Tensor
|
scale tensor. Defaults to None. |
None
|
Returns:
| Type | Description |
|---|---|
Tensor
|
torch.Tensor: the output tensor after modulate. |
Source code in fastvideo/models/utils.py
fastvideo.models.utils.pred_noise_to_pred_video
¶
pred_noise_to_pred_video(pred_noise: Tensor, noise_input_latent: Tensor, timestep: Tensor, scheduler: Any) -> Tensor
Convert predicted noise to clean latent.
pred_noise: the predicted noise with shape [B, C, H, W] where B is batch_size or batch_size * num_frames noise_input_latent: the noisy latent with shape [B, C, H, W], timestep: the timestep with shape [1] or [bs * num_frames] or [bs, num_frames] scheduler: the scheduler
Returns:
| Type | Description |
|---|---|
Tensor
|
the predicted video with shape [B, C, H, W] |
Source code in fastvideo/models/utils.py
fastvideo.models.utils.set_weight_attrs
¶
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:
| Name | Type | Description | Default |
|---|---|---|---|
weight
|
Tensor
|
The weight tensor. |
required |
weight_attrs
|
dict[str, Any] | None
|
A dictionary of attributes to set on the weight tensor. |
required |