-
Notifications
You must be signed in to change notification settings - Fork 1
Add evaluation episodes in a new thread #7
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
Open
JacobHA
wants to merge
11
commits into
main
Choose a base branch
from
jacob/eval-thread
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
5541f92
aadd evaluation episodes in a new thread
JacobHA d38cada
comparison profiling, polyak needs device, new NullLogger, new polyak
JacobHA d826bf6
polyak
JacobHA 57c2b95
fix test, don't tear down prematurely
JacobHA 3785c49
Merge pull request #8 from JacobHA/jacob/eval-thread
JacobHA fcd0acc
adding kwarg for threading, typo
JacobHA 99e156a
Merge branch 'jacob/dev' of https://github.com/JacobHA/BARL into jaco…
JacobHA a6a79d2
added conditionals for if the agent's eval should be threaded
JacobHA c692f0f
Merge branch 'main' into jacob/eval-thread
JacobHA 69cd251
Merge pull request #9 from JacobHA/jacob/dev
JacobHA 63c3ebb
trying to rewrite threading for proper logging
JacobHA File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -5,4 +5,6 @@ __pycache__ | |
| *.tfevents.* | ||
| logs | ||
| *.png | ||
| *.prof | ||
| *.prof | ||
| *.sh | ||
| .pytest_cache | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,87 @@ | ||
| import time | ||
| import numpy as np | ||
| from Architectures import make_atari_nature_cnn, make_mlp | ||
| from DQN import DQN | ||
| import gymnasium as gym | ||
|
|
||
| from Logger import NullLogger | ||
|
|
||
| # env = gym.make('CartPole-v1') | ||
| n_steps = 10000 | ||
| # Note: we eliminate all logging and evaluation for this comparison | ||
|
|
||
| # sb3_agent = sb3_DQN('MlpPolicy', | ||
| # env, | ||
| # learning_rate=0.001, | ||
| # buffer_size=n_steps, | ||
| # learning_starts=0, | ||
| # target_update_interval=10, | ||
| # ) | ||
| # our_agent = our_DQN(env, | ||
| # loggers=(NullLogger(),), | ||
| # architecture = make_mlp, | ||
| # architecture_kwargs = {'input_dim': env.observation_space.shape[0], | ||
| # 'output_dim': env.action_space.n, | ||
| # 'hidden_dims': [64, 64], | ||
| # 'device': 'cpu'}, | ||
| # learning_rate=0.001, | ||
| # train_interval=4, | ||
| # gradient_steps=1, | ||
| # batch_size=32, | ||
| # use_target_network=True, | ||
| # target_update_interval=10, | ||
| # buffer_size=n_steps, | ||
| # exploration_fraction=0.1, | ||
| # log_interval=n_steps, | ||
| # polyak_tau=1.0, | ||
| # device='cpu') | ||
|
|
||
| def time_learning(agent, n_steps): | ||
| start = time.time() | ||
| agent.learn(n_steps) | ||
| end = time.time() | ||
| return end - start | ||
|
|
||
|
|
||
|
|
||
| env = 'ALE/Pong-v5' | ||
|
|
||
| threaded_agent = DQN(env, | ||
| loggers=(NullLogger(),), | ||
| architecture=make_atari_nature_cnn, | ||
| architecture_kwargs={'output_dim': gym.make(env).action_space.n}, | ||
| learning_rate=0.001, | ||
| train_interval=4, | ||
| gradient_steps=1, | ||
| batch_size=32, | ||
| use_target_network=True, | ||
| target_update_interval=100, | ||
| buffer_size=n_steps, | ||
| exploration_fraction=0.1, | ||
| log_interval=n_steps // 10, | ||
| polyak_tau=1.0, | ||
| use_threaded_eval=True) | ||
|
|
||
|
|
||
| unthreaded_agent = DQN(env, | ||
| loggers=(NullLogger(),), | ||
| architecture=make_atari_nature_cnn, | ||
| architecture_kwargs={'output_dim': gym.make(env).action_space.n}, | ||
| learning_rate=0.001, | ||
| train_interval=4, | ||
| gradient_steps=1, | ||
| batch_size=32, | ||
| use_target_network=True, | ||
| target_update_interval=100, | ||
| buffer_size=n_steps, | ||
| exploration_fraction=0.1, | ||
| log_interval=n_steps // 10, | ||
| polyak_tau=1.0, | ||
| use_threaded_eval=False) | ||
|
|
||
|
|
||
| unthreaded_time = np.mean([time_learning(unthreaded_agent, n_steps) for _ in range(3)]) | ||
| threaded_time = np.mean([time_learning(threaded_agent, n_steps) for _ in range(3)]) | ||
|
|
||
| print(f"Un-threaded (standard) evaluation training took {unthreaded_time:.2f} seconds") | ||
| print(f"Threaded (new) evaluation training agent took {threaded_time:.2f} seconds") |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
looks like we are waiting for the finish of the old worker but not starting the new worker thread when
self.use_threaded_evalis true