videogen/apps/api/engine/models/dc_ae/ae_model_zoo.py
caelum0x d56639a594
Some checks failed
build-images / web (push) Has been cancelled
vision2026-ci / Python SDK resource tests (push) Has been cancelled
build-images / api (push) Has been cancelled
build-images / worker-gpu (push) Has been cancelled
vision2026-ci / Shared packages (TS≡Python golden parity) (comfy-workflow-schema) (push) Has been cancelled
vision2026-ci / Shared packages (TS≡Python golden parity) (effects-core) (push) Has been cancelled
vision2026-ci / Shared packages (TS≡Python golden parity) (eventbus-types) (push) Has been cancelled
vision2026-ci / Shared packages (TS≡Python golden parity) (growth-analytics) (push) Has been cancelled
vision2026-ci / Shared packages (TS≡Python golden parity) (provider-adapter-kit) (push) Has been cancelled
vision2026-ci / Shared packages (TS≡Python golden parity) (publishing-connectors) (push) Has been cancelled
vision2026-ci / Shared packages (TS≡Python golden parity) (render-core) (push) Has been cancelled
vision2026-ci / Shared packages (TS≡Python golden parity) (shot-template-schema) (push) Has been cancelled
vision2026-ci / Shared packages (TS≡Python golden parity) (trends-schema) (push) Has been cancelled
vision2026-ci / Desktop engine crates (test + clippy + fmt) (push) Has been cancelled
codeql / Analyze (javascript-typescript) (push) Has been cancelled
codeql / Analyze (python) (push) Has been cancelled
perf / API hot-path micro-smoke (budgeted) (push) Has been cancelled
perf / Desktop engine crates (release build check) (push) Has been cancelled
vision2026-ci / API phase modules (ruff + pytest) (push) Has been cancelled
vision2026-ci / Alembic upgrade + drift check (push) Has been cancelled
vision2026-ci / Shared packages (TS≡Python golden parity) (caption-engine) (push) Has been cancelled
Menivor — open source release (MIT), free to use and fork
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.
2026-12-04 02:10:26 +03:00

85 lines
2.9 KiB
Python

# Copyright 2024 MIT Han Lab
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
# SPDX-License-Identifier: Apache-2.0
from typing import Callable, Optional
import diffusers
import torch
from huggingface_hub import PyTorchModelHubMixin
from torch import nn
from registry import MODELS
from utils.ckpt import load_checkpoint
from .models.dc_ae import DCAE, DCAEConfig, dc_ae_f32
__all__ = ["create_dc_ae_model_cfg", "DCAE_HF", "DC_AE"]
REGISTERED_DCAE_MODEL: dict[str, tuple[Callable, Optional[str]]] = {
"dc-ae-f32t4c128": (dc_ae_f32, None),
}
def create_dc_ae_model_cfg(name: str, pretrained_path: Optional[str] = None) -> DCAEConfig:
assert name in REGISTERED_DCAE_MODEL, f"{name} is not supported"
dc_ae_cls, default_pt_path = REGISTERED_DCAE_MODEL[name]
pretrained_path = default_pt_path if pretrained_path is None else pretrained_path
model_cfg = dc_ae_cls(name, pretrained_path)
return model_cfg
class DCAE_HF(DCAE, PyTorchModelHubMixin):
def __init__(self, model_name: str):
cfg = create_dc_ae_model_cfg(model_name)
DCAE.__init__(self, cfg)
@MODELS.register_module("dc_ae")
def DC_AE(
model_name: str,
device_map: str | torch.device = "cuda",
torch_dtype: torch.dtype = torch.bfloat16,
from_scratch: bool = False,
from_pretrained: str | None = None,
is_training: bool = False,
use_spatial_tiling: bool = False,
use_temporal_tiling: bool = False,
spatial_tile_size: int = 256,
temporal_tile_size: int = 32,
tile_overlap_factor: float = 0.25,
scaling_factor: float = None,
disc_off_grad_ckpt: bool = False,
) -> DCAE_HF:
if not from_scratch:
model = DCAE_HF.from_pretrained(model_name).to(device_map, torch_dtype)
else:
model = DCAE_HF(model_name).to(device_map, torch_dtype)
if from_pretrained is not None:
model = load_checkpoint(model, from_pretrained, device_map=device_map)
print(f"loaded dc_ae from ckpt path: {from_pretrained}")
model.cfg.is_training = is_training
model.use_spatial_tiling = use_spatial_tiling
model.use_temporal_tiling = use_temporal_tiling
model.spatial_tile_size = spatial_tile_size
model.temporal_tile_size = temporal_tile_size
model.tile_overlap_factor = tile_overlap_factor
if scaling_factor is not None:
model.scaling_factor = scaling_factor
model.decoder.disc_off_grad_ckpt = disc_off_grad_ckpt
return model