Developer docs / AI Fabric tutorials

LTX-Video text-to-video

  • GPU
  • Volume
  • Image DSL

Text-to-video is heavier than text-to-image: bigger weights, more compute, and a full clip of frames to render instead of one picture. That makes it a good job for a GPU you rent by the second. In this tutorial you'll turn a sentence into a short MP4 with LTX-Video from Lightricks, running on a single GPU with AI Fabric.

LTX-Video produces spatially and temporally consistent frames at 24 fps from a plain text prompt. Its weights are large (~14 GB), so you'll cache them on a Volume: the first run downloads them, and every run after that skips straight to generation.

Before you start

You need the AI Fabric CLI installed and authenticated: run blade setup once. The function asks for a single RTX A4500 and builds on fabric/torch, the catalog image that already ships CUDA and PyTorch, so you only layer the diffusers + video stack on top.

Set up the app, Volume, and image

Create a file called ltx_video.py. Declare the App, a Volume to cache the model weights, and the container image. Start from fabric/torch and add diffusers>=0.31.0 (the release that ships LTXPipeline) plus the encoders and an imageio build with ffmpeg for writing MP4. Pointing HF_HOME at /hf-cache sends the Hugging Face cache to the mounted Volume:

ltx_video.py
import bladekit
import io

app = bladekit.app("ltx-video")

hf_cache = bladekit.Volume.from_name("hf-cache", create_if_missing=True)

image = (
    bladekit.Image.from_catalog("fabric/torch")
    .pip_install(
        "torch", "diffusers>=0.31.0", "transformers",
        "accelerate", "safetensors", "imageio[ffmpeg]", "tiktoken", "sentencepiece", "protobuf"
    )
    .env({"HF_HOME": "/hf-cache"})
)

Load the pipeline once

Request the GPU, image, and Volume on the function. The _pipe global caches the pipeline in the warm container: the first call builds the LTXPipeline and moves it onto the GPU in bfloat16, and every later call on the same warm container reuses it, with no reload and no re-download:

Python
_pipe = None

@app.function(gpu="RTX-A4500", image=image, timeout=1800, volumes={"/hf-cache": hf_cache})
def generate_video(prompt: str, num_frames: int = 25) -> bytes:
    global _pipe
    import torch, imageio, numpy as np
    from diffusers import LTXPipeline

    if _pipe is None:
        _pipe = LTXPipeline.from_pretrained(
            "Lightricks/LTX-Video",
            torch_dtype=torch.bfloat16,
        ).to("cuda")

Generate the frames and encode an MP4

Run the pipeline at 704×480 over num_frames frames, then encode the result. result.frames[0] is the list of PIL frames for the first prompt; imageio.mimsave writes them to an in-memory buffer as an MP4 at 24 fps, and the function returns the raw bytes:

Python
    result = _pipe(
        prompt=prompt,
        num_frames=num_frames,
        width=704,
        height=480,
        num_inference_steps=50,
    )
    frames = result.frames[0]
    buf = io.BytesIO()
    imageio.mimsave(buf, [np.array(f) for f in frames], format="mp4", fps=24)
    return buf.getvalue()

Call it and save the video

A local_entrypoint runs on your laptop. Calling generate_video.remote(...) ships the prompt to the GPU container, runs generation there, and returns the MP4 bytes, which you write next to your script:

Python
@app.local_entrypoint()
def main():
    import pathlib
    mp4 = generate_video.remote("a drone flying over a mountain lake at sunrise")
    pathlib.Path("ltx-out.mp4").write_bytes(mp4)
    print(f"Saved {len(mp4) / 1e6:.1f} MB video")

Run it

Run the program with the AI Fabric CLI:

Terminal
blade run ltx_video.py

Output
Saved 0.4 MB video

The first run downloads the LTX-Video weights (~14 GB) into the Volume. That's the one-time cost. Later runs mount the cache and start generating immediately. Your clip lands at ltx-out.mp4; open it in any player.

Take it for a spin

Everything above in one file, ready to run.

ltx_video.py
import bladekit
import io

app = bladekit.app("ltx-video")

hf_cache = bladekit.Volume.from_name("hf-cache", create_if_missing=True)

image = (
    bladekit.Image.from_catalog("fabric/torch")
    .pip_install(
        "torch", "diffusers>=0.31.0", "transformers",
        "accelerate", "safetensors", "imageio[ffmpeg]", "tiktoken", "sentencepiece", "protobuf"
    )
    .env({"HF_HOME": "/hf-cache"})
)

_pipe = None

@app.function(gpu="RTX-A4500", image=image, timeout=1800, volumes={"/hf-cache": hf_cache})
def generate_video(prompt: str, num_frames: int = 25) -> bytes:
    global _pipe
    import torch, imageio, numpy as np
    from diffusers import LTXPipeline

    if _pipe is None:
        _pipe = LTXPipeline.from_pretrained(
            "Lightricks/LTX-Video",
            torch_dtype=torch.bfloat16,
        ).to("cuda")

    result = _pipe(
        prompt=prompt,
        num_frames=num_frames,
        width=704,
        height=480,
        num_inference_steps=50,
    )
    frames = result.frames[0]
    buf = io.BytesIO()
    imageio.mimsave(buf, [np.array(f) for f in frames], format="mp4", fps=24)
    return buf.getvalue()

@app.local_entrypoint()
def main():
    import pathlib
    mp4 = generate_video.remote("a drone flying over a mountain lake at sunrise")
    pathlib.Path("ltx-out.mp4").write_bytes(mp4)
    print(f"Saved {len(mp4) / 1e6:.1f} MB video")

Concepts used: Cold start, GPU, Image build

Contact the team

Loading the form…