Skip to content

ReShot — copy the shot, not the actors. Video → depth map, OpenPose skeleton or canny lines for Seedance 2.0/2.5 reference video, MiniMax H3 Fun ControlNet and Wan VACE. Apache-2.0. Open-sourced by Maosika 猫斯卡 (www.maosika.com), the AI short-drama production system.

metrics: GPU peak (allocated/reserved) per run; hidden --cuda-memory-fraction to emulate a smaller card

wangfeng6c9b9d2b1ddd
diff --git a/reshot/backends/base.py b/reshot/backends/base.py
index 3247ed4..91e48a2 100644
--- a/reshot/backends/base.py
+++ b/reshot/backends/base.py
@@ -28,3 +28,7 @@ class DepthBackend(Protocol):
def infer(self, frames: np.ndarray, fps: float, *, input_size: int = 518) -> np.ndarray:
"""`frames`: uint8 RGB `[T, H, W, 3]` → float32 inverse depth `[T, H, W]`."""
...
+
+ def peak_memory_bytes(self) -> dict[str, int]:
+ """Accelerator memory peak of the last `infer()`; `{}` when there is none to report."""
+ ...
diff --git a/reshot/backends/fake.py b/reshot/backends/fake.py
index 8ab446e..cbaf5cc 100644
--- a/reshot/backends/fake.py
+++ b/reshot/backends/fake.py
@@ -23,3 +23,6 @@ class FakeBackend:
base = 1.0 / (1.0 + ((xx - w / 2) ** 2 + (yy - h / 2) ** 2) / (0.15 * w * h))
ramp = np.linspace(0.8, 1.0, num=max(t, 1), dtype=np.float32)
return (base[None] * ramp[:, None, None]).astype(np.float32)
+
+ def peak_memory_bytes(self) -> dict[str, int]:
+ return {}
diff --git a/reshot/backends/vda.py b/reshot/backends/vda.py
index c91e68c..f60281a 100644
--- a/reshot/backends/vda.py
+++ b/reshot/backends/vda.py
@@ -67,6 +67,7 @@ class VDABackend:
model: str = "small",
device: str = "auto",
checkpoint: str | None = None,
+ cuda_memory_fraction: float | None = None,
) -> None:
variant = model
if variant not in _VARIANTS:
@@ -101,6 +102,11 @@ class VDABackend:
f"could not obtain weights for '{variant}': {exc}. "
"Set HF_ENDPOINT to a mirror, or pass --checkpoint with a local .pth."
) from exc
+ if cuda_memory_fraction is not None and self.device == "cuda":
+ # Emulate a smaller card: allocations beyond the fraction raise OOM instead of
+ # silently using the whole GPU. Used to verify the "runs on N GB" claim.
+ torch.cuda.set_per_process_memory_fraction(cuda_memory_fraction)
+ log.info("cuda memory capped at %.0f%% of the card", cuda_memory_fraction * 100)
log.info("loading %s from %s on %s (fp32=%s)", variant, path, self.device, self.fp32)
model = VideoDepthAnything(**_VARIANTS[variant])
model.load_state_dict(torch.load(path, map_location="cpu", weights_only=True), strict=True)
@@ -112,11 +118,23 @@ class VDABackend:
# Upstream's infer_video_depth already does 32-frame windows with 10-frame overlap,
# keyframe-based scale/shift alignment across windows and interpolation over the
# seam. That is the temporal-consistency machinery — do not re-chunk outside it.
+ if self.device == "cuda":
+ torch.cuda.reset_peak_memory_stats()
with torch.inference_mode(): # upstream uses no_grad; inference_mode also skips version counters
depths, _ = self.model.infer_video_depth(
frames, fps, input_size=input_size, device=self.device, fp32=self.fp32
)
return np.asarray(depths, dtype=np.float32)
+ def peak_memory_bytes(self) -> dict[str, int]:
+ """Peak VRAM of the last `infer()`: what the model actually touched (`allocated`)
+ and what the caching allocator held (`reserved`, ≈ what nvidia-smi shows)."""
+ if self.device != "cuda":
+ return {}
+ return {
+ "gpu_peak_allocated_bytes": int(torch.cuda.max_memory_allocated()),
+ "gpu_peak_reserved_bytes": int(torch.cuda.max_memory_reserved()),
+ }
+
__all__ = ["VDABackend", "pick_device"]
diff --git a/reshot/cli.py b/reshot/cli.py
index acc50cc..20be998 100644
--- a/reshot/cli.py
+++ b/reshot/cli.py
@@ -71,6 +71,9 @@ def build_parser() -> argparse.ArgumentParser:
g.add_argument("--metrics", type=Path, help="write timing / memory / size metrics as JSON")
g = p.add_argument_group("safety")
g.add_argument("--force", action="store_true", help="run even if the RAM estimate exceeds the budget")
+ # Verification aid, not a user feature: makes a big card behave like a small one so a
+ # "runs on N GB" claim can be tested (torch.cuda.set_per_process_memory_fraction).
+ g.add_argument("--cuda-memory-fraction", type=float, default=None, help=argparse.SUPPRESS)
p.add_argument("-v", "--verbose", action="store_true")
p.add_argument("--version", action="version", version=f"reshot {__version__}")
return p
@@ -114,6 +117,7 @@ def configs_from_args(args: argparse.Namespace) -> list[RunConfig]:
metrics=per_clip(args.metrics, stem, ".json"),
checkpoint=args.checkpoint,
force=args.force,
+ cuda_memory_fraction=args.cuda_memory_fraction,
)
)
return cfgs
diff --git a/reshot/config.py b/reshot/config.py
index d36d73a..344ec41 100644
--- a/reshot/config.py
+++ b/reshot/config.py
@@ -34,6 +34,7 @@ class RunConfig:
metrics: Path | None = None
checkpoint: Path | None = None
force: bool = False # ignore the RAM budget
+ cuda_memory_fraction: float | None = None # cap VRAM to this share of the card (verification aid)
extra: dict = field(default_factory=dict) # free-form, echoed into metrics
def __post_init__(self) -> None:
@@ -53,3 +54,5 @@ class RunConfig:
raise InputError("--crf must be in [0, 51]")
if self.max_frames is not None and self.max_frames < 1:
raise InputError("--max-frames must be ≥ 1")
+ if self.cuda_memory_fraction is not None and not 0 < self.cuda_memory_fraction <= 1:
+ raise InputError("--cuda-memory-fraction must be in (0, 1]")
diff --git a/reshot/pipeline.py b/reshot/pipeline.py
index f090071..a4e8b77 100644
--- a/reshot/pipeline.py
+++ b/reshot/pipeline.py
@@ -131,7 +131,11 @@ def _make_backend(cfg: RunConfig):
return get_backend("fake"), backend_name
device = pick_device(cfg.device)
backend = get_backend(
- "vda", model=cfg.model, device=device, checkpoint=str(cfg.checkpoint) if cfg.checkpoint else None
+ "vda",
+ model=cfg.model,
+ device=device,
+ checkpoint=str(cfg.checkpoint) if cfg.checkpoint else None,
+ cuda_memory_fraction=cfg.cuda_memory_fraction,
)
return backend, backend_name
@@ -213,8 +217,14 @@ def _run_one(cfg: RunConfig, rep: Reporter, backend, backend_name: str) -> RunRe
depths = backend.infer(frames, fps, input_size=cfg.input_size)
depth_seconds = time.time() - t1
del frames
+ gpu_peak = backend.peak_memory_bytes()
_release_accelerator(backend.device) # the model stays; only cached activations go
rep.step("depth", f"{depth_seconds:.1f}s = {depth_seconds / t * 1000:.0f} ms/frame")
+ if gpu_peak:
+ rep.step(
+ "vram",
+ f"peak {gib(gpu_peak['gpu_peak_allocated_bytes'])} allocated, {gib(gpu_peak['gpu_peak_reserved_bytes'])} reserved",
+ )
if cfg.npz:
Path(cfg.npz).parent.mkdir(parents=True, exist_ok=True)
@@ -251,6 +261,7 @@ def _run_one(cfg: RunConfig, rep: Reporter, backend, backend_name: str) -> RunRe
"ms_per_frame": round(depth_seconds / t * 1000, 1),
"total_seconds": round(total, 2),
"peak_rss_bytes": peak,
+ **gpu_peak,
"output": str(out),
"output_size": [p.out_w, p.out_h],
"output_bytes": os.path.getsize(out),