# Saving best checkpoint - tune is saving first iterations instead

**URL:** <https://discuss.ray.io/t/saving-best-checkpoint-tune-is-saving-first-iterations-instead/3826>\
**Category:** Ray Tune\
**Created:** [October 15, 2021, 11:19am UTC](https://discuss.ray.io/t/saving-best-checkpoint-tune-is-saving-first-iterations-instead/3826 "2021-10-15T11:19:33Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![TheExGenesis](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.ray.io/theexgenesis/32/1502_2.png) [@TheExGenesis](https://discuss.ray.io/u/TheExGenesis)\
**Post date:** [October 15, 2021, 11:19am UTC](https://discuss.ray.io/t/saving-best-checkpoint-tune-is-saving-first-iterations-instead/3826/1 "2021-10-15T11:19:33Z")

</div>

Hi all, I’m trying to checkpoint only the best iterations of my model, but when I check, only the first 5 checkpoints (because of `keep_checkpoint_num=5`) and the last one are saved, like so:

```auto
checkpoint_010001 checkpoint_010003 checkpoint_010005 events.out.tfevents.1634291196.LAPTOP-7VGTS0VK params.pkl result.json
checkpoint_010002 checkpoint_010004 checkpoint_013663 params.json progress.csv

```

My `tune.run` call:

```auto
        scheduler = AsyncHyperBandScheduler(
            time_attr="training_iteration",
            grace_period=5 * 60,
            max_t=1000000 * 60,
        )

        print("Training automatically with Ray Tune")
        analysis = tune.run(
            args.run,
            config=config,
            stop=stop,
            checkpoint_freq=1,
            keep_checkpoints_num=5,
            checkpoint_score_attr="episode_reward_mean",
            metric="episode_reward_mean",
            mode="max",
            callbacks=[
                WandbLoggerCallback(
                    group=name_run(config, ""),
                    api_key_file=".wandb_api_key",
                    project="egt-rl",
                ),
            ],
            scheduler=scheduler,
            name=name_run(config, ""),
        )

```

Any idea why this is happening? Intended behavior is saving the 5-best models by episode\_reward\_mean. Keeping the last one too.

---

<div class="post-metadata">

**Author:** ![kai](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.ray.io/kai/32/3380_2.png) [@kai](https://discuss.ray.io/u/kai)\
**Post date:** [October 18, 2021, 11:43am UTC](https://discuss.ray.io/t/saving-best-checkpoint-tune-is-saving-first-iterations-instead/3826/2 "2021-10-18T11:43:28Z")

</div>

What kind of trainable are you training (or environment if using rllib)? Does your run converge (i.e. are you seeing higher rewards over time)?
