CoolFace
Apppublic

stargatek1/SSM-MetaRL-Unified

sourceHugging Facemitupdated 11mo agoView on Hugging Face
0likes
App README

๐Ÿš€ SSM-MetaRL-Unified: State Space Model + Meta-Reinforcement Learning

Try it now! Pre-trained model ready for immediate testing - no training required!

![GitHub](https://github.com/sunghunkwag/SSM-MetaRL-Unified) ![Model](https://huggingface.co/stargatek1/ssm-metarl-cartpole) ![License](https://opensource.org/licenses/MIT) ![Paper](https://arxiv.org/abs/1703.03400)

๐ŸŽฏ 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

  1. 1.Click on the "0. Load Pre-trained Model" tab
  2. 2.Click the "๐Ÿ“ฅ Load Pre-trained Model" button
  3. 3.Wait ~5 seconds for the model to load

Step 2: Test the Model

  1. 1.Go to the "2. Test-Time Adaptation" tab
  2. 2.Select adaptation mode:
  3. 3.Standard: Uses only current task observations (baseline)
  4. 4.Hybrid: Uses current observations + past experiences (recommended)
  5. 5.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 Interaction

Meta-Learning Process

Meta-Training (MAML):

  1. 1.Sample multiple tasks (episodes)
  2. 2.Inner loop: Adapt on support set
  3. 3.Outer loop: Update meta-parameters based on query set
  4. 4.Result: Good initialization for fast adaptation

Test-Time Adaptation:

  1. 1.Start with meta-learned initialization
  2. 2.Collect observations from new task
  3. 3.Adapt using Standard or Hybrid mode
  4. 4.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:

๐Ÿ’ก 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

Documentation

  • โ€”Architecture Details: See ARCHITECTURE.md in 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

python
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

python
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:

bibtex
@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! ๐Ÿš€