stargatek1/SSM-MetaRL-Unified
๐ SSM-MetaRL-Unified: State Space Model + Meta-Reinforcement Learning
Try it now! Pre-trained model ready for immediate testing - no training required!
   
๐ฏ What is This?
This Space demonstrates a complete implementation of State Space Models (SSM) combined with Meta-Reinforcement Learning (MAML) for fast adaptation to new tasks. The key innovation is the Hybrid Adaptation mode that combines current task data with experience replay for more robust learning.
Key Features
- โ Pre-trained Model Available - Load and test immediately without waiting for training!
- โ State Space Model (SSM) - Efficient temporal modeling with hidden states
- โ Meta-Learning (MAML) - Learn to learn for fast adaptation
- โ Standard Adaptation - Baseline using only current task data
- โ Hybrid Adaptation - Novel approach combining current data + experience replay (research contribution)
- โ Interactive Demo - Test different adaptation strategies in real-time
๐ Quick Start (3 Simple Steps!)
Step 1: Load Pre-trained Model
- Click on the "0. Load Pre-trained Model" tab
- Click the "๐ฅ Load Pre-trained Model" button
- Wait ~5 seconds for the model to load
Step 2: Test the Model
- Go to the "2. Test-Time Adaptation" tab
- Select adaptation mode:
- Standard: Uses only current task observations (baseline)
- Hybrid: Uses current observations + past experiences (recommended)
- Click "๐งช Test Adaptation"
Step 3: View Results
- See the model's performance in the CartPole environment
- Compare different adaptation strategies
- Observe how meta-learning enables fast adaptation
That's it! No training required - the pre-trained model is ready to use!
๐ What You'll Learn
State Space Models (SSM)
Efficient sequential models that maintain hidden states over time, enabling temporal dependency modeling without the complexity of traditional RNNs.
Meta-Learning (MAML)
Model-Agnostic Meta-Learning learns good parameter initializations that can quickly adapt to new tasks with minimal data - essentially "learning how to learn."
Test-Time Adaptation
- Standard Mode: Adapts using only current task observations (simple baseline)
- Hybrid Mode: Combines current observations with experience replay buffer (more robust, original research contribution)
๐๏ธ Architecture
Input (CartPole observations)
โ
State Space Model (SSM)
โโ State Transition (A matrix)
โโ Input Projection (B matrix)
โโ Output Network (C matrix)
โโ Feedthrough (D matrix)
โ
Action Selection
โ
Environment InteractionMeta-Learning Process
Meta-Training (MAML):
- Sample multiple tasks (episodes)
- Inner loop: Adapt on support set
- Outer loop: Update meta-parameters based on query set
- Result: Good initialization for fast adaptation
Test-Time Adaptation:
- Start with meta-learned initialization
- Collect observations from new task
- Adapt using Standard or Hybrid mode
- Evaluate performance
๐ Model Performance
Pre-trained Model Specifications:
- Environment: CartPole-v1
- Training: 50 epochs with MetaMAML
- Parameters: 6,744 trainable parameters
- File Size: 32 KB
- Adaptation Mode: Hybrid (with experience replay)
Verification Results:
- Average Reward: 9.40 ยฑ 0.66
- Min Reward: 8.0
- Max Reward: 10.0
- Consistency: โ Stable across 10 test episodes
๐ฌ Research Background
This implementation is based on:
- MAML: Model-Agnostic Meta-Learning for Fast Adaptation of Deep Networks (Finn et al., 2017)
- Meta-RL: Meta-Reinforcement Learning Survey
- State Space Models: Efficiently Modeling Long Sequences
๐ก Why This Matters
Traditional RL Problem
Training RL agents from scratch is:
- โฐ Time-consuming (hours or days)
- ๐ Data-hungry (millions of samples)
- ๐ฏ Task-specific (no transfer)
Meta-RL Solution
With meta-learning:
- โก Fast adaptation (minutes or seconds)
- ๐ Sample-efficient (few-shot learning)
- ๐ Transferable (learns across tasks)
Hybrid Adaptation Innovation
Our hybrid mode adds:
- ๐ง Experience replay for better adaptation
- ๐ช More robust to distribution shift
- ๐ฏ Improved performance over standard adaptation
๐ฎ Use Cases
- Robotics: Quick adaptation to new environments or tasks
- Game AI: Fast learning of new game mechanics
- Control Systems: Rapid tuning for different operating conditions
- Research: Benchmark for meta-learning algorithms
๐ What's Inside
Tabs Overview
Tab 0: Load Pre-trained Model โญ Start Here!
- One-click loading of pre-trained weights
- Instant access to meta-learned model
- Skip the 5-10 minute training wait
Tab 1: Meta-Training (Optional)
- Train your own model from scratch
- Customize hyperparameters
- Experiment with different configurations
Tab 2: Test-Time Adaptation
- Test the loaded model
- Compare Standard vs Hybrid adaptation
- Evaluate performance
Tab 3: About
- Detailed documentation
- Architecture overview
- Research references
๐ Resources
Model & Code
- ๐ค Pre-trained Model: stargatek1/ssm-metarl-cartpole
- ๐ป GitHub Repository: sunghunkwag/SSM-MetaRL-Unified
- ๐ Model Card: Detailed documentation in Model Hub
- ๐ Training Logs: Available in repository
Documentation
- Architecture Details: See
ARCHITECTURE.mdin repository - Model Generation Report: See
MODEL_GENERATION_REPORT.md - Training Script:
train_and_save_model.py - Verification Script:
verify_model.py
Papers & References
๐ ๏ธ Technical Details
Model Architecture
StateSpaceModel(
state_dim=32, # Hidden state dimension
input_dim=4, # CartPole observation space
output_dim=4, # For state prediction
hidden_dim=64 # Network hidden dimension
)Training Configuration
- Algorithm: MetaMAML (Model-Agnostic Meta-Learning)
- Epochs: 50
- Tasks per Epoch: 5
- Inner Learning Rate: 0.01 (task adaptation)
- Outer Learning Rate: 0.001 (meta-update)
- Adaptation Mode: Hybrid (with experience replay)
- Experience Buffer: 3,191 transitions
Usage Example
from core.ssm import StateSpaceModel
# Load pre-trained model
model = StateSpaceModel(
state_dim=32,
input_dim=4,
output_dim=4,
hidden_dim=64
)
model.load("cartpole_hybrid_real_model.pth")
model.eval()
# Use for inference
obs = env.reset()
hidden_state = model.init_hidden(batch_size=1)
action_logits, hidden_state = model(obs_tensor, hidden_state)๐ค Contributing
Contributions are welcome! This is an open-source research project.
- Report Issues: GitHub Issues
- Submit PRs: Improvements and extensions welcome
- Share Results: Try on different environments and share your findings
๐ Citation
If you use this work in your research, please cite:
@software{ssm_metarl_unified,
title={SSM-MetaRL-Unified: State Space Model + Meta-Reinforcement Learning},
author={stargatek1},
year={2025},
url={https://github.com/sunghunkwag/SSM-MetaRL-Unified}
}๐ License
This project is licensed under the MIT License - see the LICENSE file for details.
๐ Acknowledgments
- MAML Algorithm: Chelsea Finn et al.
- Gymnasium: OpenAI and Farama Foundation
- Gradio: Hugging Face team
- PyTorch: Meta AI Research
๐ Star History
If you find this project useful, please consider:
- โญ Starring the GitHub repository
- ๐ Liking this Space
- ๐ Sharing with others interested in Meta-RL
Made with โค๏ธ for the Meta-RL and Reinforcement Learning community
Ready to try? Click the "Load Pre-trained Model" button above and start testing! ๐
