multimodalart HF Staff commited on
Commit
4ef2b10
Β·
verified Β·
1 Parent(s): 1d5b5ac

Upload app.py with huggingface_hub

Browse files
Files changed (1) hide show
  1. app.py +34 -1
app.py CHANGED
@@ -45,10 +45,43 @@ _tokenizer_path = os.path.join(_base_dir, "google", "umt5-xxl")
45
  from env.loop_utils import load_pipeline_and_ckpt
46
  from env.run_replay_loop_two_chunk import run_one_chunk, encode_context_frames_per_frame
47
  from env.memory_baseline_runtime import MemoryProfile, infer_memory_profile_spec
48
- from inference.unified_inference import resolve_memory_profile, apply_profile_to_pipe
49
  from diffsynth import save_video
50
  from src.model_training.fov_retrieval import compute_rotation_list
51
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
52
  print("[app] Loading pipeline (DiT -> cuda)...")
53
  pipe = load_pipeline_and_ckpt(
54
  ckpt_path=_ckpt_path,
 
45
  from env.loop_utils import load_pipeline_and_ckpt
46
  from env.run_replay_loop_two_chunk import run_one_chunk, encode_context_frames_per_frame
47
  from env.memory_baseline_runtime import MemoryProfile, infer_memory_profile_spec
 
48
  from diffsynth import save_video
49
  from src.model_training.fov_retrieval import compute_rotation_list
50
 
51
+
52
+ # ── Inline helpers from inference/unified_inference.py ──────────────────────
53
+ def resolve_memory_profile(memory_type: str, ckpt_path: str) -> MemoryProfile:
54
+ """Resolve memory_type to a MemoryProfile. context_k* use default pipe flags."""
55
+ _CONTEXT_K_PROFILES = {
56
+ "context_k1": MemoryProfile(context_override=1),
57
+ "context_k5": MemoryProfile(context_override=5),
58
+ "context_k20": MemoryProfile(context_override=20),
59
+ }
60
+ if memory_type in _CONTEXT_K_PROFILES:
61
+ print(f"[app] Using context learning profile: {memory_type}")
62
+ return _CONTEXT_K_PROFILES[memory_type]
63
+ spec = infer_memory_profile_spec(ckpt_path)
64
+ if spec is not None:
65
+ print(f"[app] Auto-detected memory profile: {spec.profile_id}")
66
+ return spec.profile
67
+ return MemoryProfile()
68
+
69
+
70
+ def apply_profile_to_pipe(pipe, profile: MemoryProfile) -> None:
71
+ """Apply a MemoryProfile directly to the pipeline object."""
72
+ pipe.use_framepack_memory = bool(profile.use_framepack_memory)
73
+ pipe.context_temporal_decay = float(profile.context_temporal_decay or 1.0)
74
+ pipe.context_attention_weight = float(profile.context_attention_weight or 1.0)
75
+ pipe.use_framepack_length_compress = bool(profile.use_framepack_length_compress)
76
+ pipe.framepack_ratio = int(profile.framepack_ratio or 2)
77
+ pipe.use_spatial_memory = bool(profile.use_spatial_memory)
78
+ pipe.spatial_memory_tokens = int(profile.spatial_memory_tokens or 64)
79
+ if profile.spatial_memory_inject_mode:
80
+ pipe.spatial_memory_inject_mode = str(profile.spatial_memory_inject_mode)
81
+ pipe.use_spatial_memory_legacy = bool(profile.use_spatial_memory_legacy)
82
+ pipe.use_block_wise_ssm = bool(getattr(profile, "use_block_wise_ssm", False))
83
+ pipe.use_videossm_hybrid = bool(getattr(profile, "use_videossm_hybrid", False))
84
+
85
  print("[app] Loading pipeline (DiT -> cuda)...")
86
  pipe = load_pipeline_and_ckpt(
87
  ckpt_path=_ckpt_path,