Some checks are pending
build-images / api (push) Waiting to run
build-images / worker-gpu (push) Waiting to run
build-images / web (push) Waiting to run
codeql / Analyze (javascript-typescript) (push) Waiting to run
codeql / Analyze (python) (push) Waiting to run
perf / API hot-path micro-smoke (budgeted) (push) Waiting to run
perf / Desktop engine crates (release build check) (push) Waiting to run
vision2026-ci / Shared packages (TS≡Python golden parity) (comfy-workflow-schema) (push) Waiting to run
vision2026-ci / Shared packages (TS≡Python golden parity) (effects-core) (push) Waiting to run
vision2026-ci / Shared packages (TS≡Python golden parity) (eventbus-types) (push) Waiting to run
vision2026-ci / Shared packages (TS≡Python golden parity) (growth-analytics) (push) Waiting to run
vision2026-ci / Shared packages (TS≡Python golden parity) (trends-schema) (push) Waiting to run
vision2026-ci / API phase modules (ruff + pytest) (push) Waiting to run
vision2026-ci / Shared packages (TS≡Python golden parity) (provider-adapter-kit) (push) Waiting to run
vision2026-ci / Shared packages (TS≡Python golden parity) (publishing-connectors) (push) Waiting to run
vision2026-ci / Shared packages (TS≡Python golden parity) (render-core) (push) Waiting to run
vision2026-ci / Shared packages (TS≡Python golden parity) (shot-template-schema) (push) Waiting to run
vision2026-ci / Python SDK resource tests (push) Waiting to run
vision2026-ci / Desktop engine crates (test + clippy + fmt) (push) Waiting to run
vision2026-ci / Alembic upgrade + drift check (push) Waiting to run
vision2026-ci / Shared packages (TS≡Python golden parity) (caption-engine) (push) Waiting to run
Paid, hosted product at menivor.com, now retired as a company project. Fresh squashed history of the cleaned working tree (secret-scanned, no .env, no customer data, no outreach logs). Built on MoneyPrinterTurbo (MIT, harry0703) — see NOTICE.
92 lines
2.8 KiB
Python
92 lines
2.8 KiB
Python
import colossalai
|
|
import torch
|
|
import torch.distributed as dist
|
|
from colossalai.booster import Booster
|
|
from colossalai.cluster import DistCoordinator
|
|
|
|
from acceleration.parallel_states import (
|
|
get_sequence_parallel_group,
|
|
get_tensor_parallel_group,
|
|
set_sequence_parallel_group,
|
|
)
|
|
from models.hunyuan_vae.policy import HunyuanVaePolicy
|
|
from models.mmdit.distributed import MMDiTPolicy
|
|
from utils.logger import is_distributed
|
|
from utils.train import create_colossalai_plugin
|
|
|
|
from .logger import log_message
|
|
|
|
|
|
def set_group_size(plugin_config: dict):
|
|
"""
|
|
Set the group size for tensor parallelism and sequence parallelism.
|
|
|
|
Args:
|
|
plugin_config (dict): Plugin configuration.
|
|
"""
|
|
tp_size = int(plugin_config.get("tp_size", 1))
|
|
sp_size = int(plugin_config.get("sp_size", 1))
|
|
if tp_size > 1:
|
|
assert sp_size == 1
|
|
plugin_config["tp_size"] = tp_size = min(tp_size, torch.cuda.device_count())
|
|
log_message(f"Using TP with size {tp_size}")
|
|
if sp_size > 1:
|
|
assert tp_size == 1
|
|
plugin_config["sp_size"] = sp_size = min(sp_size, torch.cuda.device_count())
|
|
log_message(f"Using SP with size {sp_size}")
|
|
|
|
|
|
def init_inference_environment():
|
|
"""
|
|
Initialize the inference environment.
|
|
"""
|
|
if is_distributed():
|
|
colossalai.launch_from_torch({})
|
|
coordinator = DistCoordinator()
|
|
enable_sequence_parallelism = coordinator.world_size > 1
|
|
if enable_sequence_parallelism:
|
|
set_sequence_parallel_group(dist.group.WORLD)
|
|
|
|
|
|
def get_booster(cfg: dict, ae: bool = False):
|
|
suffix = "_ae" if ae else ""
|
|
policy = HunyuanVaePolicy if ae else MMDiTPolicy
|
|
|
|
plugin_type = cfg.get(f"plugin{suffix}", "zero2")
|
|
plugin_config = cfg.get(f"plugin_config{suffix}", {})
|
|
plugin_kwargs = {}
|
|
booster = None
|
|
if plugin_type == "hybrid":
|
|
set_group_size(plugin_config)
|
|
plugin_kwargs = dict(custom_policy=policy)
|
|
|
|
plugin = create_colossalai_plugin(
|
|
plugin=plugin_type,
|
|
dtype=cfg.get("dtype", "bf16"),
|
|
grad_clip=cfg.get("grad_clip", 0),
|
|
**plugin_config,
|
|
**plugin_kwargs,
|
|
)
|
|
booster = Booster(plugin=plugin)
|
|
return booster
|
|
|
|
|
|
def get_is_saving_process(cfg: dict):
|
|
"""
|
|
Check if the current process is the one that saves the model.
|
|
|
|
Args:
|
|
plugin_config (dict): Plugin configuration.
|
|
|
|
Returns:
|
|
bool: True if the current process is the one that saves the model.
|
|
"""
|
|
plugin_type = cfg.get("plugin", "zero2")
|
|
plugin_config = cfg.get("plugin_config", {})
|
|
is_saving_process = (
|
|
plugin_type != "hybrid"
|
|
or (plugin_config["tp_size"] > 1 and dist.get_rank(get_tensor_parallel_group()) == 0)
|
|
or (plugin_config["sp_size"] > 1 and dist.get_rank(get_sequence_parallel_group()) == 0)
|
|
)
|
|
return is_saving_process
|