Downloads · 30 days
0
Nharen/Reward_Rush_SAC_Half_Cheetah
Reward_Rush_SAC_Half_Cheetah is a reinforcement learning model from Nharen. 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 stable-baselines3. The card lists the license as mit.
This repository contains a Soft Actor-Critic (SAC) agent trained for the HalfCheetah-v4 environment.
Downloads · 30 days
0
Access
Public
Updated Dec 31, 2025
Repo size
5.5 MB
Likes
0
Public
Click a slice to open those files.
.mp43.7 MB · 92%
From the Hugging Face model README
This repository contains a Soft Actor-Critic (SAC) agent trained for the HalfCheetah-v4 environment.
The SAC actor is a multi-layer perceptron with the following specifications:
mean + Linear(256, 6) for log_stdnet, mean, and log_std. Do not try to redefine layers with different names (fc1, fc2) unless you remap the keys.weights_only=True when loading .pth state dicts for safety.import torch
import torch.nn as nn
import gymnasium as gym
import numpy as np
from huggingface_hub import hf_hub_download
# Load stripped checkpoint
ckpt = torch.load(
hf_hub_download("Nharen/Reward_Rush_SAC_Half_Cheetah", "half_cheetah.pth"),
weights_only=True
)
obs_dim = ckpt["obs_dim"]
act_dim = ckpt["act_dim"]
hidden_dim = ckpt.get("hidden_dim", 256)
# SAC Gaussian Actor
class SACActor(nn.Module):
def __init__(self, obs_dim, act_dim, hidden_dim=256):
super().__init__()
self.net = nn.Sequential(
nn.Linear(obs_dim, hidden_dim),
nn.ReLU(),
nn.Linear(hidden_dim, hidden_dim),
nn.ReLU()
)
self.mean = nn.Linear(hidden_dim, act_dim)
self.log_std = nn.Linear(hidden_dim, act_dim)
def forward(self, obs):
x = self.net(obs)
mean = self.mean(x)
return torch.tanh(mean)
# Instantiate actor
actor = SACActor(obs_dim, act_dim, hidden_dim)
actor.load_state_dict(ckpt["actor_state_dict"])
actor.eval()
# Environment
env = gym.make("HalfCheetah-v4")
num_episodes = 100
episode_rewards = []
# Run evaluation
for ep in range(num_episodes):
obs, _ = env.reset()
done = False
ep_reward = 0.0
while not done:
with torch.no_grad():
obs_t = torch.tensor(obs, dtype=torch.float32).unsqueeze(0)
action = actor(obs_t).squeeze(0).cpu().numpy()
obs, reward, terminated, truncated, _ = env.step(action)
ep_reward += reward
done = terminated or truncated
episode_rewards.append(ep_reward)
print(f"Episode {ep+1:3d} | Reward: {ep_reward:.2f}")
env.close()
# Results
episode_rewards = np.array(episode_rewards)
print("\n===== Evaluation Summary =====")
print(f"Episodes run: {num_episodes}")
print(f"Mean reward: {episode_rewards.mean():.2f}")
print(f"Std reward: {episode_rewards.std():.2f}")
print(f"Min reward: {episode_rewards.min():.2f}")
print(f"Max reward: {episode_rewards.max():.2f}")