Skip to content

BouajilaHamza/Skill-Discovery-Agent

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

48 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

🎯 Skill Discovery with DIAYN

arXiv License Python PyTorch Hugging Face

An efficient PyTorch implementation of the Diversity is All You Need (DIAYN) algorithm for unsupervised skill discovery in reinforcement learning. This project enables agents to autonomously learn diverse behaviors in MiniGrid environments using information-theoretic objectives.

πŸ“ Paper Reference

Diversity is All You Need: Learning Skills without a Reward Function
Benjamin Eysenbach, Abhishek Gupta, Julian Ibarz, Sergey Levine
International Conference on Learning Representations (ICLR), 2019

✨ Features

  • πŸ€– Unsupervised Skill Discovery: Learn diverse skills without external rewards
  • πŸ”„ MiniGrid Integration: Test in various MiniGrid environments
  • ⚑ PyTorch Implementation: Optimized for performance and readability
  • πŸ“Š Visualization Tools: Built-in visualization of learned skills and metrics
  • πŸ”§ Configurable: Easy hyperparameter tuning via YAML configs
  • πŸ“ˆ TensorBoard Logging: Track training progress and metrics
  • πŸ€— HuggingFace Ready: Easy model sharing and loading

πŸš€ Quick Start

Installation

  1. Clone the repository:

    git clone https://github.com/BouajilaHamza/Skill-Discovery-Agent.git
    cd Skill-Discovery-Agent
  2. Install dependencies:

    # Using pip
    pip install -e .
    
    # Or using UV (faster)
    uv sync

Training

Train a new DIAYN agent with default settings:

uv run src/scripts/train.py --config configs/diayn.yaml

Visualizing Learned Skills

Visualize the skills learned by a trained agent:

uv run src/scripts/visualize_skills.py --checkpoint /path/to/checkpoint.pt

πŸ—οΈ Project Structure

.
β”œβ”€β”€ configs/                    # Configuration files
β”‚   └── diayn.yaml             # DIAYN agent configuration
β”œβ”€β”€ logs/                      # Training logs and checkpoints
β”œβ”€β”€ src/                       # Source code
β”‚   β”œβ”€β”€ agents/                # Agent implementations
β”‚   β”‚   β”œβ”€β”€ base_agent.py      # Base agent class
β”‚   β”‚   └── diayn_agent.py     # DIAYN agent implementation
β”‚   β”œβ”€β”€ envs/                  # Environment wrappers
β”‚   β”‚   β”œβ”€β”€ __init__.py        # Environment registration
β”‚   β”‚   └── minigrid_wrapper.py# MiniGrid environment wrapper
β”‚   β”œβ”€β”€ models/                # Model architectures
β”‚   β”‚   β”œβ”€β”€ base_model.py      # Base model class
β”‚   β”‚   β”œβ”€β”€ encoder.py         # State encoder
β”‚   β”‚   └── discriminator.py   # Skill discriminator
β”‚   └── scripts/               # Training and evaluation scripts
β”‚       β”œβ”€β”€ train.py           # Training script
β”‚       β”œβ”€β”€ visualize_skills.py # Skill visualization
β”‚       └── visualization.py   # Training metrics visualization
β”œβ”€β”€ tests/                     # Unit tests
β”œβ”€β”€ .gitignore                 # Git ignore file
β”œβ”€β”€ pyproject.toml             # Project configuration
└── README.md                  # This file

πŸ€— Model Sharing

Uploading to Hugging Face

To share your trained models on Hugging Face Hub:

from huggingface_hub import HfApi

api = HfApi()
api.upload_folder(
    folder_path="logs/your_experiment/checkpoints",
    repo_id="your-username/diayn-minigrid",
    repo_type="model",
)

Loading from Hugging Face

from huggingface_hub import hf_hub_download
import torch

checkpoint_path = hf_hub_download(
    repo_id="your-username/diayn-minigrid",
    filename="diayn_final.pt"
)
model = torch.load(checkpoint_path, map_location='cpu')

