selector ¶
Classes¶
Functions:¶
fastvideo.attention.selector.backend_name_to_enum ¶
backend_name_to_enum(backend_name: str) -> AttentionBackendEnum | None
Convert a string backend name to a _Backend enum value.
Returns: * _Backend: enum value if backend_name is a valid in-tree type * None: otherwise it's an invalid in-tree type or an out-of-tree platform is loaded.
Source code in fastvideo/attention/selector.py
fastvideo.attention.selector.coerce_attn_backend ¶
coerce_attn_backend(attn_backend: AttentionBackendEnum | str | None) -> AttentionBackendEnum | None
Normalize an explicit backend selection.
Environment-variable parsing remains permissive via :func:backend_name_to_enum, but typed/config-driven call sites should fail fast on typos instead of silently falling back to another backend.
Source code in fastvideo/attention/selector.py
fastvideo.attention.selector.component_attention_backend ¶
component_attention_backend(component: object) -> AttentionBackendEnum | _NoRequest
Read back the decision :func:record_resolved_attention_backend wrote.
Returns NO_REQUEST unless the component recorded a concrete backend, so a caller that passes this through only overrides the ambient fallback when there is a real decision to override it with.
NO_REQUEST rather than None for the no-decision case is deliberate, and cannot be derived from the attribute's presence: ModelConfig declares _resolved_attention_backend as a field defaulting to None, so the attribute always exists and a getattr default can never fire. Worse, record_resolved_attention_backend writes None whenever no scope is active, so "resolved to automatic selection" and "never recorded" are the same stored value. Neither state should suppress the environment variable at a call site that previously honoured it, and collapsing both to NO_REQUEST keeps that behavior identical.
Source code in fastvideo/attention/selector.py
fastvideo.attention.selector.get_attn_backend ¶
get_attn_backend(head_size: int, dtype: dtype, supported_attention_backends: tuple[AttentionBackendEnum, ...] | None = None, default_backend: AttentionBackendEnum | None = None, *, requested: AttentionBackendEnum | None | _NoRequest = NO_REQUEST) -> type[AttentionBackend]
Resolve the attention backend class for one call site.
requested is the decision made for the component this call site belongs to — read from ModelConfig._resolved_attention_backend. Passing it means the caller knows the answer, so nothing ambient is consulted:
requested=SOME_BACKEND— use it (subject to the layer's declared support), ignoring the construction scope and the environment;requested=None— that component resolved to automatic selection. That is an answer, not an absence, so the environment is not consulted behind it;requestedomitted (NO_REQUEST) — the caller has no opinion; fall back to the construction scope, then the environment. This is the path every layer built inside a loader still takes.
Source code in fastvideo/attention/selector.py
fastvideo.attention.selector.get_env_variable_attn_backend ¶
Get the backend override specified by the FastVideo attention backend environment variable, if one is specified.
Returns:
- _Backend enum value if an override is specified
- None otherwise
Source code in fastvideo/attention/selector.py
fastvideo.attention.selector.record_resolved_attention_backend ¶
record_resolved_attention_backend(config: object) -> AttentionBackendEnum | None
Write the request governing construction right now onto a component config.
Called by each loader while its component is being built, so the decision ends up on the object the component keeps and is readable from the component after load. The loader is the right place rather than the caller above it: a loader may narrow the request for one component (the DMD teacher/critic transformers build dense inside a nested scope), and only it knows that.