-
Notifications
You must be signed in to change notification settings - Fork 30
feat: custom resolution support for comfyui live pipeline #586
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Draft
eliteprox
wants to merge
21
commits into
main
Choose a base branch
from
feat/dynamic-resolution
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from all commits
Commits
Show all changes
21 commits
Select commit
Hold shift + click to select a range
7eab4d9
poc multiresolution
eliteprox 3d15ccb
warmup pipeline based on workflow prompt
eliteprox 6cd09d3
wip params update
eliteprox 1389508
Pass output resolution from decoder to encoder, remove defaults
eliteprox 9ac60ae
(wip) dynamic resolution
eliteprox 99387ab
use resolution from prompt
eliteprox 8b803a5
fix latent dimension parsing on string
eliteprox 84690f0
restart pipeline process on resolution change
eliteprox 087a41a
change default due to warm-up
eliteprox 78088b1
improve parsing of resolution for restarts
eliteprox ed42e56
fix pipeline restart with different resolution
eliteprox c2af95c
code cleanup
eliteprox e2786ae
fix decoder
eliteprox 7794f17
crop and resize input frames to workflow dimensions
eliteprox aa54a4c
remove exception
eliteprox d5c1f8f
refactor process.py to use self.pipeline
eliteprox b0b9859
improve cleanup for comfyui pipeline
eliteprox a48b595
bump comfyui-base
eliteprox bc5191f
add width/height params for resolution, fix noop pipeline cleanup
eliteprox b81d248
unload tensor correctly
eliteprox 7f42ab9
set dimensions of pipeline with startup arg
eliteprox File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -7,6 +7,7 @@ | |
| from trickle import InputFrame, OutputFrame | ||
| from .process import PipelineProcess | ||
| from .status import PipelineState, PipelineStatus, InferenceStatus, InputStatus | ||
| from utils import ComfyUtils | ||
|
|
||
| FPS_LOG_INTERVAL = 10.0 | ||
|
|
||
|
|
@@ -19,6 +20,9 @@ class StreamerCallbacks(abc.ABC): | |
| @abc.abstractmethod | ||
| def is_stream_running(self) -> bool: ... | ||
|
|
||
|
|
||
|
|
||
| class ProcessCallbacks(abc.ABC): | ||
| @abc.abstractmethod | ||
| async def emit_monitoring_event(self, event_data: dict) -> None: ... | ||
|
|
||
|
|
@@ -44,6 +48,7 @@ def __init__( | |
| ): | ||
| self.pipeline = pipeline | ||
| self.initial_params = params | ||
| self.width, self.height = ComfyUtils.get_latent_image_dimensions(params.get('prompt')) | ||
| self.streamer: StreamerCallbacks = _NoopStreamerCallbacks() | ||
|
|
||
| self.process: Optional[PipelineProcess] = None | ||
|
|
@@ -82,13 +87,33 @@ async def reset_stream( | |
| ): | ||
| if not self.process: | ||
| raise RuntimeError("Process not running") | ||
|
|
||
| # Check if resolution has changed | ||
| new_width = params.get("width", None) | ||
| new_height = params.get("height", None) | ||
| if (new_width is None or new_height is None): | ||
| new_width, new_height = ComfyUtils.DEFAULT_WIDTH, ComfyUtils.DEFAULT_HEIGHT | ||
|
|
||
| # If resolution changed, we need to restart the process (does not work for comfyui) | ||
| if (new_width != self.width or new_height != self.height): | ||
| logging.info(f"Resolution changed from {self.width}x{self.height} to {new_width}x{new_height}, restarting process") | ||
| self.width = new_width | ||
| self.height = new_height | ||
| await self.process._cleanup_pipeline() | ||
| await self.stop() | ||
| # Create new process with current pipeline name and params | ||
| params.update({"width": new_width, "height": new_height}) | ||
| self.process = PipelineProcess.start(self.pipeline, params) | ||
|
|
||
| self.status.start_time = time.time() | ||
| self.status.input_status = InputStatus() | ||
| self.input_fps_counter.reset() | ||
| self.output_fps_counter.reset() | ||
| self.streamer = streamer or _NoopStreamerCallbacks() | ||
|
|
||
| self.process.reset_stream(request_id, manifest_id, stream_id) | ||
| self.process.update_params(params) | ||
|
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. likely not needed |
||
|
|
||
| await self.update_params(params) | ||
| self.status.update_state(PipelineState.ONLINE) | ||
|
|
||
|
|
@@ -310,7 +335,7 @@ async def _monitor_loop(self): | |
| # Hot fix: the comfyui pipeline process is having trouble shutting down and causes restarts not to recover. | ||
| # So we skip the restart here and move the state to ERROR so the worker will restart the whole container. | ||
| # TODO: Remove this exception once pipeline shutdown is fixed and restarting process is useful again. | ||
| raise Exception("Skipping process restart due to pipeline shutdown issues") | ||
| #raise Exception("Skipping process restart due to pipeline shutdown issues") | ||
| await self._restart_process() | ||
| except Exception: | ||
| logging.exception("Failed to stop streamer and restart process. Moving to ERROR state", stack_info=True) | ||
|
|
||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Will remove, comfyui pipeline will stop itself