Skip to main content

Advanced World Model for Universal Industrial and Real-World Applications - DreamerV3 with RSSM, Groq LLM Integration, and Enterprise Security

Project description

Arynoxtech World Model - Advanced DreamerV3 with RSSM

PyPI version License: MIT Python 3.8+

A powerful World Model implementation based on Recurrent State Space Models (RSSM) inspired by DreamerV3, designed for industrial automation, robotics, drones, autonomous vehicles, and intelligent systems.

๐Ÿ†• NEW: Cognitive Agent with Groq LLM & User Authentication

We've added a Cognitive Agent that combines the World Model with Groq's LLM to create an AI that truly thinks before it speaks!

  • User Authentication: Secure login/register system with password hashing
  • Data Persistence: All conversations are saved per-user and can be restored
  • Memory: RSSM maintains conversation context in latent space
  • Imagination: Simulates multiple response strategies before answering
  • Decision Making: Actor-Critic selects the best response approach
  • Natural Language: Groq LLM (llama-3.3-70b-versatile) generates human-like responses

๐Ÿ‘‰ See COGNITIVE_AGENT_GUIDE.md for details!

Running the Cognitive Agent

# Set your Groq API key first
export GROQ_API_KEY="your-api-key-here"

# Run the cognitive agent
streamlit run LLM_integration/app.py

Features

  • ๐Ÿ” User Authentication: Register and login with username/password
  • ๐Ÿ’พ Conversation Persistence: All conversations are automatically saved
  • ๐Ÿ“œ Conversation History: Load and continue previous conversations
  • ๐Ÿ“Ž File Upload: Attach text files, images, and documents for analysis
  • ๐Ÿง  Cognitive Processing: See the AI's thinking process and strategy selection

Installation

pip install Arynoxtech_world_model

Optional Dependencies

# With API support (Flask)
pip install Arynoxtech_world_model[api]

# With development tools
pip install Arynoxtech_world_model[dev]

# Everything included
pip install Arynoxtech_world_model[all]

Quick Start

Training an Agent

import world_model

# Create and train an agent
agent = world_model.Agent()
agent.train(
    env='CartPole-v1',      # Any Gymnasium environment
    steps=50000,            # Training steps
    save_path='models/',    # Where to save models
)

# Evaluate
avg_reward = agent.evaluate(episodes=10)
print(f"Average reward: {avg_reward}")

Using a Pre-trained Model

import world_model

# Load pre-trained agent
agent = world_model.Agent(model_path='models/')

# Run inference
agent.reset()
obs = [0.1, 0.2, 0.3, 0.4]
action = agent.step(obs, deterministic=True)
print(f"Action: {action}")

Imagination / Planning

import world_model

agent = world_model.Agent(model_path='models/')

# Imagine future trajectories
actions, rewards, uncertainties = agent.imagine(horizon=20)

print(f"Total predicted reward: {sum(rewards):.2f}")
print(f"Average uncertainty: {sum(uncertainties)/len(uncertainties):.4f}")

Handling Missing Data

import world_model

agent = world_model.Agent(model_path='models/')

# Observation with missing values
obs = [0.1, None, 0.3, 0.4]  # Second value is missing
mask = [1, 0, 1, 1]           # 1 = valid, 0 = missing

action = agent.step(obs, mask=mask)
print(f"Action: {action}")

Custom Configuration

import world_model

# Create agent with custom config
config = {
    'env_name': 'Pendulum-v1',
    'obs_shape': [3],
    'action_type': 'continuous',
    'action_dim': 1,
    'latent_dim': 128,
    'hidden_dim': 512,
}

agent = world_model.Agent(config=config)
agent.train(env='Pendulum-v1', steps=100000)

Architecture

The World Model consists of six core components:

Component Description
Encoder Maps observations to latent embeddings
RSSM Recurrent State Space Model for dynamics modeling
Decoder Reconstructs observations from latent state
Actor Policy network for action selection
Critic Value function for state evaluation
Reward Predictor Predicts rewards from latent state

Core Concepts

  • Deterministic State (h): GRU-based hidden state capturing temporal dependencies
  • Stochastic State (z): Gaussian latent variable capturing uncertainty
  • Prior: p(z|h) - Distribution before seeing observation
  • Posterior: q(z|h,e) - Distribution after seeing observation
  • Imagination: Using RSSM to simulate future trajectories without environment interaction

Features

  • Multi-Modal Support: Vector (sensors) and Image (cameras) observations
  • Discrete & Continuous Actions: Supports both action types
  • Robust to Missing Data: Learnable embeddings for missing sensor values
  • Safety-Aware: Uncertainty-based action safety checks
  • Edge Deployment: Pruning, quantization, and TorchScript export
  • REST API: Multi-tenant API for integration
  • Domain Randomization: Training robustness for real-world deployment

Trained on Industrial Datasets

