Downloads · 30 days
0
Nharen/Reward_Rush_SAC_Mountain_Car
Reward_Rush_SAC_Mountain_Car 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 MountainCarContinuous-v0 environment.
Downloads · 30 days
0
Access
Public
Updated Dec 31, 2025
Repo size
1.1 MB
Likes
0
Public
Click a slice to open those files.
.pth812 KB · 72%
From the Hugging Face model README
This repository contains a Soft Actor-Critic (SAC) agent trained for the MountainCarContinuous-v0 environment.
The model uses a multi-layer perceptron actor with the following specifications:
Note: The final layer outputs two values representing the mean and log standard deviation. For inference, only the first value (mean) is used, passed through a tanh activation function to bound the action to the [-1, 1] range.
import torch
import torch.nn as nn
import gymnasium as gym
import numpy as np
from huggingface_hub import hf_hub_download
class SACPolicy(nn.Module):
def __init__(self):
super(SACPolicy, self).__init__()
self.net = nn.Sequential(
nn.Linear(2, 256),
nn.ReLU(),
nn.Linear(256, 256),
nn.ReLU(),
nn.Linear(256, 2)
)
def forward(self, x):
out = self.net(x)
return torch.tanh(out[:, 0:1])
def run_mountain_car_test():
path = hf_hub_download(repo_id="Nharen/Reward_Rush_SAC_Mountain_Car", filename="Mountain_car.pth")
model = SACPolicy()
state_dict = torch.load(path, map_location='cpu', weights_only=True)
if isinstance(state_dict, dict) and "actor_state_dict" in state_dict:
state_dict = state_dict["actor_state_dict"]
elif isinstance(state_dict, dict) and "state_dict" in state_dict:
state_dict = state_dict["state_dict"]
model.load_state_dict(state_dict)
model.eval()
env = gym.make("MountainCarContinuous-v0")
total_rewards = []
for _ in range(100):
state, _ = env.reset()
episode_reward = 0
done = False
while not done:
state_t = torch.as_tensor(state, dtype=torch.float32).unsqueeze(0)
with torch.no_grad():
action = model(state_t).cpu().numpy().flatten()
state, reward, terminated, truncated, _ = env.step(action)
episode_reward += reward
done = terminated or truncated
total_rewards.append(episode_reward)
print(f"Average Reward: {np.mean(total_rewards)}")
env.close()
if __name__ == "__main__":
run_mountain_car_test()