# Selecting best checkpoint to keep training in tune

**URL:** <https://discuss.ray.io/t/selecting-best-checkpoint-to-keep-training-in-tune/582>\
**Category:** Ray Tune\
**Created:** [January 25, 2021, 10:33am UTC](https://discuss.ray.io/t/selecting-best-checkpoint-to-keep-training-in-tune/582 "2021-01-25T10:33:03Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![sven1977](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.ray.io/sven1977/32/53_2.png) [@sven1977](https://discuss.ray.io/u/sven1977)\
**Post date:** [January 25, 2021, 10:33am UTC](https://discuss.ray.io/t/selecting-best-checkpoint-to-keep-training-in-tune/582/1 "2021-01-25T10:33:03Z")

</div>

O.S.Tov asked this question on the Slack channel.

Please do not use the Slack channel anymore for questions on RLlib! All discussions should be moved here for better searchability and documentation of issues and questions. Thank you.

* * *

Hi, I’ve been training a PPO agent in a jupyter notebook using analysis = tune.run(), I’ve added a checkpoint\_freq=10 and checkpoint\_at\_end=True as arguments. I want to load the best agent without using the ‘analysis’ object since this one is only available at the current python session (using the .get\_best\_trial).I’ve tried to instantiate a new ExperimentAnalysis object by providing the path to the .json file representing that specific run but I cannot use .best\_get\_trial the same wayThere seems to be a bit of confusion about the whole saving/loading agents procedure, if someone could please clarify the process I think it would be very helpful to the communityThanks

`analysis = tune.run(`  
` PPOTrainer,`  
` stop=stop,`  
` config=config,`  
` local_dir=log_dir,`  
` checkpoint_at_end=True,`  
` checkpoint_freq=10,`  
` name='PPO_run_1')` `checkpoints = analysis.get_trial_checkpoints_paths(`  
` trial=analysis.get_best_trial('episode_reward_mean', mode='max'),`  
` metric='episode_reward_mean')` `checkpoint_path = checkpoints[0][0]` `agent = PPOTrainer(config=config, env='TradingEnv')`  
`agent.restore(checkpoint_path)`

This is the code I’ve been using so far, if for some reason the python session isn’t available, the “analysis” object cannot be used anymore.
