175 lines
6.4 KiB
Python
175 lines
6.4 KiB
Python
"""Install a wheelhouse overlay in a new venv, or verify its CPU imports and assets."""
|
|
|
|
import argparse
|
|
import hashlib
|
|
import os
|
|
import subprocess
|
|
import sys
|
|
from importlib.metadata import version
|
|
from pathlib import Path
|
|
|
|
ENV = Path("/workspace/envs/latentsync16-preview")
|
|
ROOT = Path("/workspace/models/latentsync16-preview-v1")
|
|
APP = Path(__file__).resolve().parents[1]
|
|
LOCK = APP / "requirements-latentsync-preview.txt"
|
|
SOURCE_FILES = {
|
|
"configs/scheduler_config.json": "14561e18160bf30bbcf7c93259af07ae82bbf611defeb93e995883fce1461315",
|
|
"latentsync/whisper/whisper/assets/mel_filters.npz": "dd2cc75e70e36fcbdd8ffbc2499062f30094093e6bf2cbafa9859f59972b420b",
|
|
"latentsync/pipelines/lipsync_pipeline.py": "1355313d99ef0ce3bce22deec2db82ac0910b3f887650a14611e8077a2dc800c",
|
|
"latentsync/whisper/audio2feature.py": "16c851d4619375fe328cc7c58c0408beff9311dcd057d32fe6e69241b0945aa4",
|
|
"latentsync/utils/image_processor.py": "003cc7370e2b9724e23b3d498b4c2dd9c11f1c4c31ec3c4e23b9c662d89a17aa",
|
|
"latentsync/models/unet.py": "9064845c34ebb9d4c854a56705b249130471822c101e84c0bf9df7ff2f604fe6",
|
|
"latentsync/utils/affine_transform.py": "50eed2cce5c6e365c84161949b0216f24b1a715c3a10661f0881cbbe8e09c691",
|
|
"configs/unet/stage2_512.yaml": "652bbf469d3baf68f1b364fd47409901cd8d1bf8bb7754133aa69a28132312e6",
|
|
"latentsync/utils/mask.png": "aa233251b9ff5691a1565a4108f0910ab1e5e7ad79a7bb2b741ab4d92c81053c",
|
|
}
|
|
|
|
|
|
def checksum(path):
|
|
with path.open("rb") as stream:
|
|
return hashlib.file_digest(stream, "sha256").hexdigest()
|
|
|
|
|
|
def verify():
|
|
if Path(sys.prefix) != ENV:
|
|
raise RuntimeError("Run verification inside the candidate environment")
|
|
repo = ROOT / "LatentSync"
|
|
sys.path[:0] = [str(repo), str(APP)]
|
|
from llm_services.dialogue.latentsync_preview import UNET_SHA, WHISPER_SHA
|
|
|
|
for rel, expected in {
|
|
**SOURCE_FILES,
|
|
"checkpoints/latentsync_unet.pt": UNET_SHA,
|
|
"checkpoints/whisper/tiny.pt": WHISPER_SHA,
|
|
}.items():
|
|
if checksum(repo / rel) != expected:
|
|
raise ValueError("Unexpected contents: " + rel)
|
|
vae = ROOT / "sd-vae-ft-mse"
|
|
vae_files = {
|
|
"diffusion_pytorch_model.safetensors": "a1d993488569e928462932c8c38a0760b874d166399b14414135bd9c42df5815",
|
|
"diffusion_pytorch_model.bin": "1b4889b6b1d4ce7ae320a02dedaeff1780ad77d415ea0d744b476155c6377ddc",
|
|
}
|
|
present = [path for path in vae_files if (vae / path).is_file()]
|
|
if not present or any(checksum(vae / path) != vae_files[path] for path in present):
|
|
raise ValueError("Unexpected or missing sd-vae-ft-mse weights")
|
|
for p in (
|
|
vae / "config.json",
|
|
repo / "configs/scheduler_config.json",
|
|
repo / "checkpoints/auxiliary/models/buffalo_l/2d106det.onnx",
|
|
):
|
|
if not p.is_file():
|
|
raise ValueError(f"Missing {p}")
|
|
for line in LOCK.read_text().splitlines():
|
|
if "==" in line and not line.startswith("#"):
|
|
name, expected = line.split("==")
|
|
if version(name) != expected:
|
|
raise ValueError("Unpinned candidate dependency: " + name)
|
|
# Import all runtime entry points on CPU. This does not initialize a model or open a GPU session.
|
|
from importlib import import_module
|
|
|
|
for name in (
|
|
"cv2",
|
|
"numpy",
|
|
"scipy.signal",
|
|
"soundfile",
|
|
"torch",
|
|
"torchvision",
|
|
"psutil",
|
|
"pynvml",
|
|
"onnxruntime",
|
|
):
|
|
import_module(name)
|
|
for module, names in {
|
|
"diffusers": ("AutoencoderKL", "DDIMScheduler"),
|
|
"insightface.model_zoo.landmark": ("Landmark",),
|
|
"latentsync.pipelines.lipsync_pipeline": ("LipsyncPipeline",),
|
|
"latentsync.whisper.audio2feature": ("Audio2Feature",),
|
|
"transformers": ("SegformerForSemanticSegmentation", "SegformerImageProcessor"),
|
|
}.items():
|
|
loaded = import_module(module)
|
|
for name in names:
|
|
getattr(loaded, name)
|
|
print(
|
|
"CPU imports and candidate assets verified; temporal 24fps quality awaits a queued sample"
|
|
)
|
|
print(
|
|
{
|
|
p: version(p)
|
|
for p in (
|
|
"torch",
|
|
"torchvision",
|
|
"diffusers",
|
|
"transformers",
|
|
"numpy",
|
|
"insightface",
|
|
)
|
|
}
|
|
)
|
|
|
|
|
|
def main():
|
|
parser = argparse.ArgumentParser(description=__doc__)
|
|
parser.add_argument("--verify-only", action="store_true")
|
|
parser.add_argument("--wheelhouse", type=Path)
|
|
args = parser.parse_args()
|
|
python = ENV / "bin/python"
|
|
sys.path.insert(0, str(APP))
|
|
from llm_services.dialogue.latentsync_preview import cache_environment
|
|
|
|
cpu = {
|
|
**os.environ,
|
|
**cache_environment(ROOT),
|
|
"CUDA_VISIBLE_DEVICES": "",
|
|
"OPENBLAS_NUM_THREADS": "2",
|
|
"OMP_NUM_THREADS": "2",
|
|
"PYTHONDONTWRITEBYTECODE": "1",
|
|
"PYTHONPATH": str(APP),
|
|
}
|
|
if not args.verify_only:
|
|
if not args.wheelhouse or not args.wheelhouse.is_dir():
|
|
parser.error("Provide the local wheelhouse for an offline installation")
|
|
if sys.version_info[:2] != (3, 12):
|
|
parser.error("Use the existing CPython 3.12 runtime")
|
|
if not python.is_file():
|
|
subprocess.run(
|
|
[sys.executable, "-m", "venv", str(ENV)], check=True, env=cpu
|
|
)
|
|
target = ENV / "lib/python3.12/site-packages"
|
|
paths = [
|
|
Path("/workspace/envs") / name / "lib/python3.12/site-packages"
|
|
for name in ("dialogue-v1", "vllm")
|
|
]
|
|
if not all(p.is_dir() for p in paths):
|
|
raise ValueError("Missing shared dialogue or GPU libraries")
|
|
(target / "shared_gpu.pth").write_text("".join(str(p) + "\n" for p in paths))
|
|
subprocess.run(
|
|
[
|
|
str(python),
|
|
"-m",
|
|
"pip",
|
|
"install",
|
|
"--no-index",
|
|
"--find-links",
|
|
str(args.wheelhouse),
|
|
"--only-binary=:all:",
|
|
"--no-deps",
|
|
"-r",
|
|
str(LOCK),
|
|
],
|
|
check=True,
|
|
env=cpu,
|
|
)
|
|
if args.verify_only and Path(sys.prefix) == ENV:
|
|
os.environ.update(cpu)
|
|
verify()
|
|
else:
|
|
subprocess.run(
|
|
[str(python), str(Path(__file__).resolve()), "--verify-only"],
|
|
check=True,
|
|
env=cpu,
|
|
)
|
|
|
|
|
|
if __name__ == "__main__":
|
|
main()
|