Scaling training when drawing unique assets each episode
max-reuter opened this issue · 4 comments
I'm calling a custom version of images_load
in resources.cpp
each episode, which draws a unique pattern on some assets based on the level seed. My concern is that, during training, the sprites
variable (map of shared pointers) may change as other envs
call images_load
(say num_envs=64
) asynchronously while another is in the middle of drawing its assets, causing that episode to draw assets that it didn't intend to.
Is this possible? How might I prove/disprove this? If it is possible, what is a way to draw unique assets per episode and scale up training to 64 num_envs
? At the moment, the best solution I can think of is to train with num_envs=1
.
The images in there are global read-only sorts of things, so yeah, it seems possible that you could have some issues. There's already some code to generate assets, but the assets will be still be static for the entire run, I believe.
One idea is that you could modify it so that each BasicAbstractGame
maintains copies of the original images (like image.copy()
deep copies) and initialize_asset_if_necessary
would re-initialize these with the randomized ones at the start of each episode (maybe by clearing the existing asset lists such as basic_assets
at the end of each episode). Would that work for your case?
hey, thanks for the guidance. could you please elaborate on how I might obtain and maintain those copies in BasicAbstractGame
and/or wipe the stored assets at (probably) BasicAbstractGame::game_reset
?
Not sure, maybe something like make basic_assets
use a shared pointer to a copy of an image instead of the original and clear it in game_reset
?
that worked perfectly, thanks!
For reference, I made these changes that worked for my purposes:
(1) I changed asset_ptr = get_asset_ptr(names[theme]);
to
asset_ptr = std::make_shared<QImage>(get_asset_ptr(names[theme])->copy());
in BasicAbstractGame::initialize_asset_if_necessary
, and
(2) the very first thing I do in BasicAbstractGame::game_reset()
is
basic_assets.clear();
basic_assets.resize(USE_ASSET_THRESHOLD * MAX_IMAGE_THEMES, nullptr);