| # Interleaved Multimodal Reasoning Dataset |
|
|
| A dataset generation framework for spatial reasoning tasks involving camera viewpoint prediction and ordering around static 3D objects. This project generates multimodal chain-of-thought reasoning traces that teach models how camera views change during orbital rotation. |
|
|
| ## Table of Contents |
|
|
| - [Overview](#overview) |
| - [Installation](#installation) |
| - [Project Structure](#project-structure) |
| - [Quick Start](#quick-start) |
| - [Usage](#usage) |
| - [Configuration](#configuration) |
| - [Development](#development) |
|
|
| ## Overview |
|
|
| This framework generates two types of spatial reasoning tasks: |
|
|
| 1. **Task 1: Camera View Prediction** - Given an initial view and rotation parameters (angle + direction), predict what the object looks like from the new viewpoint |
| 2. **Task 3: Camera View Ordering** - Given a reference frame and scrambled candidate images, reconstruct the correct temporal order of camera views |
|
|
| ### Key Features |
|
|
| - **Automatic Ground Plane Estimation**: PCA-based geometry calibration eliminates manual tuning |
| - **Oracle Chain Generation**: Creates step-by-step reasoning paths with intermediate ground-truth views |
| - **LLM Chain-of-Thought**: Generates natural language reasoning that mirrors human spatial thinking |
| - **Multi-backend Support**: Works with OpenAI-compatible APIs and local vLLM inference |
| - **Cluster Deployment**: Ready for distributed GPU execution via Determined AI |
|
|
| ## Installation |
|
|
| ### Prerequisites |
|
|
| - Python 3.12 |
| - CUDA 11.8+ (for GPU support) |
| - Access to CO3D dataset |
| - (Optional) Determined AI cluster for distributed training |
|
|
| ### Setup |
|
|
| 1. **Clone the repository** |
| ```bash |
| git clone <repository-url> |
| cd interleaved-umm |
| ``` |
|
|
| 2. **Create conda environment** |
| ```bash |
| conda create -n interleaved-umm python=3.12 |
| conda activate interleaved-umm |
| ``` |
|
|
| 3. **Install PyTorch** |
|
|
| First, install PyTorch 2.8.0 matching your CUDA version from the [official PyTorch website](https://pytorch.org/get-started/locally/). |
|
|
| For example, with CUDA 11.8: |
| ```bash |
| pip install torch==2.8.0 torchvision torchaudio --index-url https://download.pytorch.org/whl/cu118 |
| ``` |
|
|
| For CUDA 12.1: |
| ```bash |
| pip install torch==2.8.0 torchvision torchaudio --index-url https://download.pytorch.org/whl/cu121 |
| ``` |
|
|
| 4. **Install in editable mode** |
| ```bash |
| pip install -e . |
| ``` |
|
|
| 5. **Install dependencies** |
| ```bash |
| pip install -r requirements.txt |
| ``` |
|
|
| 6. **Set up environment variables** |
|
|
| Create a `.env` file in the project root: |
| ```bash |
| # OpenAI-compatible API |
| BASE_URL=https://api.openai.com/v1/chat/completions |
| API_KEY=your_api_key_here |
| |
| # Qwen API (optional) |
| QWEN_API_KEY=your_qwen_key |
| QWEN_BASE_URL=https://dashscope.aliyuncs.com/compatible-mode/v1 |
| ``` |
|
|
| **⚠️ Important**: Never commit the `.env` file. It's already in `.gitignore`. |
|
|
| 7. **Prepare CO3D dataset** |
|
|
| Download and extract the CO3D dataset, then update paths in generation scripts: |
| - `ROOT_PATH`: Path to CO3D dataset root |
| - `IMAGE_PREFIX`: Relative path for storing processed images |
|
|
| ## Project Structure |
|
|
| ``` |
| interleaved-umm/ |
| ├── src/ |
| │ ├── action_state/ # Task generation logic |
| │ │ ├── gen_task1.py # Camera view prediction |
| │ │ ├── gen_task3.py # Camera view ordering |
| │ │ └── utils.py # Geometry utilities (PCA, camera poses) |
| │ ├── llm_generation/ # Chain-of-thought generation |
| │ │ ├── generator.py # CoTGenerator orchestrator |
| │ │ ├── prompts.py # Task-specific prompts |
| │ │ ├── api_client.py # OpenAI-compatible API client |
| │ │ ├── vllm_client.py # Local vLLM inference |
| │ │ └── cleaning_generator.py # Data quality verification |
| │ └── utils/ |
| │ └── image_utils.py # Multimodal content parsing |
| ├── scripts/ |
| │ ├── action_state/ # Task generation runners |
| │ │ ├── task1/ # Task 1 generation scripts |
| │ │ └── task3/ # Task 3 generation scripts |
| │ ├── run_llm_cot.py # LLM CoT generation (API) |
| │ ├── run_llm_cot_vllm.py # LLM CoT generation (vLLM) |
| │ ├── run_cleaning.py # Data quality checker |
| │ ├── filter/ # Sequence filtering scripts |
| │ ├── copy_image.py # Image preprocessing |
| │ └── visualize_*.py # Visualization tools |
| ├── deploy/ |
| │ ├── local/ # Cluster deployment configs |
| │ │ ├── task1/ |
| │ │ ├── task3/ |
| │ │ └── cleaning/ |
| │ └── template/ # Config templates |
| ├── configs/ # Legacy configuration files |
| ├── data/ # Generated datasets (not in repo) |
| ├── debug/ # Debugging outputs (not in repo) |
| ├── pyproject.toml # Package configuration |
| ├── requirements.txt # Python dependencies |
| └── CLAUDE.md # Documentation for Claude Code |
| ``` |
|
|
| ## Quick Start |
|
|
| ### 1. Generate Task Metadata |
|
|
| Generate Task 1 samples with oracle reasoning chains: |
|
|
| ```bash |
| cd scripts/action_state/task1 |
| bash run_gen_task1_v3.sh |
| ``` |
|
|
| This will: |
| - Sample camera pose pairs from CO3D sequences |
| - Verify geometric constraints (angle ranges, intervals) |
| - Generate oracle chains with intermediate views |
| - Save JSONL files to `data/questions/task1_metadata_v3/` |
|
|
| ### 2. Generate Chain-of-Thought Reasoning |
|
|
| **Option A: Using OpenAI-compatible API** |
|
|
| ```bash |
| python scripts/run_llm_cot.py \ |
| --input_file data/questions/task1_metadata_v3/train/train_1.jsonl \ |
| --output_file data/questions/task1_v3/train/train_1.jsonl \ |
| --image_root /path/to/project/root \ |
| --model gpt-4o |
| ``` |
|
|
| **Option B: Using local vLLM server** |
|
|
| ```bash |
| python scripts/run_llm_cot_vllm.py \ |
| --input_file data/questions/task1_metadata_v3/train/train_1.jsonl \ |
| --output_file data/questions/task1_v3/train/train_1.jsonl \ |
| --image_root /path/to/project/root \ |
| --model /path/to/Qwen3-VL-32B-Instruct \ |
| --tp_size 2 \ |
| --gpu_memory_utilization 0.9 |
| ``` |
|
|
| ### 3. Deploy to Cluster |
|
|
| If using Determined AI: |
|
|
| ```bash |
| det experiment create deploy/local/task1/config.yaml . |
| ``` |
|
|
| ## Usage |
|
|
| ### Task Generation Parameters |
|
|
| **Task 1 (Camera View Prediction)** |
|
|
| Key parameters in `scripts/action_state/task1/run_gen_task1_v3.sh`: |
|
|
| ```bash |
| MIN_ANGLE=60.0 # Minimum rotation angle (degrees) |
| MAX_ANGLE=125.0 # Maximum rotation angle (degrees) |
| MIN_INTERVAL=25.0 # Minimum angular separation between options |
| NUM_SAMPLES=3 # Samples per sequence |
| ``` |
|
|
| **Task 3 (Camera View Ordering)** |
|
|
| Key parameters in `scripts/action_state/task3/run_gen_task3_v3.sh`: |
|
|
| ```bash |
| MIN_INTERVAL=15.0 # Minimum per-step rotation |
| MAX_INTERVAL=40.0 # Maximum per-step rotation |
| MAX_ANGLE=170.0 # Maximum total trajectory span |
| ``` |
|
|
| ### Data Filtering |
|
|
| Before generating tasks, filter sequences for quality: |
|
|
| ```bash |
| python scripts/filter/filter_v4.py \ |
| --category apple \ |
| --root_path /path/to/co3d \ |
| --output_dir data/filter_log_v4_pca |
| ``` |
|
|
| ### Visualization |
|
|
| Visualize camera trajectories: |
|
|
| ```bash |
| python scripts/visualize_traj_pca.py \ |
| --category apple \ |
| --root_path /path/to/co3d \ |
| --sequence_name <sequence_id> |
| ``` |
|
|
| ## Configuration |
|
|
| ### Environment Variables |
|
|
| | Variable | Description | Example | |
| |----------|-------------|---------| |
| | `BASE_URL` | OpenAI-compatible API endpoint | `https://api.openai.com/v1/chat/completions` | |
| | `API_KEY` | API authentication key | `sk-...` | |
| | `QWEN_API_KEY` | Qwen API key (optional) | `sk-...` | |
| | `QWEN_BASE_URL` | Qwen API endpoint (optional) | `https://dashscope.aliyuncs.com/...` | |
|
|
| ### Cluster Deployment |
|
|
| Edit `deploy/local/*/config.yaml`: |
|
|
| ```yaml |
| resources: |
| resource_pool: amp-80g # GPU pool |
| slots_per_trial: 2 # Number of GPUs |
| |
| bind_mounts: |
| - host_path: /mount/HOME/username |
| container_path: /home/username |
| |
| environment: |
| image: your-docker-image:tag |
| ``` |
|
|
| ## Development |
|
|
| ### Running Tests |
|
|
| ```bash |
| # Test on a small subset |
| python src/action_state/gen_task1.py \ |
| --root_path /path/to/co3d \ |
| --output_dir test_output \ |
| --category apple \ |
| --num_samples 1 |
| ``` |
|
|
| ### Code Structure |
|
|
| **Geometry Pipeline**: |
| 1. `CO3DDataLoader` loads frame annotations |
| 2. `get_sequence_geometry_pca()` estimates ground plane via PCA |
| 3. `get_relative_yaw()` computes angular differences |
| 4. `decompose_angle()` breaks rotations into steps |
|
|
| **CoT Generation Pipeline**: |
| 1. `CoTGenerator` receives oracle chain |
| 2. For each step, constructs context messages |
| 3. Calls LLM with "cheat sheet" (target view + physics hints) |
| 4. LLM generates reasoning that appears to derive the action |
| 5. Combines into final `<think>...</think>` trace |
|
|
| ### Key Concepts |
|
|
| - **Oracle Chain**: Ground-truth reasoning path with intermediate views |
| - **Cheat Mechanism**: LLM sees target but must write as if deriving it |
| - **Parallax Rule**: "Camera moves RIGHT → View shifts LEFT" |
| - **Bird's Eye View**: Rotation direction defined from top-down perspective |
|
|
| ## Troubleshooting |
|
|
| **Issue**: `FileNotFoundError` for images |
| - **Solution**: Check `IMAGE_PREFIX` and `image_root` match your actual paths |
|
|
| **Issue**: `LinAlgError` in PCA |
| - **Solution**: Sequence has too few frames or degenerate geometry. Filter will catch these. |
|
|
| **Issue**: vLLM OOM errors |
| - **Solution**: Reduce `gpu_memory_utilization` or `limit_mm_per_prompt` |
|
|
| **Issue**: No valid samples generated |
| - **Solution**: Relax `MIN_ANGLE`, `MAX_ANGLE`, or `MIN_INTERVAL` constraints |
|
|
| ## Citation |
|
|
| If you use this dataset or codebase, please cite: |
|
|
| ```bibtex |
| @misc{interleaved-umm, |
| title={Interleaved Multimodal Reasoning Dataset}, |
| author={Your Name}, |
| year={2024} |
| } |
| ``` |
|
|
| ## License |
|
|
| [Specify your license here] |
|
|
| ## Contact |
|
|
| For questions or issues, please contact [your contact info] or open an issue on GitHub. |
|
|