[1/N] Unify multiple-path encoder cuda graph support (#49934)
Signed-off-by: Isotr0py <Isotr0py@outlook.com> Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
This commit is contained in:
co-authored by
mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
parent
c67fe497a2
commit
e2fa28594f
@@ -26,13 +26,28 @@ class EncoderItemSpec:
|
||||
"""Number of output tokens after encoder processing (e.g. after
|
||||
spatial merge)."""
|
||||
|
||||
global_output_tokens: int = 0
|
||||
"""Number of output tokens from the global image path.
|
||||
Only used when ``EncoderCudaGraphConfig.enable_dual_path_graph`` is True."""
|
||||
path_output_tokens: dict[str, int] = field(default_factory=dict)
|
||||
"""Per-path output token counts for multi-path encoders.
|
||||
|
||||
local_output_tokens: int = 0
|
||||
"""Number of output tokens from the local patch path.
|
||||
Only used when ``EncoderCudaGraphConfig.enable_dual_path_graph`` is True."""
|
||||
Single-path encoders leave this empty and use ``output_tokens`` for the
|
||||
default path.
|
||||
"""
|
||||
|
||||
def get_path_output_tokens(self, path: str) -> int:
|
||||
if path == "default" and not self.path_output_tokens:
|
||||
return self.output_tokens
|
||||
return self.path_output_tokens.get(path, 0)
|
||||
|
||||
|
||||
@dataclass(frozen=True)
|
||||
class EncoderCudaGraphPathConfig:
|
||||
"""Capture policy for one independently replayable encoder path."""
|
||||
|
||||
min_token_budget: int | None = None
|
||||
"""Smallest capture budget, or the model default minimum when unset."""
|
||||
|
||||
allow_zero_tokens: bool = False
|
||||
"""Whether a batch may omit this path entirely."""
|
||||
|
||||
|
||||
@dataclass
|
||||
@@ -68,17 +83,10 @@ class EncoderCudaGraphConfig:
|
||||
Only relevant when "video" is in ``modalities``.
|
||||
Image-only models can use the default of 1."""
|
||||
|
||||
enable_dual_path_graph: bool = False
|
||||
"""If True, the manager captures two independent graph sets
|
||||
(global + local) and runs dual-path graph selection during inference."""
|
||||
|
||||
global_token_per_image: int = 0
|
||||
"""Tokens per global image (e.g. 272 for DeepSeek-OCR).
|
||||
Only used when ``enable_dual_path_graph`` is True."""
|
||||
|
||||
local_token_per_patch: int = 0
|
||||
"""Tokens per local patch (e.g. 100 for DeepSeek-OCR).
|
||||
Only used when ``enable_dual_path_graph`` is True."""
|
||||
paths: dict[str, EncoderCudaGraphPathConfig] = field(
|
||||
default_factory=lambda: {"default": EncoderCudaGraphPathConfig()}
|
||||
)
|
||||
"""Independently captured encoder paths keyed by their forward name."""
|
||||
|
||||
|
||||
@dataclass
|
||||
|
||||
Reference in New Issue
Block a user