Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
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
2 changes: 1 addition & 1 deletion pufferlib/config/default.ini
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ project = ablations
seed = 42
torch_deterministic = True
cpu_offload = False
device = cuda
device = default
Copy link
Author

Choose a reason for hiding this comment

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

Not sure if this is controversial or not, but just means people don't need to manually pass --train.device mps every time, automatically select the best one based off of the get_accelerator function

optimizer = muon
precision = float32
total_timesteps = 10_000_000
Expand Down
11 changes: 9 additions & 2 deletions pufferlib/pufferl.py
Original file line number Diff line number Diff line change
Expand Up @@ -694,6 +694,12 @@ def abbreviate(num, b2, c2):
else:
return f'{b2}{num/1e12:.2f}{c2}T'

def get_accelerator(device):
if device == 'default':
return torch.accelerator.current_accelerator() if torch.accelerator.is_available() else 'cpu'
else:
return device

def duration(seconds, b2, c2):
if seconds < 0:
return f"{b2}0{c2}s"
Expand Down Expand Up @@ -994,7 +1000,7 @@ def eval(env_name, args=None, vecenv=None, policy=None):
ob, info = vecenv.reset()
driver = vecenv.driver_env
num_agents = vecenv.observation_space.shape[0]
device = args['train']['device']
device = get_accelerator(args['train']['device'])

state = {}
if args['train']['use_rnn']:
Expand Down Expand Up @@ -1146,7 +1152,7 @@ def load_policy(args, vecenv, env_name=''):
module_name = 'pufferlib.ocean' if package == 'ocean' else f'pufferlib.environments.{package}'
env_module = importlib.import_module(module_name)

device = args['train']['device']
device = get_accelerator(args['train']['device'])
policy_cls = getattr(env_module.torch, args['policy_name'])
policy = policy_cls(vecenv.driver_env, **args['policy'])

Expand Down Expand Up @@ -1284,6 +1290,7 @@ def auto_type(value):

args['train']['env'] = args['env_name'] or '' # for trainer dashboard
args['train']['use_rnn'] = args['rnn_name'] is not None
args['train']['device'] = get_accelerator(args['train']['device'])
return args

def main():
Expand Down