πŸ“Š Results

Training Metrics

Training Metrics

Learned Skills

Learned Skills

πŸ“š Documentation

Configuration

Key configuration parameters in configs/diayn.yaml:

# Environment
env_id: "MiniGrid-Empty-8x8-v0"
obs_type: "rgb"

# Training
num_skills: 8
batch_size: 64
learning_rate: 3e-4
gamma: 0.99
entropy_coeff: 0.01
replay_size: 10000
max_episodes: 1000

Available Commands

Command Description
python -m src.scripts.train Train a new DIAYN agent
python -m src.scripts.visualize_skills Visualize learned skills
python -m src.scripts.visualization Generate training plots
--output_dir models/text_model

Advanced options

python -m machine_learning.models text
--data_path /path/to/training_data/text
--output_dir models/text_model
--model_type kmeans
--n_clusters 5
--n_components 100


### Training Image Clustering Model

```bash
# Basic usage
python -m machine_learning.models image \
  --data_path /path/to/training_data/images \
  --output_dir models/image_model

# Advanced options
python -m machine_learning.models image \
  --data_path /path/to/training_data/images \
  --output_dir models/image_model \
  --model_type kmeans \
  --n_clusters 5 \
  --feature_type deep \
  --n_components 128

Training Options

Text Clustering Options:

  • --model_type: Clustering algorithm (kmeans, dbscan, agglomerative, gmm, optics)
  • --n_clusters: Number of clusters (default: 5, not used for DBSCAN/OPTICS)
  • --n_components: Number of components for dimensionality reduction (default: 100)
  • --no_dim_reduction: Disable dimensionality reduction
  • --random_state: Random seed (default: 42)

Image Clustering Options:

  • --model_type: Clustering algorithm (kmeans, dbscan, gmm, optics)
  • --n_clusters: Number of clusters (default: 5, not used for DBSCAN/OPTICS)
  • --feature_type: Type of features to use (deep, color, texture, all)
  • --n_components: Number of components for dimensionality reduction (default: 128)
  • --no_dim_reduction: Disable dimensionality reduction
  • --random_state: Random seed (default: 42)

Model Output

After training, each model will be saved with the following structure:

output_dir/
β”œβ”€β”€ model.pkl          # Trained model
└── metadata.json      # Model metadata and parameters

The metadata.json file contains information about the training process and model configuration.

πŸ› οΈ Usage

Training with Custom Configuration

python -m src.scripts.train \
  --config configs/diayn.yaml \
  --num_skills 16 \
  --env_id "MiniGrid-Empty-16x16-v0"

Monitoring Training

Monitor training progress with TensorBoard:

tensorboard --logdir=logs/

🀝 Contributing

Contributions are welcome! Please follow these steps:

  1. Fork the repository
  2. Create a feature branch (git checkout -b feature/amazing-feature)
  3. Commit your changes (git commit -m 'Add some amazing feature')
  4. Push to the branch (git push origin feature/amazing-feature)
  5. Open a Pull Request

πŸ“œ License

This project is licensed under the MIT License - see the LICENSE file for details.

πŸ“„ Citation

If you use this code in your research, please cite the original DIAYN paper:

@inproceedings{eysenbach2018diversity,
  title={Diversity is All You Need: Learning Skills without a Reward Function},
  author={Eysenbach, Benjamin and Gupta, Abhishek and Ibarz, Julian and Levine, Sergey},
  booktitle={International Conference on Learning Representations (ICLR)},
  year={2019}
}

πŸ™ Acknowledgements

python client.py --source /path/to/files --destination /path/to/organized/files --model_dir /path/to/trained/models

Configuration

Edit config/organizer_config.py to customize the organization rules and model parameters.

Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

License

This project is licensed under the MIT License - see the LICENSE file for details.

About

A PyTorch implementation of DIAYN for unsupervised skill discovery in MiniGrid environments. Trains agents to learn diverse behaviors without reward engineering. Features modular architecture and visualization tools.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors