-
Notifications
You must be signed in to change notification settings - Fork 555
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
Features/openai hacks #35
Open
richardrl
wants to merge
17
commits into
rail-berkeley:master
Choose a base branch
from
richardrl:features/openai-hacks
base: master
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
17 commits
Select commit
Hold shift + click to select a range
052a5c8
refactor gass epislon strategy name
richardrl 7969e31
unboundlocalerror, fetchstack2
richardrl af79a23
fetchstack 2 sending successfully...
richardrl 3378fe2
removed data gitignore
richardrl 000c2e7
changes
richardrl 830daaf
got gymfetchstack2 ec2 working
richardrl 088dae1
environments
richardrl ec231e7
Added additional settings from OpenAI HER paper enabling HER TD3 to w…
richardrl 51f9c17
Removing random files from tracked list...
richardrl 648e939
Git rm cached environment folder
richardrl 9245122
Rm more things
richardrl cee2a86
uhhh
richardrl 78150e8
ok
richardrl 050e86f
squashing cleanup
richardrl 97936cc
Update .gitignore
richardrl a768c46
Pull request changes
richardrl 91c3e2e
Merge branch 'features/openai-hacks' of github.com:richardrl/rlkit in…
richardrl 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 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 |
---|---|---|
@@ -1,3 +1,4 @@ | ||
data/ | ||
*/*/mjkey.txt | ||
**/.DS_STORE | ||
**/*.pyc | ||
|
This file contains 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
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains 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,149 @@ | ||
import gym | ||
|
||
import rlkit.torch.pytorch_util as ptu | ||
from rlkit.exploration_strategies.base import ( | ||
PolicyWrappedWithExplorationStrategy | ||
) | ||
from rlkit.exploration_strategies.gaussian_and_epsilon_strategy import ( | ||
GaussianAndEpsilonStrategy | ||
) | ||
from rlkit.torch.her.her import HerTd3 | ||
import rlkit.samplers.rollout_functions as rf | ||
|
||
|
||
from rlkit.torch.networks import FlattenMlp, MlpPolicy, QNormalizedFlattenMlp, CompositeNormalizedMlpPolicy | ||
from rlkit.torch.data_management.normalizer import CompositeNormalizer | ||
|
||
|
||
def experiment(variant): | ||
try: | ||
import robotics_recorder | ||
except ImportError as e: | ||
print(e) | ||
|
||
env = gym.make(variant['env_id']) | ||
es = GaussianAndEpsilonStrategy( | ||
action_space=env.action_space, | ||
max_sigma=.2, | ||
min_sigma=.2, # constant sigma | ||
epsilon=.3, | ||
) | ||
obs_dim = env.observation_space.spaces['observation'].low.size | ||
goal_dim = env.observation_space.spaces['desired_goal'].low.size | ||
action_dim = env.action_space.low.size | ||
|
||
shared_normalizer = CompositeNormalizer(obs_dim + goal_dim, action_dim, obs_clip_range=5) | ||
|
||
qf1 = QNormalizedFlattenMlp( | ||
input_size=obs_dim + goal_dim + action_dim, | ||
output_size=1, | ||
hidden_sizes=[400, 300], | ||
composite_normalizer=shared_normalizer | ||
) | ||
qf2 = QNormalizedFlattenMlp( | ||
input_size=obs_dim + goal_dim + action_dim, | ||
output_size=1, | ||
hidden_sizes=[400, 300], | ||
composite_normalizer=shared_normalizer | ||
) | ||
import torch | ||
policy = CompositeNormalizedMlpPolicy( | ||
input_size=obs_dim + goal_dim, | ||
output_size=action_dim, | ||
hidden_sizes=[400, 300], | ||
composite_normalizer=shared_normalizer, | ||
output_activation=torch.tanh | ||
) | ||
exploration_policy = PolicyWrappedWithExplorationStrategy( | ||
exploration_strategy=es, | ||
policy=policy, | ||
) | ||
|
||
from rlkit.data_management.obs_dict_replay_buffer import ObsDictRelabelingBuffer | ||
|
||
observation_key = 'observation' | ||
desired_goal_key = 'desired_goal' | ||
achieved_goal_key = desired_goal_key.replace("desired", "achieved") | ||
|
||
replay_buffer = ObsDictRelabelingBuffer( | ||
env=env, | ||
observation_key=observation_key, | ||
desired_goal_key=desired_goal_key, | ||
achieved_goal_key=achieved_goal_key, | ||
**variant['replay_buffer_kwargs'] | ||
) | ||
|
||
algorithm = HerTd3( | ||
her_kwargs=dict( | ||
observation_key='observation', | ||
desired_goal_key='desired_goal' | ||
), | ||
td3_kwargs = dict( | ||
env=env, | ||
qf1=qf1, | ||
qf2=qf2, | ||
policy=policy, | ||
exploration_policy=exploration_policy | ||
), | ||
replay_buffer=replay_buffer, | ||
**variant['algo_kwargs'] | ||
) | ||
|
||
if variant.get("save_video", True): | ||
rollout_function = rf.create_rollout_function( | ||
rf.multitask_rollout, | ||
max_path_length=algorithm.max_path_length, | ||
observation_key=algorithm.observation_key, | ||
desired_goal_key=algorithm.desired_goal_key, | ||
) | ||
video_func = get_video_save_func( | ||
rollout_function, | ||
env, | ||
algorithm.eval_policy, | ||
variant, | ||
) | ||
algorithm.post_epoch_funcs.append(video_func) | ||
|
||
algorithm.to(ptu.device) | ||
algorithm.train() | ||
|
||
|
||
if __name__ == "__main__": | ||
variant = dict( | ||
algo_kwargs=dict( | ||
num_epochs=5000, | ||
num_steps_per_epoch=1000, | ||
num_steps_per_eval=500, | ||
max_path_length=50, | ||
batch_size=128, | ||
discount=0.98, | ||
save_algorithm=True, | ||
), | ||
replay_buffer_kwargs=dict( | ||
max_size=100000, | ||
fraction_goals_rollout_goals=0.2, # equal to k = 4 in HER paper | ||
fraction_goals_env_goals=0.0, | ||
), | ||
render=False, | ||
env_id="FetchPickAndPlace-v1", | ||
doodad_docker_image="", # Set | ||
gpu_doodad_docker_image="", # Set | ||
save_video=False, | ||
save_video_period=50, | ||
) | ||
|
||
from rlkit.launchers.launcher_util import run_experiment | ||
|
||
run_experiment( | ||
experiment, | ||
exp_prefix="her_td3_gym_fetch_pnp_test", # Make sure no spaces... | ||
region="us-east-2", | ||
mode='here_no_doodad', | ||
variant=variant, | ||
use_gpu=True, # Note: online normalization is very slow without GPU. | ||
spot_price=.5, | ||
snapshot_mode='gap_and_last', | ||
snapshot_gap=100, | ||
num_exps_per_instance=2 | ||
) | ||
|
This file contains 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 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 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 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 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 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 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
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.
Thanks for this fix!