text_encoding
¶
Prompt encoding stages for diffusion pipelines.
This module contains implementations of prompt encoding stages for diffusion pipelines.
Classes¶
fastvideo.pipelines.stages.text_encoding.TextEncodingStage
¶
Bases: PipelineStage
Stage for encoding text prompts into embeddings for diffusion models.
This stage handles the encoding of text prompts into the embedding space expected by the diffusion model.
Initialize the prompt encoding stage.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
enable_logging
|
Whether to enable logging for this stage. |
required | |
is_secondary
|
Whether this is a secondary text encoder. |
required |
Source code in fastvideo/pipelines/stages/text_encoding.py
Functions¶
fastvideo.pipelines.stages.text_encoding.TextEncodingStage.encode_text
¶
encode_text(text: str | list[str], fastvideo_args: FastVideoArgs, encoder_index: int | list[int] | None = None, return_attention_mask: bool = False, return_type: str = 'list', device: device | str | None = None, dtype: dtype | None = None, max_length: int | None = None, truncation: bool | None = None, padding: bool | str | None = None)
Encode plain text using selected text encoder(s) and return embeddings.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
text
|
str | list[str]
|
A single string or a list of strings to encode. |
required |
fastvideo_args
|
FastVideoArgs
|
The inference arguments providing pipeline config, including tokenizer and encoder settings, preprocess and postprocess functions. |
required |
encoder_index
|
int | list[int] | None
|
Encoder selector by index. Accepts an int or list of ints. |
None
|
return_attention_mask
|
bool
|
If True, also return attention masks for each selected encoder. |
False
|
return_type
|
str
|
"list" (default) returns a list aligned with selection; "dict" returns a dict keyed by encoder index as a string; "stack" stacks along a new first dimension (requires matching shapes). |
'list'
|
device
|
device | str | None
|
Optional device override for inputs; defaults to local torch device. |
None
|
dtype
|
dtype | None
|
Optional dtype to cast returned embeddings to. |
None
|
max_length
|
int | None
|
Optional per-call tokenizer override. |
None
|
truncation
|
bool | None
|
Optional per-call tokenizer override. |
None
|
padding
|
bool | str | None
|
Optional per-call tokenizer override. |
None
|
Returns:
| Type | Description |
|---|---|
|
Depending on return_type and return_attention_mask: |
|
|
|
|
|
|
Source code in fastvideo/pipelines/stages/text_encoding.py
113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 | |
fastvideo.pipelines.stages.text_encoding.TextEncodingStage.forward
¶
forward(batch: ForwardBatch, fastvideo_args: FastVideoArgs) -> ForwardBatch
Encode the prompt into text encoder hidden states.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
batch
|
ForwardBatch
|
The current batch information. |
required |
fastvideo_args
|
FastVideoArgs
|
The inference arguments. |
required |
Returns:
| Type | Description |
|---|---|
ForwardBatch
|
The batch with encoded prompt embeddings. |
Source code in fastvideo/pipelines/stages/text_encoding.py
fastvideo.pipelines.stages.text_encoding.TextEncodingStage.verify_input
¶
verify_input(batch: ForwardBatch, fastvideo_args: FastVideoArgs) -> VerificationResult
Verify text encoding stage inputs.
Source code in fastvideo/pipelines/stages/text_encoding.py
fastvideo.pipelines.stages.text_encoding.TextEncodingStage.verify_output
¶
verify_output(batch: ForwardBatch, fastvideo_args: FastVideoArgs) -> VerificationResult
Verify text encoding stage outputs.