mirror of
https://github.com/wassname/ray.git
synced 2026-08-17 11:25:34 +08:00
[RaySGD] Add tqdm logging to TorchTrainer (#7588)
* Update issue templates * Init fp16 * fp16 and schedulers * scheduler linking and fp16 * to fp16 * loss scaling and documentation * more documentation * add tests, refactor config * moredocs * more docs * fix logo, add test mode, add fp16 flag * fix tests * fix scheduler * fix apex * improve safety * fix tests * fix tests * remove pin memory default * rm * fix * Update doc/examples/doc_code/raysgd_torch_signatures.py * fix * migrate changes from other PR * ok thanks * pass * signatures * lint' * Update python/ray/experimental/sgd/pytorch/utils.py * Apply suggestions from code review Co-Authored-By: Edward Oakes <ed.nmi.oakes@gmail.com> * should address most comments * comments * fix this ci * first_pass * add overrides * override * fixing up operators * format * sgd * constants * rm * revert * Checkpoint the basics * End of day checkpoint * Checkpoint log-to-head implementation * Checkpoint * Add actor-based batch log reporting, currently segfaults * Work around progress segfault * Fix some stuff in quicktorch * Make things more customizable * Quality of life fixes * More quality of life * Move tqdm logic to training_operator * Update examples * Fix some minor bugs * Fix merge * Fix small things, add pbar to dcgan * Run format.sh * Fix missing epoch number for batch pbar * Address PR comments * Fix float is not subscriptable * Add train_loss to pbar by default * Isolate tqdm code into a handler system * Format * Remove the batch_logs_reporter from distributed runner as well * Check if the train_loss is avaialbale before using it * Enable tqdm in the dcgan example * Fix a crash in no-handler trainers * Fix * Allow not calling set_reporters for tests Co-authored-by: Philipp Moritz <pcmoritz@gmail.com> Co-authored-by: Richard Liaw <rliaw@berkeley.edu> Co-authored-by: Edward Oakes <ed.nmi.oakes@gmail.com>
This commit is contained in:
co-authored by
Edward Oakes
Philipp Moritz
Richard Liaw
parent
54a892bb84
commit
e95455b7d7
@@ -4,19 +4,22 @@ import logging
|
||||
import numbers
|
||||
import tempfile
|
||||
import time
|
||||
import asyncio
|
||||
import torch
|
||||
import torch.distributed as dist
|
||||
|
||||
import ray
|
||||
|
||||
from ray.exceptions import RayActorError
|
||||
from ray.tune import Trainable
|
||||
from ray.tune.trial import Resources
|
||||
from ray.util.sgd.torch.distributed_torch_runner import (
|
||||
DistributedTorchRunner)
|
||||
from ray.util.sgd import utils
|
||||
from ray.util.sgd.utils import NUM_SAMPLES, BATCH_SIZE
|
||||
from ray.util.sgd.utils import check_for_failure, NUM_SAMPLES, BATCH_SIZE
|
||||
from ray.util.sgd.torch.torch_runner import TorchRunner
|
||||
from ray.util.sgd.torch.constants import VALID_SCHEDULER_STEP
|
||||
from ray.util.sgd.torch.constants import (VALID_SCHEDULER_STEP,
|
||||
BATCH_LOGS_RATE_LIMIT)
|
||||
from ray.util.sgd.torch.tqdm_handler import TqdmHandler
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
RESIZE_COOLDOWN_S = 10
|
||||
@@ -146,6 +149,7 @@ class TorchTrainer:
|
||||
use_gpu=False,
|
||||
backend="auto",
|
||||
use_fp16=False,
|
||||
tqdm=False,
|
||||
apex_args=None,
|
||||
scheduler_step_freq="batch",
|
||||
num_replicas=None,
|
||||
@@ -217,6 +221,10 @@ class TorchTrainer:
|
||||
self._num_failures = 0
|
||||
self._last_resize = float("-inf")
|
||||
|
||||
self.handlers = []
|
||||
if tqdm:
|
||||
self.handlers.append(TqdmHandler())
|
||||
|
||||
_validate_scheduler_step_freq(scheduler_step_freq)
|
||||
self.scheduler_step_freq = scheduler_step_freq
|
||||
|
||||
@@ -271,6 +279,8 @@ class TorchTrainer:
|
||||
self.apply_all_workers(self.initialization_hook)
|
||||
# Get setup tasks in order to throw errors on failure
|
||||
ray.get(self.workers[0].setup.remote())
|
||||
ray.get(self.workers[0].set_reporters.remote(
|
||||
[h.create_reporter() for h in self.handlers]))
|
||||
else:
|
||||
# Generate actor class
|
||||
Runner = ray.remote(
|
||||
@@ -303,6 +313,11 @@ class TorchTrainer:
|
||||
worker.setup.remote(address, i, len(self.workers))
|
||||
for i, worker in enumerate(self.workers)
|
||||
])
|
||||
ray.get([
|
||||
w.set_reporters.remote(
|
||||
[h.create_reporter() for h in self.handlers])
|
||||
for w in self.workers
|
||||
])
|
||||
|
||||
def train(self,
|
||||
num_steps=None,
|
||||
@@ -359,6 +374,9 @@ class TorchTrainer:
|
||||
logger.info("Resize opportunity detected. Attempting to scale up.")
|
||||
self._resize_workers(checkpoint=checkpoint)
|
||||
|
||||
for h in self.handlers:
|
||||
h.record_train_info(info, num_steps)
|
||||
|
||||
success, worker_stats = self._train_epoch(
|
||||
num_steps=num_steps, profile=profile, info=info)
|
||||
# Fault handling
|
||||
@@ -395,14 +413,42 @@ class TorchTrainer:
|
||||
stats[stat_key] = worker_stats[0][stat_key]
|
||||
return stats
|
||||
|
||||
def _train_epoch(self, num_steps=None, profile=False, info=None):
|
||||
worker_stats = [
|
||||
def _train_epoch(self,
|
||||
num_steps=None,
|
||||
profile=False,
|
||||
info=None,
|
||||
batch_logs_handler=None):
|
||||
worker_trains = [
|
||||
w.train_epoch.remote(
|
||||
num_steps=num_steps, profile=profile, info=info)
|
||||
for w in self.workers
|
||||
]
|
||||
success = utils.check_for_failure(worker_stats)
|
||||
return success, worker_stats
|
||||
|
||||
if not self.handlers:
|
||||
success = check_for_failure(worker_trains)
|
||||
return success, worker_trains
|
||||
|
||||
unfinished = worker_trains
|
||||
try:
|
||||
while len(unfinished) > 0:
|
||||
finished, unfinished = ray.wait(
|
||||
unfinished, timeout=BATCH_LOGS_RATE_LIMIT)
|
||||
|
||||
# throw errors on agent failure
|
||||
finished = ray.get(finished)
|
||||
|
||||
futures = [h.update() for h in self.handlers]
|
||||
loop = asyncio.get_event_loop()
|
||||
if loop.is_closed():
|
||||
loop = asyncio.new_event_loop()
|
||||
asyncio.set_event_loop(loop)
|
||||
loop.run_until_complete(asyncio.wait(futures))
|
||||
loop.close()
|
||||
|
||||
return True, worker_trains
|
||||
except RayActorError as exc:
|
||||
logger.exception(str(exc))
|
||||
return False, worker_trains
|
||||
|
||||
def apply_all_workers(self, fn):
|
||||
"""Run a function on all operators on the workers.
|
||||
|
||||
Reference in New Issue
Block a user