From 318bfd093ed78233262ec54ac2431f0ed376a0f4 Mon Sep 17 00:00:00 2001 From: Aryan Kumar <156166681+aryan5v@users.noreply.github.com> Date: Tue, 10 Nov 2026 02:06:29 +0000 Subject: [PATCH] [misc]: Remove unreferenced dead code across the repo --- apps/dreamverse/dreamverse/config.py | 23 ---- collect_env.py | 8 -- comfyui/video_generator/node_helpers.py | 33 ----- comfyui/video_generator/video_generator.py | 5 - examples/inference/basic/basic_hy15.py | 1 - examples/inference/basic/basic_hy15_1080p.py | 1 - .../basic/basic_self_forcing_causal.py | 2 - .../basic/mlx_wan_prompt_to_video.py | 11 -- .../gradio/local/gradio_local_demo.py | 1 - .../local/gradio_local_demo_ltx2_3/ui.py | 1 - examples/inference/lora/wan_lora_inference.py | 1 - .../lora/wan_lora_inference_from_ckpt.py | 1 - .../quantization/bench/bench_utils.py | 7 - .../triton_kernels/attn_qat_vsa_reference.py | 6 - .../fastvideo_kernel/triton_kernels/index.py | 65 --------- .../triton_kernels/st_attn_triton.py | 5 - .../fastvideo_kernel/turbodiffusion_ops.py | 3 +- fastvideo/attention/backends/abstract.py | 20 +-- fastvideo/attention/backends/flash_attn.py | 16 --- .../attention/utils/flash_attn_no_pad.py | 52 -------- .../dataset/parquet_dataset_map_style.py | 1 - fastvideo/distributed/parallel_state.py | 9 -- fastvideo/entrypoints/cli/utils.py | 7 - .../synthetic_optical_flow/_thirdperson.py | 123 ------------------ fastvideo/layers/fp4linear.py | 8 -- fastvideo/layers/fp8linear.py | 5 - fastvideo/layers/rotary_embedding.py | 13 -- fastvideo/mlx_runtime/fastwan.py | 80 ------------ fastvideo/mlx_runtime/minimax_h3_vision.py | 12 -- fastvideo/mlx_runtime/minimax_h3_vsa.py | 4 - fastvideo/models/dits/cosmos2_5.py | 2 - fastvideo/models/dits/gen3c.py | 2 - fastvideo/models/dits/hyworld/camera_rope.py | 1 - .../models/dits/hyworld/retrieval_context.py | 2 +- fastvideo/models/dits/magi_human.py | 1 - fastvideo/models/dits/matrixgame2/utils.py | 9 -- fastvideo/models/encoders/qwen2_5.py | 8 +- fastvideo/models/encoders/vision.py | 43 ------ fastvideo/models/hf_transformer_utils.py | 16 --- fastvideo/models/loader/component_loader.py | 2 +- fastvideo/models/loader/weight_utils.py | 6 - fastvideo/models/upsamplers/hunyuan15.py | 2 - fastvideo/models/vaes/flux2vae.py | 1 - fastvideo/models/vaes/ltx2vae.py | 1 - fastvideo/models/vaes/minimax_h3_taeh3.py | 1 - fastvideo/models/wan/causal_transformer.py | 7 +- .../pipelines/basic/pika_h3_flex/buckets.py | 5 - fastvideo/platforms/interface.py | 5 - fastvideo/utils.py | 10 -- .../minimax_h3_pro6000/bench_code.py | 2 - .../convert_gen3c_to_fastvideo.py | 20 --- .../convert_magi_human_to_diffusers.py | 2 +- .../checkpoint_conversion/wan_to_diffusers.py | 1 - scripts/demo_anyflow_14b.py | 1 - scripts/lora_extraction/upload_adapter.py | 1 - scripts/lora_extraction/verify_lora.py | 1 - 56 files changed, 10 insertions(+), 666 deletions(-) diff --git a/apps/dreamverse/dreamverse/config.py b/apps/dreamverse/dreamverse/config.py index f8b699f2e..8ded333c4 100644 --- a/apps/dreamverse/dreamverse/config.py +++ b/apps/dreamverse/dreamverse/config.py @@ -168,29 +168,6 @@ def _env_choice(name: str, default: str, allowed: tuple[str, ...]) -> str: raise RuntimeError(f"Invalid {name}: {normalized!r}. Expected one of {allowed_values}.") -def _env_csv(name: str, default: str) -> list[str]: - raw = os.getenv(name, default) - values = [item.strip() for item in raw.split(",")] - unique_values: list[str] = [] - for value in values: - if not value or value in unique_values: - continue - unique_values.append(value) - return unique_values - - -def _required_env(*names: str) -> str: - for name in names: - value = os.getenv(name) - if not isinstance(value, str): - continue - normalized = value.strip() - if normalized: - return normalized - joined_names = ", ".join(names) - raise RuntimeError(f"Missing required environment variable: one of {joined_names}") - - def _optional_env(*names: str) -> str | None: for name in names: value = os.getenv(name) diff --git a/collect_env.py b/collect_env.py index af20f382e..2d77f6cbf 100644 --- a/collect_env.py +++ b/collect_env.py @@ -137,14 +137,6 @@ def run_and_parse_first_match(run_lambda, command, regex): return match.group(1) -def run_and_return_first_line(run_lambda, command): - """Run command using run_lambda and returns first line if output is not empty.""" - rc, out, _ = run_lambda(command) - if rc != 0: - return None - return out.split('\n')[0] - - def get_conda_packages(run_lambda, patterns=None): if patterns is None: patterns = DEFAULT_CONDA_PATTERNS diff --git a/comfyui/video_generator/node_helpers.py b/comfyui/video_generator/node_helpers.py index 1f0f724f8..4612634c0 100644 --- a/comfyui/video_generator/node_helpers.py +++ b/comfyui/video_generator/node_helpers.py @@ -2,26 +2,12 @@ import hashlib from collections.abc import Callable from typing import Any, TypeVar -import torch from comfy.cli_args import args from PIL import ImageFile, UnidentifiedImageError T = TypeVar('T') -def conditioning_set_values(conditioning: list[Any], values: dict[str, Any] | None = None) -> list[Any]: - if values is None: - values = {} - c = [] - for t in conditioning: - n = [t[0], t[1].copy()] - for k in values: - n[1][k] = values[k] - c.append(n) - - return c - - def pillow(fn: Callable[[Any], T], arg: Any) -> T: prev_value = None try: @@ -39,22 +25,3 @@ def pillow(fn: Callable[[Any], T], arg: Any) -> T: def hasher() -> Callable[[], Any]: hashfuncs = {"md5": hashlib.md5, "sha1": hashlib.sha1, "sha256": hashlib.sha256, "sha512": hashlib.sha512} return hashfuncs[args.default_hashing_function] - - -def string_to_torch_dtype(string: str) -> torch.dtype | None: - if string == "fp32": - return torch.float32 - if string == "fp16": - return torch.float16 - if string == "bf16": - return torch.bfloat16 - return None - - -def image_alpha_fix(destination: torch.Tensor, source: torch.Tensor) -> tuple[torch.Tensor, torch.Tensor]: - if destination.shape[-1] < source.shape[-1]: - source = source[..., :destination.shape[-1]] - elif destination.shape[-1] > source.shape[-1]: - destination = torch.nn.functional.pad(destination, (0, 1)) - destination[..., -1] = 1.0 - return destination, source diff --git a/comfyui/video_generator/video_generator.py b/comfyui/video_generator/video_generator.py index dbcdac670..4357d0173 100644 --- a/comfyui/video_generator/video_generator.py +++ b/comfyui/video_generator/video_generator.py @@ -16,11 +16,6 @@ from fastvideo import VideoGenerator as FastVideoGenerator sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__)))))) -# Custom exception for interruption -class GenerationInterruptedException(Exception): - pass - - # Custom exception for interruption that ComfyUI will recognize class GenerationCancelledException(Exception): diff --git a/examples/inference/basic/basic_hy15.py b/examples/inference/basic/basic_hy15.py index a9dc3d141..6d3f6a7bd 100644 --- a/examples/inference/basic/basic_hy15.py +++ b/examples/inference/basic/basic_hy15.py @@ -1,5 +1,4 @@ from fastvideo import VideoGenerator -import json # from fastvideo.api.sampling_param import SamplingParam OUTPUT_PATH = "video_samples_hy15" diff --git a/examples/inference/basic/basic_hy15_1080p.py b/examples/inference/basic/basic_hy15_1080p.py index 29ce70152..99c34a622 100644 --- a/examples/inference/basic/basic_hy15_1080p.py +++ b/examples/inference/basic/basic_hy15_1080p.py @@ -1,5 +1,4 @@ from fastvideo import VideoGenerator -import json # from fastvideo.api.sampling_param import SamplingParam OUTPUT_PATH = "video_samples_hy15_1080p" diff --git a/examples/inference/basic/basic_self_forcing_causal.py b/examples/inference/basic/basic_self_forcing_causal.py index 3937226ec..8916cded3 100644 --- a/examples/inference/basic/basic_self_forcing_causal.py +++ b/examples/inference/basic/basic_self_forcing_causal.py @@ -1,5 +1,3 @@ -import os -import time from fastvideo import VideoGenerator, SamplingParam OUTPUT_PATH = "video_samples_causal" diff --git a/examples/inference/basic/mlx_wan_prompt_to_video.py b/examples/inference/basic/mlx_wan_prompt_to_video.py index 2fd62b79f..5e86b1e24 100644 --- a/examples/inference/basic/mlx_wan_prompt_to_video.py +++ b/examples/inference/basic/mlx_wan_prompt_to_video.py @@ -484,17 +484,6 @@ def _postprocess_video(*, video_path: Path, fps: int, rife: dict | None = None, print(f"[post] {', '.join(labels)} written to {video_path}") -def _rife_interpolate_video(*, video_path: Path, target_frames: int, factor: int, - sharpen: float, fps: int) -> None: - """Read the reduced-frame mp4, RIFE-interpolate up to ``target_frames`` on - Apple Silicon, optionally light-sharpen, and rewrite the file in place.""" - _postprocess_video( - video_path=video_path, - fps=fps, - rife={"factor": factor, "target_frames": target_frames, "sharpen": sharpen}, - ) - - def main() -> None: parser = argparse.ArgumentParser( description="Prompt-to-video FastMetal-QAD generation using the Apple Silicon MLX runtime") diff --git a/examples/inference/gradio/local/gradio_local_demo.py b/examples/inference/gradio/local/gradio_local_demo.py index 3a76aabd5..8854eaf5b 100644 --- a/examples/inference/gradio/local/gradio_local_demo.py +++ b/examples/inference/gradio/local/gradio_local_demo.py @@ -1,6 +1,5 @@ import argparse import os -import base64 import time import gradio as gr diff --git a/examples/inference/gradio/local/gradio_local_demo_ltx2_3/ui.py b/examples/inference/gradio/local/gradio_local_demo_ltx2_3/ui.py index 6b25744ae..9a196225a 100644 --- a/examples/inference/gradio/local/gradio_local_demo_ltx2_3/ui.py +++ b/examples/inference/gradio/local/gradio_local_demo_ltx2_3/ui.py @@ -11,7 +11,6 @@ from fastvideo.entrypoints.video_generator import VideoGenerator from .config import ( DEFAULT_FPS, DEFAULT_HEIGHT, - DEFAULT_NEGATIVE_PROMPT, DEFAULT_NUM_FRAMES, DEFAULT_NUM_INFERENCE_STEPS, DEFAULT_WIDTH, diff --git a/examples/inference/lora/wan_lora_inference.py b/examples/inference/lora/wan_lora_inference.py index 1b42be28b..447148638 100644 --- a/examples/inference/lora/wan_lora_inference.py +++ b/examples/inference/lora/wan_lora_inference.py @@ -1,5 +1,4 @@ from fastvideo import VideoGenerator -from fastvideo.api.sampling_param import SamplingParam OUTPUT_PATH = "./lora_out" diff --git a/examples/inference/lora/wan_lora_inference_from_ckpt.py b/examples/inference/lora/wan_lora_inference_from_ckpt.py index 99f6bb1c3..0fa3cd209 100644 --- a/examples/inference/lora/wan_lora_inference_from_ckpt.py +++ b/examples/inference/lora/wan_lora_inference_from_ckpt.py @@ -2,7 +2,6 @@ Inference using a LoRA checkpoint from FastVideo trainer. """ from fastvideo import VideoGenerator -from fastvideo.api.sampling_param import SamplingParam OUTPUT_PATH = "./lora_out" diff --git a/fastvideo-kernel/attn_qat_infer/quantization/bench/bench_utils.py b/fastvideo-kernel/attn_qat_infer/quantization/bench/bench_utils.py index e757efcad..fcc797d0e 100644 --- a/fastvideo-kernel/attn_qat_infer/quantization/bench/bench_utils.py +++ b/fastvideo-kernel/attn_qat_infer/quantization/bench/bench_utils.py @@ -159,13 +159,6 @@ def bench_kineto(fn, return tuple(kernel_times) if is_tupled else kernel_times[0] -def calc_diff(x, y): - x, y = x.double(), y.double() - denominator = (x * x + y * y).sum() - sim = 2 * (x * y).sum() / denominator - return 1 - sim - - def count_bytes(tensors): total = 0 for t in tensors: diff --git a/fastvideo-kernel/python/fastvideo_kernel/triton_kernels/attn_qat_vsa_reference.py b/fastvideo-kernel/python/fastvideo_kernel/triton_kernels/attn_qat_vsa_reference.py index ed42b9977..dc2b03c5e 100644 --- a/fastvideo-kernel/python/fastvideo_kernel/triton_kernels/attn_qat_vsa_reference.py +++ b/fastvideo-kernel/python/fastvideo_kernel/triton_kernels/attn_qat_vsa_reference.py @@ -193,12 +193,6 @@ def invert_block_lists(q2k_idx: torch.Tensor, q2k_num: torch.Tensor, return k2q_idx[..., :n_qblocks].contiguous(), k2q_slot[..., :n_qblocks].contiguous(), k2q_num.contiguous() -def visit_order(q2k_idx: torch.Tensor, q2k_num: torch.Tensor, b: int, h: int, m: int) -> list[int]: - """Blocks query block ``m`` visits, in kernel order (last list entry first).""" - count = int(q2k_num[b, h, m]) - return [int(block) for block in q2k_idx[b, h, m, :count].flip(0)] - - @torch.no_grad() def fp4_vsa_attention_reference(q: torch.Tensor, k: torch.Tensor, diff --git a/fastvideo-kernel/python/fastvideo_kernel/triton_kernels/index.py b/fastvideo-kernel/python/fastvideo_kernel/triton_kernels/index.py index be7c5c379..269e6e65c 100644 --- a/fastvideo-kernel/python/fastvideo_kernel/triton_kernels/index.py +++ b/fastvideo-kernel/python/fastvideo_kernel/triton_kernels/index.py @@ -6,29 +6,6 @@ import triton.language as tl import torch -@triton.jit -def topk_index_to_map_kernel( - map_ptr, - index_ptr, - map_bs_stride, - map_h_stride, - map_q_stride, - map_kv_stride, - index_bs_stride, - index_h_stride, - index_q_stride, - index_kv_stride, - topk, -): - b, h, q = tl.program_id(0), tl.program_id(1), tl.program_id(2) - index_ptr_base = index_ptr + b * index_bs_stride + h * index_h_stride + q * index_q_stride - map_ptr_base = map_ptr + b * map_bs_stride + h * map_h_stride + q * map_q_stride - - for i in tl.static_range(topk): - index = tl.load(index_ptr_base + i * index_kv_stride) - tl.store(map_ptr_base + index * map_kv_stride, 1.0) - - @triton.jit def map_to_index_kernel( map_ptr, @@ -61,48 +38,6 @@ def map_to_index_kernel( tl.store(index_num_ptr + b * index_num_bs_stride + h * index_num_h_stride + q * index_num_q_stride, num) -def topk_index_to_map(index: torch.Tensor, num_kv_blocks: int, transpose_map: bool = False): - """ - Convert topk indices to a map. - - Args: - index: [bs, h, num_q_blocks, topk] - The topk indices tensor. - num_kv_blocks: int - The number of key-value blocks in the block_map returned - transpose_map: bool - If True, the block_map will be transposed on the final two dimensions. - - Returns: - block_map: [bs, h, num_q_blocks, num_kv_blocks] - A binary map where 1 indicates that the q block attends to the kv block. - """ - bs, h, num_q_blocks, topk = index.shape - - if transpose_map is False: - block_map = torch.zeros((bs, h, num_q_blocks, num_kv_blocks), dtype=torch.bool, device=index.device) - else: - block_map = torch.zeros((bs, h, num_kv_blocks, num_q_blocks), dtype=torch.bool, device=index.device) - block_map = block_map.transpose(2, 3) - - grid = (bs, h, num_q_blocks) - topk_index_to_map_kernel[grid]( - block_map, - index, - block_map.stride(0), - block_map.stride(1), - block_map.stride(2), - block_map.stride(3), - index.stride(0), - index.stride(1), - index.stride(2), - index.stride(3), - topk=topk, - ) - - return block_map - - def map_to_index(block_map: torch.Tensor): """ Convert a block map to indices and counts. diff --git a/fastvideo-kernel/python/fastvideo_kernel/triton_kernels/st_attn_triton.py b/fastvideo-kernel/python/fastvideo_kernel/triton_kernels/st_attn_triton.py index 4ea18f2d2..6c70ae6ed 100644 --- a/fastvideo-kernel/python/fastvideo_kernel/triton_kernels/st_attn_triton.py +++ b/fastvideo-kernel/python/fastvideo_kernel/triton_kernels/st_attn_triton.py @@ -8,11 +8,6 @@ def is_cuda(): return triton.runtime.driver.active.get_current_target().backend == "cuda" -def is_hip(): - target = triton.runtime.driver.active.get_current_target() - return target.backend == 'hip' - - def is_cdna3_cdna4(): target = triton.runtime.driver.active.get_current_target() return (target.arch == 'gfx1201' or target.arch == 'gfx1101' or target.arch == 'gfx1100' diff --git a/fastvideo-kernel/python/fastvideo_kernel/turbodiffusion_ops.py b/fastvideo-kernel/python/fastvideo_kernel/turbodiffusion_ops.py index 092e2f55f..e711e24ac 100644 --- a/fastvideo-kernel/python/fastvideo_kernel/turbodiffusion_ops.py +++ b/fastvideo-kernel/python/fastvideo_kernel/turbodiffusion_ops.py @@ -1,9 +1,8 @@ from __future__ import annotations -from typing import Optional, Tuple +from typing import Tuple import torch import torch.nn as nn -import torch.nn.functional as F import triton import triton.language as tl diff --git a/fastvideo/attention/backends/abstract.py b/fastvideo/attention/backends/abstract.py index 1d25a7c19..d61586578 100644 --- a/fastvideo/attention/backends/abstract.py +++ b/fastvideo/attention/backends/abstract.py @@ -4,7 +4,7 @@ import re from abc import ABC, abstractmethod from dataclasses import dataclass, field, fields -from typing import TYPE_CHECKING, Any, Generic, Protocol, TypeVar +from typing import TYPE_CHECKING, Any, Generic, TypeVar if TYPE_CHECKING: pass @@ -220,24 +220,6 @@ class AttentionMetadataBuilder(ABC, Generic[T]): raise NotImplementedError -class AttentionLayer(Protocol): - - _k_scale: torch.Tensor - _v_scale: torch.Tensor - _k_scale_float: float - _v_scale_float: float - - def forward( - self, - query: torch.Tensor, - key: torch.Tensor, - value: torch.Tensor, - kv_cache: torch.Tensor, - attn_metadata: AttentionMetadata, - ) -> torch.Tensor: - ... - - class AttentionImpl(ABC, Generic[T]): @abstractmethod diff --git a/fastvideo/attention/backends/flash_attn.py b/fastvideo/attention/backends/flash_attn.py index 295ef6631..e8b1a183b 100644 --- a/fastvideo/attention/backends/flash_attn.py +++ b/fastvideo/attention/backends/flash_attn.py @@ -248,22 +248,6 @@ class FlashAttnMetadata(AttentionMetadata): attn_mask: torch.Tensor | None = None -class FlashAttnMetadataBuilder(AttentionMetadataBuilder): - - def __init__(self): - pass - - def prepare(self): - pass - - def build( # type: ignore - self, - current_timestep: int, - attn_mask: torch.Tensor, - ) -> FlashAttnMetadata: - return FlashAttnMetadata(current_timestep=current_timestep, attn_mask=attn_mask) - - class FlashAttentionImpl(AttentionImpl): def __init__( diff --git a/fastvideo/attention/utils/flash_attn_no_pad.py b/fastvideo/attention/utils/flash_attn_no_pad.py index 681033f1d..dc8880f96 100644 --- a/fastvideo/attention/utils/flash_attn_no_pad.py +++ b/fastvideo/attention/utils/flash_attn_no_pad.py @@ -100,58 +100,6 @@ def flash_attn_no_pad( return output -def flash_attn_no_pad_v3( - qkv: torch.Tensor, - key_padding_mask: torch.Tensor, - causal: bool = False, - dropout_p: float = 0.0, - softmax_scale: float | None = None, - deterministic: bool = False, -) -> torch.Tensor: - from flash_attn_interface import ( - flash_attn_varlen_func as flash_attn_varlen_func_v3, ) - - if flash_attn_varlen_func_v3 is None: - raise ImportError("FlashAttention V3 backend not available") - - batch_size, seqlen, _, nheads, head_dim = qkv.shape - query, key, value = qkv.unbind(dim=2) - - query_unpad, indices, cu_seqlens_q, max_seqlen_q, _ = unpad_input(rearrange(query, "b s h d -> b s (h d)"), - key_padding_mask) - key_unpad, _, cu_seqlens_k, _, _ = unpad_input(rearrange(key, "b s h d -> b s (h d)"), key_padding_mask) - value_unpad, _, _, _, _ = unpad_input(rearrange(value, "b s h d -> b s (h d)"), key_padding_mask) - - query_unpad = rearrange(query_unpad, "nnz (h d) -> nnz h d", h=nheads) - key_unpad = rearrange(key_unpad, "nnz (h d) -> nnz h d", h=nheads) - value_unpad = rearrange(value_unpad, "nnz (h d) -> nnz h d", h=nheads) - - output_unpad = flash_attn_varlen_func_v3( - query_unpad, - key_unpad, - value_unpad, - cu_seqlens_q, - cu_seqlens_k, - max_seqlen_q, - max_seqlen_q, - softmax_scale=softmax_scale, - causal=causal, - deterministic=deterministic, - ) - - output = rearrange( - pad_input( - rearrange(output_unpad, "nnz h d -> nnz (h d)"), - indices, - batch_size, - seqlen, - ), - "b s (h d) -> b s h d", - h=nheads, - ) - return output - - def flash_attn_varlen_qk_no_pad( query: torch.Tensor, key: torch.Tensor, diff --git a/fastvideo/dataset/parquet_dataset_map_style.py b/fastvideo/dataset/parquet_dataset_map_style.py index eb35d91f4..865e650db 100644 --- a/fastvideo/dataset/parquet_dataset_map_style.py +++ b/fastvideo/dataset/parquet_dataset_map_style.py @@ -22,7 +22,6 @@ import tqdm # Dataset from torch.utils.data import Dataset, Sampler from torchdata.stateful_dataloader import StatefulDataLoader -from fastvideo.platforms import current_platform from fastvideo.dataset.sequence_capacity import ( select_sequence_capacity, diff --git a/fastvideo/distributed/parallel_state.py b/fastvideo/distributed/parallel_state.py index 4fbb0a1d1..e267b8bce 100644 --- a/fastvideo/distributed/parallel_state.py +++ b/fastvideo/distributed/parallel_state.py @@ -110,10 +110,6 @@ def all_reduce(tensor: torch.Tensor, group_name: str) -> torch.Tensor: return group._all_reduce_out_place(tensor) -def all_reduce_fake(tensor: torch.Tensor, group_name: str) -> torch.Tensor: - return torch.empty_like(tensor) - - class GroupCoordinator: """ PyTorch ProcessGroup wrapper for a group of processes. @@ -734,11 +730,6 @@ def get_tp_group() -> GroupCoordinator: _ENABLE_CUSTOM_ALL_REDUCE = True -def set_custom_all_reduce(enable: bool): - global _ENABLE_CUSTOM_ALL_REDUCE - _ENABLE_CUSTOM_ALL_REDUCE = enable - - def init_distributed_environment( world_size: int = 1, rank: int = 0, diff --git a/fastvideo/entrypoints/cli/utils.py b/fastvideo/entrypoints/cli/utils.py index 1c119fbb9..e60b0fd34 100644 --- a/fastvideo/entrypoints/cli/utils.py +++ b/fastvideo/entrypoints/cli/utils.py @@ -1,6 +1,5 @@ # SPDX-License-Identifier: Apache-2.0 -import argparse import os import subprocess import sys @@ -10,12 +9,6 @@ from fastvideo.logger import init_logger logger = init_logger(__name__) -class RaiseNotImplementedAction(argparse.Action): - - def __call__(self, parser, namespace, values, option_string=None): - raise NotImplementedError(f"The {option_string} option is not yet implemented") - - def launch_distributed(num_gpus: int, args: list[str], master_port: int | None = None) -> int: """ Launch a distributed job with the given arguments diff --git a/fastvideo/eval/metrics/optical_flow/synthetic_optical_flow/_thirdperson.py b/fastvideo/eval/metrics/optical_flow/synthetic_optical_flow/_thirdperson.py index 4f372784a..d0dae5285 100644 --- a/fastvideo/eval/metrics/optical_flow/synthetic_optical_flow/_thirdperson.py +++ b/fastvideo/eval/metrics/optical_flow/synthetic_optical_flow/_thirdperson.py @@ -207,126 +207,3 @@ PARAM_NAMES = ( "r_z", "r_y", ) - - -def predict_flow_at_pixels( - keyboard: np.ndarray, # (6,) - mouse: np.ndarray, # (2,) - xs_centered: np.ndarray, # (N,) pixel x relative to principal point - ys_centered: np.ndarray, # (N,) - cal: ThirdPersonCalibration, - mouse_pitch_sign: int, -) -> np.ndarray: - """Vectorized flow prediction at an arbitrary pixel set. Returns (N, 2). - - Stateless: assumes camera is level (theta_pitch=0). For 3P games where - the camera tilts independently of the avatar's facing, use - :func:`predict_flow_at_pixels_stateful` and pass the integrated pitch. - """ - omega, T = ThirdPersonFlowGenerator._action_to_kinematics( - keyboard, - mouse, - cal, - mouse_pitch_sign, - ) - wx, wy, wz = omega - Tx, Ty, Tz = T - f = cal.focal_length - - xy_over_f = xs_centered * ys_centered / f - f_plus_x2_over_f = f + xs_centered**2 / f - f_plus_y2_over_f = f + ys_centered**2 / f - - u_R = xy_over_f * wx - f_plus_x2_over_f * wy + ys_centered * wz - v_R = f_plus_y2_over_f * wx - xy_over_f * wy - xs_centered * wz - u_T = -f * Tx + xs_centered * Tz - v_T = -f * Ty + ys_centered * Tz - return np.stack([u_R + u_T, v_R + v_T], axis=-1) - - -def predict_flow_at_pixels_stateful( - keyboard: np.ndarray, - mouse: np.ndarray, - xs_centered: np.ndarray, - ys_centered: np.ndarray, - cal: ThirdPersonCalibration, - theta_pitch: float, -) -> np.ndarray: - """Stateful flow prediction that accounts for accumulated camera pitch. - - In a 3P game the avatar moves in the world's horizontal plane in the - direction the camera is yawed. When the camera is also pitched - (looking down at the avatar / up at the sky), this world-horizontal - motion has a non-zero y component in the camera frame. Concretely: - - T_cam = β_fwd · (W − S) · (0, sin θ_pitch, cos θ_pitch) - + β_strafe · (D − A) · (1, 0, 0) # strafe is pitch-invariant - - Yaw doesn't appear because the camera frame is yaw-aligned by construction - (avatar and camera yaw together). Mouse rotation contributions to ω are - unchanged. - - Parameters - ---------- - theta_pitch : float (radians) - Accumulated camera pitch state at this frame, integrated from - prior mouse-pitch input. Positive = camera looking up. - """ - f = cal.focal_length - cos_p = float(np.cos(theta_pitch)) - sin_p = float(np.sin(theta_pitch)) - - # Rotational velocities (unchanged from stateless) - pitch_in = float(mouse[0]) - yaw_in = float(mouse[1]) - omega_x = cal.alpha_pitch * pitch_in - omega_y = cal.alpha_yaw * yaw_in - if keyboard.shape[0] >= 6: - omega_y += cal.alpha_turn * (keyboard[5] - keyboard[4]) - - # Avatar-frame translations (in world-horizontal plane, avatar-yaw-aligned) - avatar_strafe = cal.beta_strafe * (keyboard[3] - keyboard[2]) - avatar_fwd = cal.beta_fwd * (keyboard[0] - keyboard[1]) - - # Map to camera frame using current pitch - Tx = avatar_strafe - Ty = avatar_fwd * sin_p - Tz = avatar_fwd * cos_p - - xy_over_f = xs_centered * ys_centered / f - f_plus_x2_over_f = f + xs_centered**2 / f - f_plus_y2_over_f = f + ys_centered**2 / f - - u_R = xy_over_f * omega_x - f_plus_x2_over_f * omega_y - v_R = f_plus_y2_over_f * omega_x - xy_over_f * omega_y - u_T = -f * Tx + xs_centered * Tz - v_T = -f * Ty + ys_centered * Tz - return np.stack([u_R + u_T, v_R + v_T], axis=-1) - - -def integrate_pitch_state( - mouse: np.ndarray, # (T, 2) raw or cached actions - cal: ThirdPersonCalibration, - *, - init_pitch: float = 0.0, - frames_per_step: int = 1, -) -> np.ndarray: - """Integrate per-frame mouse-pitch input into accumulated camera pitch. - - Returns a (T,) array where ``out[t]`` is the camera's accumulated pitch - angle (radians) AT THE START of frame ``t`` — i.e. the pose under which - frame ``t``'s action is interpreted. - - For raw-frame action sequences pass ``frames_per_step=1``. For cached - actions where each sample represents N raw frames of integration - (cache stride = N), pass ``frames_per_step=N``. - - NOTE: this only models the explicit user-input pitch. Cinematic - auto-pitch (camera tilting to track the avatar over uneven terrain) - isn't in the action stream and isn't captured here. For that you need - visual odometry (Option B / WorldCam-style ViPE pipeline). - """ - per_step = cal.alpha_pitch * np.asarray(mouse[:, 0], dtype=np.float64) * frames_per_step - cum = np.cumsum(per_step) - # out[t] = pose BEFORE frame t's input is applied → shift by one - return init_pitch + np.concatenate([[0.0], cum[:-1]]).astype(np.float64) diff --git a/fastvideo/layers/fp4linear.py b/fastvideo/layers/fp4linear.py index 04ab6bf3f..c8a166d19 100644 --- a/fastvideo/layers/fp4linear.py +++ b/fastvideo/layers/fp4linear.py @@ -105,11 +105,3 @@ class _LinearFWD4BWD16Fn(torch.autograd.Function): # None for the three extra forward args return grad_x, grad_w, grad_b, None, None, None - - -def fp4_linear_forward(self, x: torch.Tensor) -> tuple[torch.Tensor, torch.Tensor | None]: - # pass config **positionally**; autograd.Function.apply ignores kwargs - bias = self.bias if not self.skip_bias_add else None - output = _LinearFWD4BWD16Fn.apply(x, self.weight, bias, "cutlass", 16, True) - output_bias = self.bias if self.skip_bias_add else None - return output, output_bias diff --git a/fastvideo/layers/fp8linear.py b/fastvideo/layers/fp8linear.py index 05b8e464f..079a345a1 100644 --- a/fastvideo/layers/fp8linear.py +++ b/fastvideo/layers/fp8linear.py @@ -121,8 +121,3 @@ class _LinearFWD8BWD16Fn(torch.autograd.Function): # None for the extra forward arg (granularity) return grad_x, grad_w, grad_b, None - - -def fp8_linear_forward(self, x: torch.Tensor) -> torch.Tensor: - # pass config **positionally**; autograd.Function.apply ignores kwargs - return _LinearFWD8BWD16Fn.apply(x, self.weight, self.bias, "tensor"), None diff --git a/fastvideo/layers/rotary_embedding.py b/fastvideo/layers/rotary_embedding.py index cd8cf59e5..eff5b00ad 100644 --- a/fastvideo/layers/rotary_embedding.py +++ b/fastvideo/layers/rotary_embedding.py @@ -34,19 +34,6 @@ from fastvideo.logger import init_logger logger = init_logger(__name__) -def _rotate_neox(x: torch.Tensor) -> torch.Tensor: - x1 = x[..., :x.shape[-1] // 2] - x2 = x[..., x.shape[-1] // 2:] - return torch.cat((-x2, x1), dim=-1) - - -def _rotate_gptj(x: torch.Tensor) -> torch.Tensor: - x1 = x[..., ::2] - x2 = x[..., 1::2] - x = torch.stack((-x2, x1), dim=-1) - return x.flatten(-2) - - def apply_rotary_emb( x: torch.Tensor, freqs_cis: torch.Tensor | tuple[torch.Tensor, torch.Tensor], diff --git a/fastvideo/mlx_runtime/fastwan.py b/fastvideo/mlx_runtime/fastwan.py index 7cc7eea66..314578896 100644 --- a/fastvideo/mlx_runtime/fastwan.py +++ b/fastvideo/mlx_runtime/fastwan.py @@ -7,7 +7,6 @@ from __future__ import annotations import json import math import statistics -import time from dataclasses import dataclass from pathlib import Path from typing import TYPE_CHECKING, Any @@ -146,85 +145,10 @@ def fastwan_shape_from_config( ) -def replace_tokens(shape: FastWanShape, tokens: int) -> FastWanShape: - return FastWanShape(**{**shape.__dict__, "tokens": tokens}) - - def median_ms(samples: list[float]) -> float: return statistics.median(samples) * 1000.0 -def benchmark_mlx_attention(shape: FastWanShape, warmup: int, iters: int) -> float: - import mlx.core as mx - - q = mx.random.normal((1, shape.num_heads, shape.tokens, shape.head_dim), dtype=mx.float16) - k = mx.random.normal((1, shape.num_heads, shape.tokens, shape.head_dim), dtype=mx.float16) - v = mx.random.normal((1, shape.num_heads, shape.tokens, shape.head_dim), dtype=mx.float16) - scale = shape.head_dim**-0.5 - - for _ in range(warmup): - y = mx.fast.scaled_dot_product_attention(q, k, v, scale=scale) - mx.eval(y) - - samples = [] - for _ in range(iters): - start = time.perf_counter() - y = mx.fast.scaled_dot_product_attention(q, k, v, scale=scale) - mx.eval(y) - samples.append(time.perf_counter() - start) - return median_ms(samples) - - -def benchmark_mlx_linear(shape: FastWanShape, warmup: int, iters: int) -> float: - import mlx.core as mx - - x = mx.random.normal((shape.tokens, shape.hidden_size), dtype=mx.float16) - w = mx.random.normal((shape.hidden_size, shape.hidden_size), dtype=mx.float16) - b = mx.zeros((shape.hidden_size, ), dtype=mx.float16) - - for _ in range(warmup): - y = x @ w + b - mx.eval(y) - - samples = [] - for _ in range(iters): - start = time.perf_counter() - y = x @ w + b - mx.eval(y) - samples.append(time.perf_counter() - start) - return median_ms(samples) - - -def benchmark_torch_mps_attention(shape: FastWanShape, warmup: int, iters: int) -> float | None: - try: - import torch - import torch.nn.functional as F - except ImportError: - return None - - if not torch.backends.mps.is_available(): - return None - - device = torch.device("mps") - q = torch.randn((1, shape.num_heads, shape.tokens, shape.head_dim), device=device, dtype=torch.float16) - k = torch.randn((1, shape.num_heads, shape.tokens, shape.head_dim), device=device, dtype=torch.float16) - v = torch.randn((1, shape.num_heads, shape.tokens, shape.head_dim), device=device, dtype=torch.float16) - - for _ in range(warmup): - y = F.scaled_dot_product_attention(q, k, v) - torch.mps.synchronize() - _ = y - - samples = [] - for _ in range(iters): - start = time.perf_counter() - y = F.scaled_dot_product_attention(q, k, v) - torch.mps.synchronize() - _ = y - samples.append(time.perf_counter() - start) - return median_ms(samples) - - def torch_to_mx(tensor) -> mx.array: import mlx.core as mx @@ -869,10 +793,6 @@ def mx_split_two(x, *, axis: int): return left, right -def _load_safetensor_value(handle, name: str): - return handle.get_tensor(name) - - def _load_mx_array_from_safetensor(handle, name: str, dtype): """Load a safetensors value and cast before creating the MLX array. diff --git a/fastvideo/mlx_runtime/minimax_h3_vision.py b/fastvideo/mlx_runtime/minimax_h3_vision.py index 4f9333a1d..5651e5e45 100644 --- a/fastvideo/mlx_runtime/minimax_h3_vision.py +++ b/fastvideo/mlx_runtime/minimax_h3_vision.py @@ -31,7 +31,6 @@ from __future__ import annotations import json import math -import struct from collections.abc import Mapping from dataclasses import dataclass from pathlib import Path @@ -752,17 +751,6 @@ def read_vision_index_header(component_dir: str | Path) -> dict[str, Any]: index.close() -def safetensors_bf16_available(path: str | Path) -> bool: - """True when ``path`` is a readable safetensors shard (header probe).""" - try: - with open(path, "rb") as handle: - (header_len, ) = struct.unpack(" tuple[str, ...]: return tuple(vsa_gate_key(index) for index in range(num_layers)) -def is_vsa_gate_key(key: str) -> bool: - return key.endswith(VSA_GATE_KEY_SUFFIX) - - def dense_only_vsa_error(checkpoint_dir: str | Any) -> DenseOnlyVSACheckpointError: return DenseOnlyVSACheckpointError( f"VSA was requested but {checkpoint_dir} is a dense-only MLX H3 checkpoint " diff --git a/fastvideo/models/dits/cosmos2_5.py b/fastvideo/models/dits/cosmos2_5.py index c35bd88e9..bfba10136 100644 --- a/fastvideo/models/dits/cosmos2_5.py +++ b/fastvideo/models/dits/cosmos2_5.py @@ -1,6 +1,5 @@ # SPDX-License-Identifier: Apache-2.0 -import math from typing import Any import numpy as np @@ -10,7 +9,6 @@ from torchvision import transforms from fastvideo.attention import DistributedAttention, LocalAttention from fastvideo.configs.models.dits.cosmos2_5 import Cosmos25VideoConfig -from fastvideo.forward_context import get_forward_context from fastvideo.layers.layernorm import RMSNorm from fastvideo.layers.linear import ReplicatedLinear from fastvideo.layers.mlp import MLP diff --git a/fastvideo/models/dits/gen3c.py b/fastvideo/models/dits/gen3c.py index e00cf9795..0a1a21459 100644 --- a/fastvideo/models/dits/gen3c.py +++ b/fastvideo/models/dits/gen3c.py @@ -12,7 +12,6 @@ Key Features: Reference: https://arxiv.org/abs/2503.03751 """ -import math from typing import Any import numpy as np @@ -27,7 +26,6 @@ from fastvideo.distributed.communication_op import ( sequence_model_parallel_shard, ) from fastvideo.distributed.parallel_state import get_sp_world_size -from fastvideo.forward_context import get_forward_context from fastvideo.layers.layernorm import RMSNorm from fastvideo.layers.linear import ReplicatedLinear from fastvideo.layers.mlp import MLP diff --git a/fastvideo/models/dits/hyworld/camera_rope.py b/fastvideo/models/dits/hyworld/camera_rope.py index 8f1463e9c..0f3e876d7 100644 --- a/fastvideo/models/dits/hyworld/camera_rope.py +++ b/fastvideo/models/dits/hyworld/camera_rope.py @@ -57,7 +57,6 @@ from functools import partial from typing import Callable, Optional, Tuple, List import torch -import torch.nn.functional as F def prope_qkv( diff --git a/fastvideo/models/dits/hyworld/retrieval_context.py b/fastvideo/models/dits/hyworld/retrieval_context.py index e5ccf3343..6887a5d72 100644 --- a/fastvideo/models/dits/hyworld/retrieval_context.py +++ b/fastvideo/models/dits/hyworld/retrieval_context.py @@ -18,7 +18,7 @@ import torch import numpy as np -from typing import List, Tuple, Dict +from typing import List, Tuple import math diff --git a/fastvideo/models/dits/magi_human.py b/fastvideo/models/dits/magi_human.py index 88d7d13bf..e77d9a4d6 100644 --- a/fastvideo/models/dits/magi_human.py +++ b/fastvideo/models/dits/magi_human.py @@ -41,7 +41,6 @@ For the full history and shape-by-shape verification notes, see """ from __future__ import annotations -import math from dataclasses import dataclass from enum import IntEnum from typing import Optional diff --git a/fastvideo/models/dits/matrixgame2/utils.py b/fastvideo/models/dits/matrixgame2/utils.py index 71f6981a2..ade945f6d 100644 --- a/fastvideo/models/dits/matrixgame2/utils.py +++ b/fastvideo/models/dits/matrixgame2/utils.py @@ -1,12 +1,10 @@ from __future__ import annotations import asyncio -import os import random import numpy as np import torch -from PIL import Image from fastvideo.distributed.parallel_state import get_local_torch_device from fastvideo.utils import logger @@ -395,13 +393,6 @@ async def get_current_action_async(mode="universal"): return await asyncio.to_thread(get_current_action, mode) -def load_initial_image(image_path: str = None) -> Image.Image: - if image_path and os.path.exists(image_path): - return Image.open(image_path).convert("RGB") - logger.warning("No image provided, creating placeholder...") - return Image.new("RGB", (640, 352), (128, 128, 128)) - - def create_action_presets(num_frames: int, keyboard_dim: int = 4, seed: int = None): if keyboard_dim not in (2, 4, 6, 7): raise ValueError(f"keyboard_dim must be 2, 4, 6, or 7, got {keyboard_dim}") diff --git a/fastvideo/models/encoders/qwen2_5.py b/fastvideo/models/encoders/qwen2_5.py index a94840c18..c739eed77 100644 --- a/fastvideo/models/encoders/qwen2_5.py +++ b/fastvideo/models/encoders/qwen2_5.py @@ -1,16 +1,14 @@ # SPDX-License-Identifier: Apache-2.0 # Adapted from transformers: https://github.com/huggingface/transformers/blob/main/src/transformers/models/qwen2_5_vl/modeling_qwen2_5_vl.py -import math -from typing import Any, Optional, Tuple, Union, List, Callable, Iterable +from typing import Optional, Tuple, Iterable import torch import torch.nn as nn -import torch.nn.functional as F from fastvideo.configs.models.encoders import BaseEncoderOutput, Qwen2_5_VLConfig -from fastvideo.distributed import get_tp_rank, get_tp_world_size -from fastvideo.layers.activation import get_act_fn, SiluAndMul +from fastvideo.distributed import get_tp_world_size +from fastvideo.layers.activation import SiluAndMul from fastvideo.layers.layernorm import RMSNorm from fastvideo.layers.linear import MergedColumnParallelLinear, QKVParallelLinear, RowParallelLinear from fastvideo.layers.quantization import QuantizationConfig diff --git a/fastvideo/models/encoders/vision.py b/fastvideo/models/encoders/vision.py index 603033262..f17ca00ad 100644 --- a/fastvideo/models/encoders/vision.py +++ b/fastvideo/models/encoders/vision.py @@ -1,50 +1,7 @@ # SPDX-License-Identifier: Apache-2.0 # Adapted from vllm: https://github.com/vllm-project/vllm/blob/v0.7.3/vllm/model_executor/models/vision.py -from abc import ABC, abstractmethod -from typing import Generic, TypeVar - import torch -from transformers import PretrainedConfig - -from fastvideo.logger import init_logger - -logger = init_logger(__name__) - -_C = TypeVar("_C", bound=PretrainedConfig) - - -class VisionEncoderInfo(ABC, Generic[_C]): - - def __init__(self, vision_config: _C) -> None: - super().__init__() - - self.vision_config = vision_config - - @abstractmethod - def get_num_image_tokens( - self, - *, - image_width: int, - image_height: int, - ) -> int: - raise NotImplementedError - - @abstractmethod - def get_max_image_tokens(self) -> int: - raise NotImplementedError - - @abstractmethod - def get_image_size(self) -> int: - raise NotImplementedError - - @abstractmethod - def get_patch_size(self) -> int: - raise NotImplementedError - - @abstractmethod - def get_patch_grid_length(self) -> int: - raise NotImplementedError def resolve_visual_encoder_outputs( diff --git a/fastvideo/models/hf_transformer_utils.py b/fastvideo/models/hf_transformer_utils.py index 5f26179d9..683df0315 100644 --- a/fastvideo/models/hf_transformer_utils.py +++ b/fastvideo/models/hf_transformer_utils.py @@ -22,7 +22,6 @@ import os from pathlib import Path from typing import Any -from huggingface_hub import snapshot_download from transformers import AutoConfig, PretrainedConfig from transformers.models.auto.modeling_auto import (MODEL_FOR_CAUSAL_LM_MAPPING_NAMES) @@ -38,13 +37,6 @@ for name, cls in _CONFIG_REGISTRY.items(): AutoConfig.register(name, cls) -def download_from_hf(model_path: str): - if os.path.exists(model_path): - return model_path - - return snapshot_download(model_path, allow_patterns=["*.json", "*.bin", "*.model"]) - - def get_hf_config( model: str, trust_remote_code: bool, @@ -120,14 +112,6 @@ CONTEXT_LENGTH_KEYS = [ ] -def attach_additional_stop_token_ids(tokenizer): - # Special handling for stop token <|eom_id|> generated by llama 3 tool use. - if "<|eom_id|>" in tokenizer.get_added_vocab(): - tokenizer.additional_stop_token_ids = set([tokenizer.get_added_vocab()["<|eom_id|>"]]) - else: - tokenizer.additional_stop_token_ids = None - - def check_gguf_file(model: str | os.PathLike) -> bool: """Check if the file is a GGUF model.""" model = Path(model) diff --git a/fastvideo/models/loader/component_loader.py b/fastvideo/models/loader/component_loader.py index 06c6bc693..b9fb9e2ba 100644 --- a/fastvideo/models/loader/component_loader.py +++ b/fastvideo/models/loader/component_loader.py @@ -9,7 +9,7 @@ from abc import ABC, abstractmethod from collections.abc import Generator, Iterable from contextlib import nullcontext from copy import deepcopy -from typing import Any, cast +from typing import cast import torch import torch.distributed as dist diff --git a/fastvideo/models/loader/weight_utils.py b/fastvideo/models/loader/weight_utils.py index 1361ff179..20aa0b060 100644 --- a/fastvideo/models/loader/weight_utils.py +++ b/fastvideo/models/loader/weight_utils.py @@ -58,12 +58,6 @@ def enable_hf_transfer() -> None: enable_hf_transfer() -class DisabledTqdm(tqdm): - - def __init__(self, *args, **kwargs): - super().__init__(*args, **kwargs, disable=True) - - def get_lock(model_name_or_path: str | Path, cache_dir: str | None = None): lock_dir = cache_dir or temp_dir model_name_or_path = str(model_name_or_path) diff --git a/fastvideo/models/upsamplers/hunyuan15.py b/fastvideo/models/upsamplers/hunyuan15.py index 006cb0a41..4992b64e7 100644 --- a/fastvideo/models/upsamplers/hunyuan15.py +++ b/fastvideo/models/upsamplers/hunyuan15.py @@ -15,8 +15,6 @@ # See the License for the specific language governing permissions and limitations under the License. from collections.abc import Sequence -from dataclasses import dataclass -from enum import Enum import torch import torch.nn as nn diff --git a/fastvideo/models/vaes/flux2vae.py b/fastvideo/models/vaes/flux2vae.py index c1325deec..2fcb13906 100644 --- a/fastvideo/models/vaes/flux2vae.py +++ b/fastvideo/models/vaes/flux2vae.py @@ -13,7 +13,6 @@ from fastvideo.models.vaes.common import ( from fastvideo.models.vaes.flux2_components import ( ADDED_KV_ATTENTION_PROCESSORS, CROSS_ATTENTION_PROCESSORS, - Attention, AttnAddedKVProcessor, AttnProcessor, AutoencoderKLOutput, diff --git a/fastvideo/models/vaes/ltx2vae.py b/fastvideo/models/vaes/ltx2vae.py index af347064f..41c9ceefa 100644 --- a/fastvideo/models/vaes/ltx2vae.py +++ b/fastvideo/models/vaes/ltx2vae.py @@ -13,7 +13,6 @@ from typing import Any, Callable, Iterator, List, NamedTuple, Tuple import torch import torch.nn as nn -import torch.nn.functional as F from einops import rearrange import fastvideo.envs as envs diff --git a/fastvideo/models/vaes/minimax_h3_taeh3.py b/fastvideo/models/vaes/minimax_h3_taeh3.py index 0de71db81..bdd38f38c 100644 --- a/fastvideo/models/vaes/minimax_h3_taeh3.py +++ b/fastvideo/models/vaes/minimax_h3_taeh3.py @@ -13,7 +13,6 @@ import hashlib import tempfile import urllib.request from pathlib import Path -from typing import Any import torch import torch.nn.functional as F diff --git a/fastvideo/models/wan/causal_transformer.py b/fastvideo/models/wan/causal_transformer.py index a0a33aabf..d60e57700 100644 --- a/fastvideo/models/wan/causal_transformer.py +++ b/fastvideo/models/wan/causal_transformer.py @@ -3,7 +3,6 @@ import math from typing import Any -import numpy as np import torch import torch.nn as nn @@ -15,13 +14,11 @@ from torch.nn.attention.flex_attention import BlockMask flex_attention = torch.compile(flex_attention, dynamic=False, mode="max-autotune-no-cudagraphs") import torch.distributed as dist -import fastvideo.envs as envs -from fastvideo.attention import (DistributedAttention, LocalAttention) +from fastvideo.attention import LocalAttention from fastvideo.models.wan.config import WanVideoConfig from fastvideo.distributed.communication_op import (sequence_model_parallel_all_gather) from fastvideo.distributed.parallel_state import (get_sp_parallel_rank, get_sp_world_size) -from fastvideo.forward_context import get_forward_context -from fastvideo.layers.layernorm import (FP32LayerNorm, LayerNormScaleShift, RMSNorm, ScaleResidual, +from fastvideo.layers.layernorm import (LayerNormScaleShift, RMSNorm, ScaleResidual, ScaleResidualLayerNormScaleShift) from fastvideo.layers.linear import ReplicatedLinear from fastvideo.layers.mlp import MLP diff --git a/fastvideo/pipelines/basic/pika_h3_flex/buckets.py b/fastvideo/pipelines/basic/pika_h3_flex/buckets.py index ef9891e6c..0a949a023 100644 --- a/fastvideo/pipelines/basic/pika_h3_flex/buckets.py +++ b/fastvideo/pipelines/basic/pika_h3_flex/buckets.py @@ -138,11 +138,6 @@ def canvas_for_aspect(aspect: str | tuple[float, float], tier: str | None = None ) -def aspect_families(tier: str | None = None) -> tuple[str, ...]: - del tier - return PIKA_ASPECTS - - def bucket_table(tier: str | None = None) -> tuple[tuple[int, int], ...]: """All ``(width, height)`` buckets of one tier, in :data:`PIKA_ASPECTS` order.""" return tuple((canvas_for_aspect(aspect, tier)[1], canvas_for_aspect(aspect, tier)[0]) for aspect in PIKA_ASPECTS) diff --git a/fastvideo/platforms/interface.py b/fastvideo/platforms/interface.py index ea55f7780..f86401bf9 100644 --- a/fastvideo/platforms/interface.py +++ b/fastvideo/platforms/interface.py @@ -262,8 +262,3 @@ class Platform: def get_cpu_architecture(cls) -> CpuArchEnum: """Get the CPU architecture of the current platform.""" return CpuArchEnum.UNSPECIFIED - - -class UnspecifiedPlatform(Platform): - _enum = PlatformEnum.UNSPECIFIED - device_type = "" diff --git a/fastvideo/utils.py b/fastvideo/utils.py index 3b7d29c92..019b906f8 100644 --- a/fastvideo/utils.py +++ b/fastvideo/utils.py @@ -36,7 +36,6 @@ import yaml from diffusers.loaders.lora_base import (_best_guess_weight_name) # watch out for potetential removal from diffusers from einops import rearrange from huggingface_hub import snapshot_download -from remote_pdb import RemotePdb from torch.distributed.fsdp import MixedPrecisionPolicy import fastvideo.envs as envs @@ -874,15 +873,6 @@ class TypeBasedDispatcher: raise ValueError(f"Invalid object: {obj}") -# For non-torch.distributed debugging -def remote_breakpoint() -> None: - with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as s: - s.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1) - s.bind(("localhost", 0)) # Let the OS pick an ephemeral port. - port = s.getsockname()[1] - RemotePdb(host="localhost", port=port).set_trace() - - @dataclass class MixedPrecisionState: param_dtype: torch.dtype | None = None diff --git a/scripts/benchmarks/minimax_h3_pro6000/bench_code.py b/scripts/benchmarks/minimax_h3_pro6000/bench_code.py index c45557b83..0f91fd002 100644 --- a/scripts/benchmarks/minimax_h3_pro6000/bench_code.py +++ b/scripts/benchmarks/minimax_h3_pro6000/bench_code.py @@ -1,7 +1,6 @@ """Per-component timing of one MiniMax-H3 block on the current GPU. Imported inside the Modal container.""" import json import math -import time import torch import torch.nn.functional as F @@ -160,7 +159,6 @@ def run(shapes): diff = (o_fp4[:, :, rows].float() - o_tri[:, :, rows].float()) att["quad_vs_triton_rel_l2"] = round((diff.norm() / o_tri[:, :, rows].float().norm()).item(), 4) od = sageattn_blackwell(qd, kd, vd) - from torch.nn.attention import SDPBackend, sdpa_kernel if L < 30000: ref_dense = F.scaled_dot_product_attention(qd, kd, vd) att["dense_fp4_vs_bf16_rel_l2"] = round(((od.float() - ref_dense.float()).norm() / diff --git a/scripts/checkpoint_conversion/convert_gen3c_to_fastvideo.py b/scripts/checkpoint_conversion/convert_gen3c_to_fastvideo.py index 2cc24ca34..72cd7f157 100644 --- a/scripts/checkpoint_conversion/convert_gen3c_to_fastvideo.py +++ b/scripts/checkpoint_conversion/convert_gen3c_to_fastvideo.py @@ -27,7 +27,6 @@ import re import shutil from collections import OrderedDict from pathlib import Path -from typing import Iterator import torch from safetensors.torch import save_file @@ -166,25 +165,6 @@ def load_checkpoint(path: Path, mmap: bool = True) -> dict[str, torch.Tensor]: return checkpoint -def iterate_checkpoint_keys(path: Path) -> Iterator[str]: - """Iterate over checkpoint keys without loading all tensors. - - This is useful for analysis when memory is limited. - """ - # Load with weights_only=True to just get the structure - # Unfortunately PyTorch doesn't have a great way to do this - # So we load the full checkpoint but only keep keys - checkpoint = torch.load(path, map_location="meta", weights_only=False) - - if isinstance(checkpoint, dict): - for key in ("state_dict", "model_state_dict", "model", "ema"): - if key in checkpoint: - checkpoint = checkpoint[key] - break - - return checkpoint.keys() - - def analyze_checkpoint(state_dict: dict[str, torch.Tensor]) -> None: """Print checkpoint structure analysis.""" print("\n" + "=" * 80) diff --git a/scripts/checkpoint_conversion/convert_magi_human_to_diffusers.py b/scripts/checkpoint_conversion/convert_magi_human_to_diffusers.py index 6e131affd..7c161907d 100644 --- a/scripts/checkpoint_conversion/convert_magi_human_to_diffusers.py +++ b/scripts/checkpoint_conversion/convert_magi_human_to_diffusers.py @@ -72,7 +72,7 @@ from collections import OrderedDict from pathlib import Path import torch -from huggingface_hub import hf_hub_download, snapshot_download +from huggingface_hub import snapshot_download from safetensors.torch import load_file, save_file # MagiHuman base arch — keys must be valid `MagiHumanArchConfig` fields. diff --git a/scripts/checkpoint_conversion/wan_to_diffusers.py b/scripts/checkpoint_conversion/wan_to_diffusers.py index 2f6e1a626..2538ef885 100644 --- a/scripts/checkpoint_conversion/wan_to_diffusers.py +++ b/scripts/checkpoint_conversion/wan_to_diffusers.py @@ -1,6 +1,5 @@ from huggingface_hub import save_torch_state_dict, load_state_dict_from_file # from safetensors import safetensors -from safetensors.torch import save_file import torch import re from collections import OrderedDict diff --git a/scripts/demo_anyflow_14b.py b/scripts/demo_anyflow_14b.py index 9671b5f4b..3c3c76e56 100644 --- a/scripts/demo_anyflow_14b.py +++ b/scripts/demo_anyflow_14b.py @@ -35,7 +35,6 @@ from __future__ import annotations import gc import os import re -import sys import time from pathlib import Path diff --git a/scripts/lora_extraction/upload_adapter.py b/scripts/lora_extraction/upload_adapter.py index a5435b26b..4ded2f478 100644 --- a/scripts/lora_extraction/upload_adapter.py +++ b/scripts/lora_extraction/upload_adapter.py @@ -17,7 +17,6 @@ so it cannot end up in a shell history. from __future__ import annotations import argparse -import json import logging from pathlib import Path diff --git a/scripts/lora_extraction/verify_lora.py b/scripts/lora_extraction/verify_lora.py index 69a0a88e3..b8e1a9b11 100644 --- a/scripts/lora_extraction/verify_lora.py +++ b/scripts/lora_extraction/verify_lora.py @@ -11,7 +11,6 @@ import argparse import logging from pathlib import Path -import torch from safetensors.torch import load_file LOG = logging.getLogger(__name__)