feature: domain specific task names. added sam-3, flux-2. Moved some runway models to replicate provider#46
Conversation
…rt from act-two wich is only available from runway directly
There was a problem hiding this comment.
Pull request overview
This PR implements a comprehensive update to the model infrastructure, introducing new models, standardizing task naming conventions, and improving provider integrations. The changes include migration of Runway models to Replicate, addition of new segmentation and image generation models, system prompt enhancements, and various video processing improvements.
Key Changes:
- Standardized Celery task naming with domain prefixes (
images.,videos.,texts.) - Added new models: FLUX 2, SAM 2, and SAM 3 for image generation and segmentation
- Migrated
runway-gen-4andrunway-upscalefrom Runway API to Replicate - Introduced
NONEsystem prompt option for text models with empty default behavior - Enhanced video processing with compression, better duration handling, and resolution-aware logic
Reviewed changes
Copilot reviewed 35 out of 35 changed files in this pull request and generated 17 comments.
Show a summary per file
| File | Description |
|---|---|
| workers/images/tasks.py | Added FLUX 2, SAM 2/3 tasks; standardized task naming with images. prefix |
| workers/images/schemas.py | Updated model registry with FLUX 2, SAM 2/3 definitions; added task_name property |
| workers/images/local/flux_2.py | New FLUX 2.0 implementation with multi-image support and inpainting |
| workers/images/local/sam_2.py | Renamed from segment-anything-2; improved mask coloring logic |
| workers/images/local/sam_3.py | New SAM 3 implementation with text-based segmentation |
| workers/videos/tasks.py | Standardized task naming with videos. prefix |
| workers/videos/schemas.py | Updated runway model providers to replicate; added task_name property |
| workers/videos/context.py | Added video compression, resolution detection, duration calculation methods |
| workers/videos/external/runway_gen_4.py | Refactored to use Replicate API with aspect ratio mapping |
| workers/videos/external/runway_upscale.py | Migrated from Runway SDK to Replicate helpers |
| workers/videos/external/runway_act_two.py | Minor video compression integration |
| workers/videos/external/openai_sora_2.py | Updated duration logic from long_video() to duration_in_seconds() |
| workers/videos/external/minimax_hailuo_2.py | Updated duration and resolution logic |
| workers/videos/external/kwaivgi_kling_2.py | Updated duration logic to use duration_in_seconds() |
| workers/videos/external/google_veo_3.py | Refactored duration and audio settings |
| workers/videos/external/bytedance_seedance_1.py | Updated duration logic and added resolution parameter |
| workers/videos/local/ltx_video.py | Improved frame count handling with min() logic |
| workers/texts/tasks.py | Standardized task naming with texts. prefix |
| workers/texts/schemas.py | Added NONE system prompt; condensed optimizer prompts |
| workers/texts/local/qwen_2.py | Made system prompt optional with empty check |
| workers/texts/external/openai_gpt.py | Added conditional system prompt handling |
| workers/utils/utils.py | Added mp4_to_base64_decoded; updated load functions with model parameter; removed unused imports; increased max resolution to 4096 |
| workers/common/pipeline_helpers.py | Added offload parameter to get_quantized_model; improved optimize_pipeline with conditional safety checker; added documentation |
| workers/tests/images/local/test_*.py | Renamed and added tests for SAM 2/3 and FLUX 2 |
| workers/tests/images/helpers.py | Updated model routing for renamed and new models |
| workers/requirements.txt | Updated diffusers commit hash; added sam3 package |
| api/images/schemas.py | Mirrored worker schema updates for FLUX 2, SAM 2/3 |
| api/videos/schemas.py | Mirrored worker schema updates for provider changes |
| api/texts/schemas.py | Mirrored worker schema updates for NONE prompt and condensed text |
| clients/openapi.json | Updated OpenAPI spec with new models and system prompts |
| clients/nuke/gizmos/dd_image.gizmo | Updated model dropdown with SAM 2/3 replacements |
| README.md | Updated documentation references from models/ to local/ and tasks/ |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
workers/images/tasks.py
Outdated
| from images.local.segment_anything_2 import main | ||
| @typed_task(name="sam-2", queue="gpu") | ||
| def sam_2_image(request_dict): | ||
| from images.local.sam_2_image import main |
There was a problem hiding this comment.
The import statement references images.local.sam_2_image, but the actual file is named sam_2.py. This will cause an ImportError at runtime. The import should be:
from images.local.sam_2 import main| from images.local.sam_2_image import main | |
| from images.local.sam_2 import main |
| model_id, text_encoder=text_encoder, transformer=transformer, torch_dtype=torch.bfloat16 | ||
| ) | ||
|
|
||
| # allways offload as heavy models |
There was a problem hiding this comment.
Typo in comment: "allways" should be "always".
| # allways offload as heavy models | |
| # always offload as heavy models |
workers/videos/context.py
Outdated
|
|
||
| def get_flow_shift(self) -> float: | ||
| return 5.0 if self.get_is_720p() else 3.0 | ||
| return 5.0 if self.get_resolution_type() == "720p" else 3.0 |
There was a problem hiding this comment.
[nitpick] The logic for get_flow_shift() only checks for 720p and defaults to 3.0 for both 480p and 1080p. If 1080p should have a different flow shift value than 480p, consider adding explicit handling:
def get_flow_shift(self) -> float:
resolution = self.get_resolution_type()
if resolution == "720p":
return 5.0
elif resolution == "1080p":
return 3.0 # or appropriate value for 1080p
return 3.0 # 480p| return 5.0 if self.get_resolution_type() == "720p" else 3.0 | |
| resolution = self.get_resolution_type() | |
| if resolution == "720p": | |
| return 5.0 | |
| elif resolution == "1080p": | |
| return 3.0 # or set to a different value if needed | |
| return 3.0 # 480p |
workers/common/pipeline_helpers.py
Outdated
| from accelerate.hooks import CpuOffload | ||
| from cachetools.keys import hashkey | ||
| from diffusers import GGUFQuantizationConfig | ||
| from diffusers import DiffusionPipeline, GGUFQuantizationConfig |
There was a problem hiding this comment.
Import of 'DiffusionPipeline' is not used.
| from diffusers import DiffusionPipeline, GGUFQuantizationConfig | |
| from diffusers import GGUFQuantizationConfig |
workers/images/local/sam_3.py
Outdated
| @@ -0,0 +1,119 @@ | |||
| import os | |||
There was a problem hiding this comment.
Import of 'os' is not used.
| import os |
workers/images/local/sam_3.py
Outdated
| import os | ||
| import random | ||
|
|
||
| import numpy as np |
There was a problem hiding this comment.
Import of 'np' is not used.
| import numpy as np |
| @@ -0,0 +1,70 @@ | |||
| from typing import List, Literal | |||
There was a problem hiding this comment.
Import of 'Literal' is not used.
| from typing import List, Literal | |
| from typing import List |
| if disable_safety_checker: | ||
| try: | ||
| pipe.vae.enable_slicing() # Enable VAE slicing to reduce memory usage | ||
| except: |
There was a problem hiding this comment.
Except block directly handles BaseException.
| except: | |
| except Exception: |
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 36 out of 36 changed files in this pull request and generated 4 comments.
Comments suppressed due to low confidence (1)
workers/texts/external/openai_gpt.py:4
- Import of 'Omit' is not used.
from openai import Omit, OpenAI
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| if self.width >= 1280 or self.height >= 1280: | ||
| return True | ||
| return False | ||
|
|
||
| def is_1080p_or_higher(self) -> bool: | ||
| if self.width >= 1920 or self.height >= 1920: |
There was a problem hiding this comment.
The logic for determining 720p or higher resolution may be incorrect. Using or means a 1280x480 video would be considered 720p+ because width >= 1280, even though the total pixel count is much less than 720p (1280x720 = 921,600 pixels). Consider using and instead: if self.width >= 1280 and self.height >= 720: to ensure both dimensions meet the threshold.
| if self.width >= 1280 or self.height >= 1280: | |
| return True | |
| return False | |
| def is_1080p_or_higher(self) -> bool: | |
| if self.width >= 1920 or self.height >= 1920: | |
| if self.width >= 1280 and self.height >= 720: | |
| return True | |
| return False | |
| def is_1080p_or_higher(self) -> bool: | |
| if self.width >= 1920 and self.height >= 1080: |
| if self.width >= 1280 or self.height >= 1280: | ||
| return True | ||
| return False | ||
|
|
||
| def is_1080p_or_higher(self) -> bool: | ||
| if self.width >= 1920 or self.height >= 1920: |
There was a problem hiding this comment.
Similar to the 720p check, the logic for determining 1080p or higher resolution may be incorrect. Using or means a 1920x480 video would be considered 1080p+ even though it doesn't meet the 1080p standard (1920x1080). Consider using and instead: if self.width >= 1920 and self.height >= 1080: to ensure both dimensions meet the threshold.
| if self.width >= 1280 or self.height >= 1280: | |
| return True | |
| return False | |
| def is_1080p_or_higher(self) -> bool: | |
| if self.width >= 1920 or self.height >= 1920: | |
| if self.width >= 1280 and self.height >= 720: | |
| return True | |
| return False | |
| def is_1080p_or_higher(self) -> bool: | |
| if self.width >= 1920 and self.height >= 1080: |
| from typing import Any, Dict | ||
|
|
||
| from openai import OpenAI | ||
| from openai import Omit, OpenAI |
There was a problem hiding this comment.
The Omit import from openai is added but never used in this file. Consider removing it to keep the imports clean.
| from openai import Omit, OpenAI | |
| from openai import OpenAI |
| path = export_to_video(self.video_frames, output_video_path=tmp_path, fps=fps, quality=9) | ||
| logger.info(f"Compressed video saved at {path}") | ||
|
|
||
| # convert and check size once more abort if still too large |
There was a problem hiding this comment.
Typo in comment: "abort" should be "and abort" or the comment should read "convert and check size once more; abort if still too large".
| # convert and check size once more abort if still too large | |
| # convert and check size once more; abort if still too large |
No description provided.