Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor hopper training loop and model loading #66

Merged
merged 1 commit into from
Nov 26, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 15 additions & 15 deletions gym/hopper.py
Original file line number Diff line number Diff line change
Expand Up @@ -367,24 +367,24 @@ def main():
global_best_reward = float('-inf') # Track best reward across all phases

# Training phases
# for phase in range(10):
# print(f"\n📈 Training Phase {phase + 1}")
for phase in range(10):
print(f"\n📈 Training Phase {phase + 1}")

# try:
# checkpoint = torch.load("gym/models/hopper_best.pth", weights_only=True)
# ai.load_model(checkpoint)
# global_best_reward = float(checkpoint.get('best_reward', float('-inf')))
# print(f"Loaded best model (previous best reward: {global_best_reward:.1f})")
# except (FileNotFoundError, RuntimeError) as e:
# print(f"No saved model found: {e}")
# print("Starting with untrained agent")
try:
checkpoint = torch.load("gym/models/hopper_best.pth", weights_only=True)
ai.load_model(checkpoint)
global_best_reward = float(checkpoint.get('best_reward', float('-inf')))
print(f"Loaded best model (previous best reward: {global_best_reward:.1f})")
except (FileNotFoundError, RuntimeError) as e:
print(f"No saved model found: {e}")
print("Starting with untrained agent")

# # Pass global best reward to train
# success = ai.train(num_episodes=100, previous_best=global_best_reward)
# Pass global best reward to train
success = ai.train(num_episodes=100, previous_best=global_best_reward)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

issue (code-quality): Use named expression to simplify assignment and conditional (use-named-expression)


# if success:
# print("🎯 Reached solution threshold! Moving to demonstration.")
# break
if success:
print("🎯 Reached solution threshold! Moving to demonstration.")
break

# Load and play best model
print("\n🦘 Loading best model for demonstration...")
Expand Down
Loading