Dataset Sensors Samples Training Loss Use Case
Smart Factory IoT 52 5M 1.03 IoT anomaly detection
NASA Turbofan 24 5M 1.04 Engine health monitoring
Bearing Faults 6 5M 1.10 Vibration analysis
AI4I Predictive 5 10K 3.44 Multi-sensor maintenance

Performance: AUC-ROC: 0.8346 | Failure Detection: 86% | False Positive Rate: 5%

Project Structure

src/world_model/
โ”œโ”€โ”€ __init__.py              # Public API exports
โ”œโ”€โ”€ agent.py                 # Simplified high-level API
โ”œโ”€โ”€ deployment.py            # Deployment agent
โ”œโ”€โ”€ model/
โ”‚   โ”œโ”€โ”€ encoder.py           # Observation encoder
โ”‚   โ”œโ”€โ”€ rssm.py              # Recurrent State Space Model
โ”‚   โ”œโ”€โ”€ decoder.py           # Observation decoder
โ”‚   โ”œโ”€โ”€ actor.py             # Policy network
โ”‚   โ”œโ”€โ”€ critic.py            # Value network
โ”‚   โ””โ”€โ”€ reward_predictor.py  # Reward prediction
โ”œโ”€โ”€ training/
โ”‚   โ””โ”€โ”€ trainer.py           # Training loop
โ””โ”€โ”€ utils/
    โ”œโ”€โ”€ losses.py            # Loss functions
    โ””โ”€โ”€ replay_buffer.py     # Experience replay

API Reference

world_model.Agent

Agent(
    config=None,        # Dict or path to config JSON
    model_path=None,    # Path to pre-trained models
    device='auto',      # 'cpu', 'cuda', or 'auto'
)

Methods:

  • agent.step(obs, mask=None, deterministic=True) - Get action from observation
  • agent.imagine(horizon=20, start_obs=None) - Imagine future trajectories
  • agent.reset() - Reset internal state
  • agent.train(env, steps, **kwargs) - Train the agent
  • agent.save(path) - Save models
  • agent.load(path) - Load models
  • agent.evaluate(env_name, episodes) - Evaluate agent

world_model.DreamerTrainer

DreamerTrainer(config_path='config.json')

Methods:

  • trainer.train() - Full training loop
  • trainer.collect_experience(num_episodes) - Collect environment data
  • trainer.train_world_model(epochs) - Train world model
  • trainer.train_actor_critic(epochs) - Train policy
  • trainer.evaluate(num_episodes) - Evaluate performance

Configuration Parameters

Parameter Default Description
env_name CartPole-v1 Gymnasium environment
obs_type vector Observation type
obs_shape [4] Observation shape
action_type discrete Action type
latent_dim 64 Latent state dimension
hidden_dim 256 Hidden state dimension
batch_size 64 Training batch size
seq_len 50 Sequence length
imagine_horizon 25 Imagination steps
kl_beta 0.1 KL divergence weight
gamma 0.99 Discount factor
total_steps 50000 Training steps

Examples

See the examples/ directory for more usage examples:

  • quick_start.py - Basic training and inference
  • Custom environment integration
  • Advanced configuration options

Developer

Aryan Sanjay Chavan
๐Ÿ“ Chiplun, Kherdi, Maharashtra, India
๐Ÿ“ž +91 88579 12586
๐ŸŒ Portfolio
๐Ÿ“ง aryaanchavan1@gmail.com
๐Ÿ”— GitHub

License

MIT License - See LICENSE for details.

References

  1. Hafner et al. (2020). Dream to Control: Learning Behaviors by Latent Imagination. ICLR 2020
  2. Hafner et al. (2021). Mastering Atari with Discrete World Models. ICLR 2021
  3. Hafner et al. (2023). Mastering Diverse Domains through World Models. arXiv:2301.04104

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

arynoxtech_world_model-1.0.0.tar.gz (22.0 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

arynoxtech_world_model-1.0.0-py3-none-any.whl (24.3 kB view details)

Uploaded Python 3

File details

Details for the file arynoxtech_world_model-1.0.0.tar.gz.

File metadata

  • Download URL: arynoxtech_world_model-1.0.0.tar.gz
  • Upload date:
  • Size: 22.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.11

File hashes

Hashes for arynoxtech_world_model-1.0.0.tar.gz
Algorithm Hash digest
SHA256 1cbeabe6cbf0985c4e55aa87f625f74af7673ebf5bb5ba564e403c437d926f8a
MD5 4a4441046d9350c2fa8adcc68ab61299
BLAKE2b-256 3484c8dc9f1243220b5b5afdd0a5849b659c4ab9adb5d8c6e79d7e1675fa8bd5

See more details on using hashes here.

File details

Details for the file arynoxtech_world_model-1.0.0-py3-none-any.whl.

File metadata

File hashes

Hashes for arynoxtech_world_model-1.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 dc29dd586570ca0827d3275ac44e6628be71ea21c070d610520982e8809cf892
MD5 683d910f827154218c1d83d5af4a904c
BLAKE2b-256 7706f235d6ebb9481b2aad35abaa08b698ca761aacda71085040778c41bb45a6

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page