Skip to content

Commit

Permalink
fix default arg (#1927)
Browse files Browse the repository at this point in the history
* fix default

* formatting errors

* update

* flake8
  • Loading branch information
Borda authored and justusschock committed Jun 29, 2020
1 parent 83694c0 commit 5492245
Show file tree
Hide file tree
Showing 7 changed files with 30 additions and 24 deletions.
4 changes: 2 additions & 2 deletions pytorch_lightning/core/saving.py
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,6 @@ def save_hparams_to_yaml(config_yaml, hparams: Union[dict, Namespace]) -> None:
def convert(val: str) -> Union[int, float, bool, str]:
try:
return ast.literal_eval(val)
except (ValueError, SyntaxError) as e:
log.debug(e)
except (ValueError, SyntaxError) as err:
log.debug(err)
return val
2 changes: 1 addition & 1 deletion pytorch_lightning/loggers/comet.py
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ def __init__(self,
if experiment_name:
try:
self.name = experiment_name
except TypeError as e:
except TypeError:
log.exception("Failed to set experiment name for comet.ml logger")
self._kwargs = kwargs

Expand Down
4 changes: 2 additions & 2 deletions pytorch_lightning/overrides/data_parallel.py
Original file line number Diff line number Diff line change
Expand Up @@ -177,9 +177,9 @@ def _worker(i, module, input, kwargs, device=None):

with lock:
results[i] = output
except Exception as e:
except Exception as ex:
with lock:
results[i] = e
results[i] = ex

# TODO: fix hack (maybe not a hack)
# make sure each module knows what training state it's in...
Expand Down
2 changes: 1 addition & 1 deletion pytorch_lightning/trainer/distrib_data_parallel.py
Original file line number Diff line number Diff line change
Expand Up @@ -277,7 +277,7 @@ def configure_slurm_ddp(self, num_gpu_nodes):
should_fake = int(os.environ['FAKE_SLURM_MANAGING_TASKS'])
if should_fake:
self.is_slurm_managing_tasks = True
except Exception as e:
except Exception:
pass

# notify user the that slurm is managing tasks
Expand Down
37 changes: 22 additions & 15 deletions pytorch_lightning/trainer/distrib_parts.py
Original file line number Diff line number Diff line change
Expand Up @@ -343,7 +343,7 @@
import time
import random
import torch
from typing import Union
from typing import Union, Callable

from pytorch_lightning import _logger as log
from pytorch_lightning.loggers import LightningLoggerBase
Expand Down Expand Up @@ -748,26 +748,33 @@ def determine_root_gpu_device(gpus):
return root_gpu


def retry_jittered_backoff(f, num_retries=5):
# Based on:
# https://aws.amazon.com/blogs/architecture/exponential-backoff-and-jitter/
cap = 1.0 # max sleep time is 1s
base = 0.01 # initial sleep time is 10ms
sleep = base # initial sleep time is 10ms
def retry_jittered_backoff(func: Callable, num_retries: int = 5, cap_delay: float = 1.0, base_delay: float = 0.01):
"""Retry jittered backoff.
Based on:
https://aws.amazon.com/blogs/architecture/exponential-backoff-and-jitter/
Args:
func: tested function
num_retries: number of tries
cap_delay: max sleep time
base_delay: initial sleep time is 10ms
"""
sleep_delay = base_delay # initial sleep time is 10ms

for i in range(num_retries):
try:
return f()
except RuntimeError as e:
return func()
except RuntimeError as err:
if i == num_retries - 1:
raise e
raise err
else:
continue
time.sleep(sleep)
sleep = min(cap, random.uniform(base, sleep * 3))
time.sleep(sleep_delay)
sleep_delay = min(cap_delay, random.uniform(base_delay, sleep_delay * 3))


def pick_single_gpu(exclude_gpus=[]):
def pick_single_gpu(exclude_gpus: list):
for i in range(torch.cuda.device_count()):
if i in exclude_gpus:
continue
Expand All @@ -781,9 +788,9 @@ def pick_single_gpu(exclude_gpus=[]):
raise RuntimeError("No GPUs available.")


def pick_multiple_gpus(n):
def pick_multiple_gpus(nb):
picked = []
for _ in range(n):
for _ in range(nb):
picked.append(pick_single_gpu(exclude_gpus=picked))

return picked
3 changes: 1 addition & 2 deletions pytorch_lightning/trainer/training_io.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,6 @@
"""

import os
import pickle
import re
import signal
from abc import ABC
Expand Down Expand Up @@ -211,7 +210,7 @@ def register_slurm_signal_handlers(self):
job_name = os.environ['SLURM_JOB_NAME']
if job_name != 'bash':
on_slurm = True
except Exception as e:
except Exception:
pass

if on_slurm:
Expand Down
2 changes: 1 addition & 1 deletion tests/trainer/test_trainer.py
Original file line number Diff line number Diff line change
Expand Up @@ -823,5 +823,5 @@ def __init__(self, **kwargs):
assert trainer.fast_dev_run

# when we pass in an unknown arg, the base class should complain
with pytest.raises(TypeError, match=r"__init__\(\) got an unexpected keyword argument 'abcdefg'") as e:
with pytest.raises(TypeError, match=r"__init__\(\) got an unexpected keyword argument 'abcdefg'"):
TrainerSubclass(abcdefg='unknown_arg')

0 comments on commit 5492245

Please sign in to comment.