How zhanglixuan0720/prelar works
Project Overview
• The project is a research-oriented implementation in PyTorch focused on world model pre-training. It is designed for learning action representations (PreLAR) using both pretraining (action-free videos) and fine-tuning (using real actions), with baselines provided for DreamerV2 and APV.
• The system handles both data processing (for datasets like Something-Something-V2) and training pipelines for variants of model-based RL in visual control tasks.
Main Components to Illustrate
a. Data Preparation and Management
• “data” directory: This houses dataset preparation for Something-Something-V2. Show sub-processes like:
• Frame extraction (extract_frames.py)
• Data processing (process_somethingv2.py)
• Generated lists (train/val video folder text files) as data inputs.
b. Configuration Management
• The “configs” directory holds various YAML configuration files (e.g., apv_finetuning.yaml, prelar_pretraining.yaml, etc.) that define essential hyperparameters and settings for different training regimes.
c. Core Library (wmlib)
• This is the backbone of the project and is divided into several modules:
• Agents (wmlib/agents): Implements different training agents & their variants (standard methods, APV, DreamerV2, PreLAR versions, etc.). It is the central point where model-specific training logic is housed.
• Core (wmlib/core): Implements the training loop driver, replay buffers, distribution utilities, and additional supporting functionalities.
• Networks (wmlib/nets): Contains model building blocks classified into submodules:
• Encoders: (wmlib/nets/encoder) for creating visual representations.
• Decoders: (wmlib/nets/decoder) for reconstruction aspects of the visual world model.
• Dynamics: (wmlib/nets/dynamics) which manage the latent dynamics (using approaches like RSSM or variational RSSM).
• VA Net: Specialized network for action encoding.
• Datasets (wmlib/datasets): Utilities for handling video datasets (including Something-Something-V2) and possibly video-specific processing.
• Environment Interfaces (wmlib/envs): Wrap around external simulated environments (Meta-world and Robodesk) with additional wrappers and utility functions.
• Training Helpers (wmlib/train): Contains the training trainers, pretrainer, and finetuner submodules.
d. Example Scripts
• The “examples” directory contains scripts that act as entry points to launch training for the various modes:
• Pretraining (e.g., train_prelar_pretraining.py, train_apv_pretraining.py)
• Finetuning (e.g., train_prelar_finetuning.py, train_apv_finetuning.py)
• Baseline methods (DreamerV2, APV, and contextualized versions)
• These coordinate the loading of configurations, data, and call upon the agents in wmlib to start the training process.
e. External Dependencies and Environment
• External libraries and tools (like PyTorch, MuJoCo [via Meta-world], and other referenced repositories).
• Mention that the Conda environment is built using environment.yaml, ensuring dependencies are consistent across runs.
Relationships and Data Flows
• How configuration files feed into the training scripts, which then initialize the training agents in wmlib.
• Integration between the core modules:
• Data → Datasets Module → Agents/Training Loop (Driver, Replay Buffer)
• Networks (Encoders, Decoders, Dynamics, VA Net) integrate with agents for forward passes and learning.
• Environment Modules (envs) provide simulated scenarios (for Meta-world and Robodesk) that the agents interact with.
• That example scripts act as a wrapper that links configuration, data, and the underlying model/training pipelines in wmlib.
Important Architectural Patterns and Design Principles
• Modular design splitting data handling, model architecture, training logic, and configuration management.
• Separation of concerns is emphasized with clear distinctions between:
• Data preprocessing (in the data/ folder)
• Model architecture (in wmlib/nets)
• Training logic and orchestration (in wmlib/core and wmlib/train)
• Agent behavior and different training schemes (in wmlib/agents)
• Extensibility: The system is designed to support multiple variants (PreLAR with/without contrastive loss, APV, DreamerV2) and can be extended by switching configuration and agent modules.
• How example scripts (from the “examples” directory) initiate experiments by selecting particular configurations.
• External services like MuJoCo installation for Meta-world and note dependencies referenced in the README.