Text-to-Video
Diffusers
video-generation
test-time-search
best-of-n
caching
training-free
wan
cogvideox
hunyuanvideo
ltx-video
Instructions to use shreshthsaini/CachedSearch with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Diffusers
How to use shreshthsaini/CachedSearch with Diffusers:
pip install -U diffusers transformers accelerate
import torch from diffusers import DiffusionPipeline # switch to "mps" for apple devices pipe = DiffusionPipeline.from_pretrained("shreshthsaini/CachedSearch", dtype=torch.bfloat16, device_map="cuda") prompt = "Astronaut in a jungle, cold color palette, muted colors, detailed, 8k" image = pipe(prompt).images[0] - Notebooks
- Google Colab
- Kaggle
Download examples/run_wan.py from shreshthsaini/CachedSearch: direct link, hf CLI and curl.
- Browser
- Download file 2.01 kB
-
https://huggingface.co/shreshthsaini/CachedSearch/resolve/main/examples/run_wan.py
- Command line
-
hf download hf://shreshthsaini/CachedSearch/examples/run_wan.py
-
curl -L -o run_wan.py https://huggingface.co/shreshthsaini/CachedSearch/resolve/main/examples/run_wan.py
2.01 kB
| """End-to-end example: best-of-8 search on Wan2.1 for the price of about 5 rollouts. | |
| python examples/run_wan.py --prompt "a red fox running through deep snow" | |
| Swap the pipeline for CogVideoX, HunyuanVideo, or LTX-Video and the only thing | |
| that changes is tau (run examples/calibrate_new_model.py once for a new family). | |
| """ | |
| import argparse | |
| import torch | |
| from diffusers import AutoencoderKLWan, WanPipeline | |
| from cachedsearch import cached_search, imagereward_verifier | |
| def main(): | |
| ap = argparse.ArgumentParser() | |
| ap.add_argument("--prompt", required=True) | |
| ap.add_argument("--model", default="Wan-AI/Wan2.1-T2V-1.3B-Diffusers") | |
| ap.add_argument("--n", type=int, default=8, help="search width") | |
| ap.add_argument("--tau", type=float, default=0.10, help="caching threshold") | |
| ap.add_argument("--mode", default="commit", choices=["commit", "keep"]) | |
| ap.add_argument("--out", default="delivered.mp4") | |
| # Pass --verifier to swap in your own scorer; the default is ImageReward. | |
| args = ap.parse_args() | |
| vae = AutoencoderKLWan.from_pretrained(args.model, subfolder="vae", torch_dtype=torch.float32) | |
| pipe = WanPipeline.from_pretrained(args.model, vae=vae, torch_dtype=torch.bfloat16).to("cuda") | |
| result = cached_search( | |
| pipe, | |
| args.prompt, | |
| n=args.n, | |
| tau=args.tau, | |
| mode=args.mode, | |
| gen_kwargs=dict(height=480, width=832, num_frames=81, guidance_scale=5.0), | |
| ) | |
| print(f"winner seed : {result.seed}") | |
| print(f"draft scores : {[round(s, 3) for s in result.draft_scores]}") | |
| print(f"explore / commit : {result.explore_seconds:.0f}s / {result.commit_seconds:.0f}s") | |
| print(f"total : {result.total_seconds:.0f}s " | |
| f"(full best-of-{args.n} would cost about " | |
| f"{args.n * result.commit_seconds:.0f}s)") | |
| from diffusers.utils import export_to_video | |
| export_to_video(result.video, args.out, fps=16) | |
| print(f"wrote {args.out}") | |
| if __name__ == "__main__": | |
| main() | |