-
Notifications
You must be signed in to change notification settings - Fork 5.6k
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
[rllib][tune] How to save and later use the agent/model #7983
Comments
What I am using at the moment is a combination of the tune.run call and a customizable trainer function that specifies how often checkpoints are saved, implements a training curriculum and so on.
You can use this function either directly by calling
Note that when using tune you will end up with 2 folders in your directory. One generated by tune and the other by the trainer function. The latter contains your checkpoints. You can also wrap the training configuration in a Trainer class which implements a train, setup and save function but I have not tried that successfully. For inference you generate the agent again and load the checkpoints:
Then you can get the action using the pre-trained model like this: Often you don't want to use the training environment for inference because you want to avoid a physics simulation. The easiest ways would be to generate a fake environment with the same observation and action space and provide this to your agent via the config file. |
Awesome! This advice worked out great for me. Thank you! |
Any way to change the directory to which the agent is saved when calling Update: Ok, got it, just pass the path as arg. The path seems to be relative to the experiment directory, which contains some hash code. Any idea how to get the absolute path? |
Is it possible to restore an agent and continue training it with I'm looking for something like this (which doesn't work): # restore the agent outside of tune.run()
agent = PPOTrainer(config)
agent.restore("/path/checkpoint_41/checkpoint-41")
# then continue training it; this breaks
tune.run(agent, config) |
Hello @stefanbschneider! Can you explain how to change the directory where the agent is saved when you define the agent and then use agent.train() to train. Thank you! |
By setting the But I think I already resolved my question regarding restoring a trained agent. Thanks anyways! |
What is your question?
I've successfully used Tune to train an RL model, with checkpoints. I'd like to be able to 'save' the model so that I can use it later for inferencing. As an example, I will use an API to bring in data that is affectively my observations and I'd like to get from the saved model the actions.
I've been reading through the documentation and I think I'm starting to build the intuition on how to do this, but, I feel like I'm not quite their yet.
Any help will be greatly appreciated!
The text was updated successfully, but these errors were encountered: