Downloads · 30 days
0
MohamedMaher003/LunarLander-v3-SAC
LunarLander-v3-SAC is a reinforcement learning model from MohamedMaher003. Use it for the reinforcement learning task on the model card, and read the license before you ship it in a product. It is set up for pytorch. The card lists the license as mit.
This is a trained Soft Actor-Critic (SAC) agent for the LunarLander-v3 environment from Gymnasium.
Downloads · 30 days
0
Access
Public
Updated Dec 10, 2025
Repo size
1.4 MB
Likes
0
Public
Click a slice to open those files.
.pth1.4 MB · 99%
From the Hugging Face model README
This is a trained Soft Actor-Critic (SAC) agent for the LunarLander-v3 environment from Gymnasium.
This model was trained using the SAC algorithm with continuous action space on the LunarLander-v3 environment. The agent learns to safely land a lunar module on a landing pad using continuous thrust controls.
SAC is an off-policy actor-critic algorithm based on the maximum entropy reinforcement learning framework. Key features:
| Parameter | Value |
|---|---|
| Total Timesteps | 750,000 |
| Start Timesteps (Random) | 10,000 |
| Batch Size | 256 |
| Discount Factor (γ) | 0.99 |
| Soft Update Rate (τ) | 0.005 |
| Entropy Coefficient (α) | 0.2 |
| Learning Rate | 3e-4 |
| Replay Buffer Capacity | 500,000 |
| Network Architecture | MLP (256, 256) |
LunarLander-v3Input (8) → Linear(256) → ReLU → Linear(256) → ReLU → [Mean(2), Log_Std(2)]
Input (8 + 2) → Linear(256) → ReLU → Linear(256) → ReLU → Q-value(1)
| File | Description |
|---|---|
sac_model_actor.pth | Actor (policy) network weights |
sac_model_critic.pth | Twin critic network weights |
sac_model_critic_target.pth | Target critic network weights |
pip install gymnasium[box2d] torch numpy
import torch
import numpy as np
import gymnasium as gym
# Define the Actor Network
class ActorNetwork(torch.nn.Module):
def __init__(self, state_dim, action_dim, max_action):
super(ActorNetwork, self).__init__()
self.l1 = torch.nn.Linear(state_dim, 256)
self.l2 = torch.nn.Linear(256, 256)
self.mean = torch.nn.Linear(256, action_dim)
self.log_std_layer = torch.nn.Linear(256, action_dim)
self.max_action = float(max_action)
def forward(self, state):
x = torch.nn.functional.relu(self.l1(state))
x = torch.nn.functional.relu(self.l2(x))
mean = self.mean(x)
log_std = self.log_std_layer(x)
log_std = torch.clamp(log_std, -20.0, 2.0)
return mean, log_std
# Download and load the model
from huggingface_hub import hf_hub_download
# Download model file
actor_path = hf_hub_download(
repo_id="MohamedMaher003/LunarLander-v3-SAC",
filename="sac_model_actor.pth"
)
# Initialize environment and model
env = gym.make("LunarLander-v3", continuous=True, render_mode="human")
state_dim = 8
action_dim = 2
max_action = 1.0
# Load actor
device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
actor = ActorNetwork(state_dim, action_dim, max_action).to(device)
actor.load_state_dict(torch.load(actor_path, map_location=device))
actor.eval()
# Run evaluation
def select_action(state, actor, device):
with torch.no_grad():
state_tensor = torch.FloatTensor(state).unsqueeze(0).to(device)
mean, _ = actor(state_tensor)
action = torch.tanh(mean) * actor.max_action
return action.cpu().numpy().flatten()
state, _ = env.reset()
done = False
total_reward = 0
while not done:
action = select_action(state, actor, device)
state, reward, terminated, truncated, _ = env.step(action)
total_reward += reward
done = terminated or truncated
print(f"Episode Reward: {total_reward:.2f}")
env.close()
The full training implementation is available at: GitHub Repository
Training was done using:
The trained agent achieves:
If you use this model, please cite:
@misc{maher2024sac-lunarlander,
author = {Mohamed Maher},
title = {SAC Agent for LunarLander-v3},
year = {2024},
publisher = {Hugging Face},
howpublished = {\url{https://huggingface.co/MohamedMaher003/LunarLander-v3-SAC}}
}
Mohamed Maher - Hugging Face Profile
This model was trained as part of a Reinforcement Learning course assignment on State-of-the-Art Model-Free Algorithms at cairo university faculty of engineering.