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
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 observationagent.imagine(horizon=20, start_obs=None)- Imagine future trajectoriesagent.reset()- Reset internal stateagent.train(env, steps, **kwargs)- Train the agentagent.save(path)- Save modelsagent.load(path)- Load modelsagent.evaluate(env_name, episodes)- Evaluate agent
world_model.DreamerTrainer
DreamerTrainer(config_path='config.json')
Methods:
trainer.train()- Full training looptrainer.collect_experience(num_episodes)- Collect environment datatrainer.train_world_model(epochs)- Train world modeltrainer.train_actor_critic(epochs)- Train policytrainer.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
- Hafner et al. (2020). Dream to Control: Learning Behaviors by Latent Imagination. ICLR 2020
- Hafner et al. (2021). Mastering Atari with Discrete World Models. ICLR 2021
- Hafner et al. (2023). Mastering Diverse Domains through World Models. arXiv:2301.04104
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
1cbeabe6cbf0985c4e55aa87f625f74af7673ebf5bb5ba564e403c437d926f8a
|
|
| MD5 |
4a4441046d9350c2fa8adcc68ab61299
|
|
| BLAKE2b-256 |
3484c8dc9f1243220b5b5afdd0a5849b659c4ab9adb5d8c6e79d7e1675fa8bd5
|
File details
Details for the file arynoxtech_world_model-1.0.0-py3-none-any.whl.
File metadata
- Download URL: arynoxtech_world_model-1.0.0-py3-none-any.whl
- Upload date:
- Size: 24.3 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.13.11
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
dc29dd586570ca0827d3275ac44e6628be71ea21c070d610520982e8809cf892
|
|
| MD5 |
683d910f827154218c1d83d5af4a904c
|
|
| BLAKE2b-256 |
7706f235d6ebb9481b2aad35abaa08b698ca761aacda71085040778c41bb45a6
|