DreamDojo Documentation

repository·main·Indexed 21 days ago

https://github.com/nvidia/dreamdojo

An interactive robot world model trained on 44,000 hours of human egocentric video. It features a foundation for robot learning via pretraining, post-training, and a distillation pipeline for real-time, long-horizon video generation. The ecosystem includes the cosmos-predict2 World Foundation Model, the Imaginaire Attention API, and cosmos-gradio for model deployment.

Tokens
17.2K
Snippets
55
Records
81
Agent score
76%

What's inside DreamDojo

  1. Overview of DreamDojo capabilities

    main

    DreamDojo provides a foundation robot world model with the following key features:

    • Large-scale Video Dataset: Access to 44k hours of diverse human egocentric videos.
    • Foundation World Model: A model capable of strong generalization to diverse objects and environments after post-training.
    • Distillation Pipeline: Enables long-horizon autoregressive generation with stable real-time interactions at 10 FPS for durations exceeding 1 minute.
  2. Understand tensor layouts for Multi-Dimensional Attention

    main

    Multi-Dimensional Attention requires a specific tensor layout. In addition to the standard contiguous heads-last layout, the "sequence length" dimension must be unrolled into its original spatial/temporal representation.

    Important Requirements:

    1. Token Layout Shape: The dimensions representing the token layout (e.g., $X, Y$ for images) must be present in the tensor shape.
    2. Shape Matching: The shapes of query, key, and value must match exactly along all dimensions of the token layout shape. This is because the API assumes query and context coordinate spaces are identical.

    Supported Layouts

    • 1-D (Language/Audio): (batch, X, heads, head_dim)
    • 2-D (Images): (batch, X, Y, heads, head_dim)
    • 3-D (Videos/3-D Images): (batch, X, Y, Z, heads, head_dim)
    # 1-D case: language, audio
    batch, X, heads, head_dim = query_1d.shape
    
    # 2-D case: images
    batch, X, Y, heads, head_dim = query_2d.shape
    
    # 3-D case: videos / 3-D images
    batch, X, Y, Z, heads, head_dim = query_3d.shape
    
    # Requirement: query, key, and value must match on layout dimensions
    assert query_2d.shape[1:3] == key_2d.shape[1:3] == value_2d.shape[1:3]
  3. Required tensor layout for Imaginaire Attention

    main

    Imaginaire Attention requires input tensors (query, key, and value) to follow a specific memory layout: heads-last torch contiguous (torch.contiguous_format).

    Tensor Shape Requirements: Inputs must be rank-4 tensors with the following dimensions:

    1. Batch size
    2. Sequence length
    3. Number of attention heads
    4. Head dimension

    Memory Layout Details: This layout is consistent with PyTorch's contiguous_format, where the right-most dimension (head dimension) is the major dimension (stride 1). Tokens from different heads are interleaved in memory.

    To ensure your tensors are correctly formatted, you can use the following verification logic:

    def verify_heads_last_contig_tensor(x: Tensor):
        assert x.shape[0] == batch
        assert x.shape[1] == seqlen
        assert x.shape[2] == heads
        assert x.shape[3] == head_dim
    
        assert x.stride(3) == 1
        assert x.stride(2) == head_dim
        assert x.stride(1) == heads * head_dim
        assert x.stride(0) == heads * head_dim * seqlen
  4. Understand the DreamDojo distillation pipeline

    main

    The distillation pipeline converts a post-trained DreamDojo teacher model into a fast, causal student model. This student model is optimized for long-horizon autoregressive generation at 10 FPS. The process follows three distinct stages:

    1. Teacher Generation: Pre-computes multi-step denoising targets from the teacher model to serve as supervision.
    2. Warmup: Trains the causal student architecture to match the teacher's denoising outputs.
    3. Self-Forcing: Finetunes the student using its own autoregressive predictions to minimize error accumulation during long-horizon generation.

    Once distillation is complete, the student model can be used for either offline video generation or real-time interactive teleoperation.

  5. Use Flash Attention v3 as an attention backend

    main

    The flash3 backend provides access to the original Flash Attention v3 C++ kernels.

    Requirements:

    • Requires the flash_attn_3 package.
    • Version required: 3.0.0.b*.

    Note: torch.compile is NOT supported for this backend.

    Feature Support (Ampere/RTX):

    • Causal mask
    • Varlen
    • GQA/MQA
    • MLA: Technically supported, but currently disabled due to an API bug in the backward pass.
  6. Install DreamDojo via Virtual Environment

    main

    Use uv to manage the environment. Note that Blackwell architecture users must use Docker; virtual environment support for Blackwell is currently in development.

    1. Install Git LFS and clone the repository:
      sudo apt install git-lfs
      git lfs install
      git clone git@github.com:nvidia-cosmos/<repository_name>.git
      cd <repository_name>
      git lfs pull
    2. Install system dependencies:
      sudo apt install curl ffmpeg tree wget
    3. Install uv:
      curl -LsSf https://astral.sh/uv/install.sh | sh
      source $HOME/.local/bin/env
    4. Sync the environment with the desired CUDA extra:
      • For CUDA 12.8: --extra=cu128
      • For CUDA 13.0: --extra=cu130

    To create a new environment:

    uv sync --extra=cu128
    source .venv/bin/activate

    To install into an existing active environment (like Conda):

    uv sync --extra=cu128 --active --inexact
  7. Handle variable length sequences in Imaginaire Attention

    main

    Imaginaire Attention supports variable length sequences via two methods.

    Option 1: Direct sequence lengths (Less efficient)

    Pass seqlens_Q and seqlens_KV directly as tensors. This method is less efficient because it manually computes maximum sequence lengths and cumulative sums (including additional padding) during every call.

    Option 2: Pre-computed parameters (More efficient)

    For better performance, compute the cumulative sequence lengths and maximums once using generate_varlen_parameters and pass these pre-computed values to the attention layer. This avoids redundant computations in subsequent layers.

    from cosmos_predict2._src.imaginaire.attention.varlen import generate_varlen_parameters
    
    # Pre-compute parameters once
    (
        cumulative_seqlen_Q,
        cumulative_seqlen_KV,
        max_seqlen_Q,
        max_seqlen_KV,
    ) = generate_varlen_parameters(query, key, value, seqlens_Q, seqlens_KV)
    
    # Use pre-computed parameters in attention layers
    output = attention(
        query=query,
        key=key,
        value=value,
        cumulative_seqlen_Q=cumulative_seqlen_Q,
        cumulative_seqlen_KV=cumulative_seqlen_KV,
        max_seqlen_Q=max_seqlen_Q,
        max_seqlen_KV=max_seqlen_KV,
    )
  8. Download and Configure Model Checkpoints

    main

    Checkpoints are automatically downloaded during inference and post-training. To access them, follow these steps:

    1. Obtain a Hugging Face Access Token with Read permission.
    2. Install the Hugging Face CLI using uv:
      uv tool install -U "huggingface_hub[cli]"
    3. Log in via the CLI:
      hf auth login
    4. Accept the NVIDIA Open Model License Agreement on Hugging Face.

    Customizing Cache Location

    To change where checkpoints are stored, set the HF_HOME environment variable.

    uv tool install -U "huggingface_hub[cli]"
    hf auth login
  9. Publish the cosmos-gradio package

    main

    Once you have built the distributions in the dist/ directory, you can publish them to PyPI using one of the following methods:

    Method 1: Using just

    If the just command is available in your environment, use the project's built-in command:

    just publish <pypi_token>

    Method 2: Using twine

    1. Install twine:
      pip install twine
    2. Upload the distributions:
      twine upload dist/*
    # Using twine
    pip install twine
    twine upload dist/*