# TURRET: Transferable Unified Robot Representation with Graph Neural Networks
> **TURRET**: A Graph Neural Network framework for adaptive multi-source cross-domain transfer learning in robotic control.
## π Overview
TURRET is a novel framework that enables effective knowledge transfer across different robot morphologies and task domains using Graph Neural Networks (GNNs). This implementation reproduces the core contributions of the original paper:
- **Unified Semantic Space**: Projects states from different tasks into a common embedding space
- **Adaptive Transfer**: Dynamically weights source policies based on state-level semantic similarity
- **GNN-based Policy**: Structured policy networks that explicitly model robot morphology
- **Gradual Independence**: Progressive transition from transfer learning to independent learning
## π― Key Features
- πΈοΈ **Morphology-aware GNNs**: Explicitly model robot structure as graphs
- π **Multi-source Transfer**: Combine knowledge from multiple source policies
- π― **State-level Adaptation**: Dynamic transfer weights based on current state
- π **Progressive Learning**: Smooth transition from transfer to independent learning
- π§ͺ **Comprehensive Evaluation**: Size transfer, morphology transfer, and ablation studies
## π Quick Start
### Installation & Setup# Clone repository
git clone https://github.com/your-username/turret-replication.git
cd turret-replication
# Create environment (recommended)
conda create -n turret python=3.8
conda activate turret
# Install dependencies
pip install -r requirements.txt
# Download pre-trained models
python scripts/download_pretrained.py
# Or pre-train source policies yourself
python experiments/pretrain_source.py# Quick demo (2 seeds, 100 episodes)
python scripts/run_all_experiments.py --num_seeds 2 --total_episodes 100
# Full paper replication (5 seeds, 500 episodes)
python scripts/run_all_experiments.py --num_seeds 5 --total_episodes 500
# Run specific experiments only
python scripts/run_all_experiments.py --experiments size morphology
# With GPU acceleration
python scripts/run_all_experiments.py --device cudafrom configs.base_config import TURRETConfig
from experiments.paper_experiments import PaperExperimentReplicator
# Configure experiment
config = TURRETConfig(
device="cuda",
total_episodes=500,
num_seeds=5
)
# Run all paper experiments
replicator = PaperExperimentReplicator(config)
results = replicator.run_all_experiments()# Run transfer experiments directly
python experiments/transfer_experiment.py
# Run specific experiment types
python scripts/run_all_experiments.py --experiments size # Only size transfer
python scripts/run_all_experiments.py --experiments size morphology # Size and morphology# Results are saved in:
ls data/paper_results/
# Main files:
# - paper_experiments_YYYYMMDD_HHMMSS.json # Raw results
# - training_statistics_YYYYMMDD_HHMMSS.json # Training statistics
# - analysis/comprehensive_analysis_report.json # Analysis reportfrom analysis.result_analyzer import ResultAnalyzer
analyzer = ResultAnalyzer("data/paper_results")
analysis = analyzer.generate_comprehensive_analysis(results)from experiments.visualization.advanced_visualizer import AdvancedVisualizer
visualizer = AdvancedVisualizer()
visualizer.plot_transfer_dynamics(results)# Run with GPU
python scripts/run_all_experiments.py --device cuda
# Run with multiple GPUs
python scripts/run_all_experiments.py --device cuda --num_processes 4from optimization.distributed_trainer import DistributedTURRETTrainer
dist_trainer = DistributedTURRETTrainer(config)from optimization.performance_optimizer import PerformanceOptimizer
optimizer = PerformanceOptimizer(config)
stats = optimizer.optimize_gnn_forward(model, node_observations, morphology_graph)TURRET/
βββ configs/
β βββ base_config.py # Main configuration dataclass (TURRETConfig)
β βββ environment_config.py # Environment-specific settings
βββ models/
β βββ policies/
β β βββ gnn_structured_policy.py # Full GNN policy (production version)
β β βββ structured_policy.py # Simplified policy (testing version)
β βββ networks/
β β βββ attention_propagation.py # Multi-head GNN layers
β β βββ set_transformer.py # State embedding via attention
β β βββ input_network.py # Node observation processing
β β βββ output_network.py # Action distribution prediction
β β βββ base_networks.py # Base neural network components
β βββ morphology.py # Robot graph structure definitions
β βββ components/
β βββ distributions.py # Probability distributions for actions
βββ training/
β βββ trainers/
β β βββ transfer_trainer.py # Complete TURRET training system
β β βββ ppo_trainer.py # Base PPO implementation
β β βββ base_trainer.py # Abstract trainer interface
β βββ buffers.py # Experience replay buffers
β βββ optimizers.py # Gradient management and schedulers
βββ environments/
β βββ tasks/
β β βββ centipede.py # Centipede-n multi-legged robots
β β βββ standard_robots.py # MuJoCo standard robots
β βββ base_env.py # Abstract environment interface
β βββ mujoco_wrapper.py # MuJoCo environment wrapper
βββ transfer/
β βββ semantic_space.py # Unified state embedding space
β βββ weight_calculator.py # Adaptive transfer weight computation
β βββ lateral_connections.py # Knowledge fusion mechanisms
β βββ independence.py # Gradual independence scheduler
β βββ base_transfer.py # Base class for transfer components
βββ experiments/
β βββ runners/
β β βββ size_transfer.py # Size transfer experiments
β β βββ morphology_transfer.py # Morphology transfer experiments
β β βββ base_runner.py # Experiment runner base class
β βββ evaluation/
β β βββ evaluator.py # Experiment evaluation
β β βββ metrics.py # Performance metrics
β β βββ baseline_models.py # Baseline method implementations
β βββ visualization/
β β βββ advanced_visualizer.py # Interactive visualizations
β β βββ tsne_visualizer.py # Dimensionality reduction
β β βββ trajectory_plot.py # Training trajectory plotting
β βββ paper_experiments.py # Unified experiment entry point
β βββ transfer_experiment.py # Transfer learning experiments
β βββ pretrain_source.py # Source policy pre-training
βββ analysis/
β βββ result_analyzer.py # Comprehensive result analysis
βββ optimization/
β βββ performance_optimizer.py # Performance optimization tools
β βββ distributed_trainer.py # Distributed training support
βββ scripts/
β βββ run_all_experiments.py # Main experiment runner
β βββ download_pretrained.py # Pre-trained model downloader
βββ utils/
βββ file_utils.py # Checkpoint and file management
βββ logging_utils.py # Logging and training statistics
- Graph-based Policy Representation
# Robot morphology as graph
morphology_graph = MorphologyGraph("Humanoid")
policy = GNNStructuredPolicyNetwork(config)- Adaptive Transfer Weights
# Compute transfer weights based on state similarity
weights = weight_calculator.compute_transfer_weights(
target_state, source_states
)- Gradual Independence
# Progressive independence factor
p = independence_scheduler.get_current_p()
fused_output = p * target + (1-p) * transferred| Experiment Type | Source Tasks | Target Tasks | Description |
|---|---|---|---|
| Size Transfer | HalfCheetah, Ant | Humanoid, Walker2d | SmallβLarge robot transfer |
| Morphology Transfer | QuadrupedβBiped | Various combinations | Cross-morphology transfer |
| Ablation Studies | - | - | Component importance analysis |
| Baseline Comparison | PPO, CAT, NerveNet | Standard tasks | Method performance comparison |
- Performance: Mean reward, learning speed, sample efficiency
- Transfer Effectiveness: Weight distributions, semantic distances
- Statistical Significance: Confidence intervals, effect sizes
| Method | Size Transfer | Morphology Transfer | Sample Efficiency |
- Effective Cross-Domain Transfer: TURRET successfully transfers knowledge across different robot morphologies
- Adaptive Weighting: State-level similarity metrics outperform fixed weighting schemes
- Scalability: GNN-based policies scale effectively to complex robot structures
- Progressive Learning: Gradual independence prevents negative transfer and improves final performance
- Create new runner in
experiments/runners/ - Register experiment in
paper_experiments.py - Update configuration classes and run scripts
- Add new components in appropriate modules
- Ensure compatibility with
TURRETConfigfor configuration - Update import paths and dependencies
The project includes comprehensive testing tools:
# Full system verification
python verify_phase8.py
# Component interface testing
python tests/test_component_interfaces.py
# Experiment replication testing
python tests/test_experiment_replication.py
# Performance benchmarking
python tests/performance_benchmark.py
# Final validation
python verification/final_validation.py
# Paper experiment test
python tests/test_run_paper_experiments.pyThe project follows a modular architecture:
- Config-driven: All experiments configured via
TURRETConfigdataclass - Modular components: Easy to extend or replace components
- Comprehensive testing: Each phase has verification scripts
- Type hints: Full type annotation for better development experience
This project is licensed under the MIT License - see the LICENSE file for details.
- Original TURRET paper authors for the innovative research
- MuJoCo team for the physics simulation environment
- PyTorch team for the deep learning framework
- HuggingFace for pre-trained model hosting
Note: This is a replication project for research purposes. Performance may vary based on hardware and specific experimental setup.