Lazy importing of agents - #247
Merged
Merged
Conversation
jonbinney
requested review from
adamantivm,
alejandromarcu,
muralx and
shoemakerlevy9
July 7, 2025 17:17
jonbinney
commented
Jul 7, 2025
| if value == "player_0": | ||
| value = 0 | ||
| else: | ||
| value = 1 |
Owner
Author
There was a problem hiding this comment.
I fixed this just so I could run our benchmark
jonbinney
commented
Jul 7, 2025
|
|
||
|
|
||
| # Register the agent with the registry | ||
| AgentRegistry.register(Agent._friendly_name(SB3PPOAgent.__name__), SB3PPOAgent) |
Owner
Author
There was a problem hiding this comment.
I don't think this was ever needed, since the agent is registered in agents.__init__
Collaborator
|
LGTM |
alejandromarcu
approved these changes
Jul 7, 2025
alejandromarcu
left a comment
Collaborator
There was a problem hiding this comment.
LGTM, I don't think we need anything fancier, this is a nice approach
This file contains hidden or 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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Instead of importing and registering the class for each agent in
agents/__init__.py, we now just register the name of the class and the name of the module it is in. The AgentRegistry dynamically imports the module for each agent as needed when they are created inAgentRegisry.create_from_encoded_name(...). On my computer if I just want to train alphazero, this reduces the startup/import time from ~4 seconds to ~2 seconds.I tested by running our benchmarks and tests, and running
train.pywith just alphazero. Let me know if I missed any scripts that I might have broken and should test.There are some fancier approaches to this that would involve using python's lazy import mechanism and some wrapper, but that felt like more magic than we needed.