-
Notifications
You must be signed in to change notification settings - Fork 17
spawn service based trainer #131
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
Changes from 2 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -15,42 +15,31 @@ | |
import sys | ||
|
||
from forge.actors import ReplayBuffer, RLTrainer | ||
|
||
from forge.cli.config import parse | ||
from forge.controller import spawn_actors | ||
from forge.controller.service import ServiceConfig, shutdown_service, spawn_service | ||
from omegaconf import DictConfig | ||
|
||
logger = logging.getLogger(__name__) | ||
logger.setLevel(logging.INFO) | ||
|
||
|
||
async def run(cfg: DictConfig): | ||
trainer, buffer = await asyncio.gather( | ||
spawn_actors( | ||
name="trainer", | ||
actor_cls=RLTrainer, | ||
cfg=cfg.trainer, | ||
processes=cfg.trainer.pop("processes"), | ||
set_address=True, | ||
), | ||
spawn_actors( | ||
name="replay_buffer", | ||
actor_cls=ReplayBuffer, | ||
cfg=cfg.replay_buffer, | ||
processes=cfg.replay_buffer.pop("processes"), | ||
), | ||
) | ||
print("Actors spawned") | ||
|
||
# Initialize everything | ||
await asyncio.gather( | ||
buffer.setup.call(), | ||
trainer.setup.call(), | ||
trainer = await spawn_service( | ||
ServiceConfig(procs_per_replica=1, with_gpus=True, num_replicas=4), | ||
|
||
RLTrainer, | ||
**cfg.trainer, | ||
) | ||
replay_buffer = await spawn_service( | ||
ServiceConfig(procs_per_replica=1, num_replicas=1), | ||
ReplayBuffer, | ||
**cfg.replay_buffer, | ||
) | ||
print("Setup done") | ||
print("Services initialized....") | ||
|
||
print("shutting down...") | ||
await asyncio.gather(*[a.mesh.stop() for a in [trainer]]) | ||
await shutdown_service(trainer) | ||
await shutdown_service(replay_buffer) | ||
|
||
|
||
@parse | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These should still be in a asyncio.gather