Download dflow/types.py from data-archetype/dflow_2b: direct link, hf CLI and curl.
- Browser
- Download file 1.96 kB
-
https://huggingface.co/data-archetype/dflow_2b/resolve/main/dflow/types.py
- Command line
-
hf download hf://data-archetype/dflow_2b/dflow/types.py
-
curl -L -o types.py https://huggingface.co/data-archetype/dflow_2b/resolve/main/dflow/types.py
1.96 kB
| """Types shared between the text path, the denoiser and the sampler. | |
| These are the contracts between modules: the text path produces | |
| ``TextConditioning``; the denoiser consumes it and runs one of the | |
| ``DFlowPath`` routings per forward. | |
| """ | |
| from __future__ import annotations | |
| from dataclasses import dataclass | |
| from enum import StrEnum | |
| from typing import TYPE_CHECKING | |
| if TYPE_CHECKING: | |
| from torch import Tensor | |
| # Learned suffix tokens appended to every prompt's text tokens. | |
| SUFFIX_TOKEN_COUNT = 3 | |
| class DFlowPath(StrEnum): | |
| """Which trained routing of the 18 middle layers a forward runs. | |
| FULL: every token through all 30 image layers (the main prediction). | |
| PATH_DROP: the middle is skipped for every token (the weak pass of | |
| path-drop guidance). | |
| THREE_QUARTER: one image token per 2x2 group (and every text token) goes | |
| through the middle; the rest skip it. | |
| """ | |
| FULL = "full" | |
| PATH_DROP = "path_drop" | |
| THREE_QUARTER = "three_quarter" | |
| class TextConditioning: | |
| """Text tokens for a prompt batch, ready for the denoiser's text refiner. | |
| All prompts in a batch have the same token count ``L`` (the dense | |
| attention path has no padding); batches of different lengths run as | |
| separate forwards. | |
| Attributes: | |
| tokens: ``[B, L, 2304]`` float32: the summed projected encoder taps | |
| followed by the learned suffix tokens (or the learned | |
| unconditional token and the suffix for an empty prompt). | |
| key_bias: ``[B, L]`` float32 additive attention-logit bias on each | |
| text token's key (prompt emphasis with weight > 0), or None when no | |
| token is weighted. | |
| value_scale: ``[B, L]`` float32 multiplier on each text token's value | |
| (prompt emphasis with weight <= 0), or None when no token is | |
| weighted. | |
| """ | |
| tokens: Tensor | |
| key_bias: Tensor | None | |
| value_scale: Tensor | None | |